phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [1/2] Updates to Pig Integration - James forgot to add some files (Ravi)
Date Tue, 22 Apr 2014 03:09:55 GMT
Repository: incubator-phoenix
Updated Branches:
  refs/heads/master 920a5cc62 -> a615cebfb


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/a615cebf/phoenix-pig/src/test/java/org/apache/phoenix/pig/PhoenixPigConfigurationTest.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/test/java/org/apache/phoenix/pig/PhoenixPigConfigurationTest.java
b/phoenix-pig/src/test/java/org/apache/phoenix/pig/PhoenixPigConfigurationTest.java
new file mode 100644
index 0000000..ac254e6
--- /dev/null
+++ b/phoenix-pig/src/test/java/org/apache/phoenix/pig/PhoenixPigConfigurationTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.pig;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.SQLException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
+
+
+/**
+ * Tests for PhoenixPigConfiguration. 
+ *
+ */
+public class PhoenixPigConfigurationTest {
+
+  
+    @Test
+    public void testBasicConfiguration() throws SQLException {
+        Configuration conf = new Configuration();
+        final PhoenixPigConfiguration phoenixConfiguration = new PhoenixPigConfiguration(conf);
+        final String zkQuorum = "localhost";
+        final String tableName = "TABLE";
+        final long batchSize = 100;
+        phoenixConfiguration.configure(zkQuorum, tableName, batchSize);
+        assertEquals(zkQuorum,phoenixConfiguration.getServer());
+        assertEquals(tableName,phoenixConfiguration.getTableName());
+        assertEquals(batchSize,phoenixConfiguration.getBatchSize());
+     }
+    
+   /* @Test
+    public void testConfiguration() throws SQLException {
+        Configuration configuration = new Configuration();
+        final PhoenixPigConfiguration phoenixConfiguration = new PhoenixPigConfiguration(configuration);
+        final String zkQuorum = "localhost";
+        final String tableName = "TABLE";
+        final long batchSize = 100;
+        phoenixConfiguration.configure(zkQuorum, tableName, batchSize);
+        PhoenixPigConfigurationUtil util = Mockito.mock(PhoenixPigConfigurationUtil.class);
+        phoenixConfiguration.setUtil(util);
+        phoenixConfiguration.getColumnMetadataList();
+        Mockito.verify(util).getUpsertColumnMetadataList(configuration, tableName);
+        Mockito.verifyNoMoreInteractions(util);
+        
+        phoenixConfiguration.getSelectStatement();
+        Mockito.verify(util).getSelectStatement(configuration, tableName);
+        Mockito.verifyNoMoreInteractions(util);
+     }
+    
+    @Test
+    public void testWithSpy() throws SQLException {
+        Configuration configuration = new Configuration();
+        final PhoenixPigConfiguration phoenixConfiguration = new PhoenixPigConfiguration(configuration);
+        final String zkQuorum = "localhost";
+        final String tableName = "TABLE";
+        final long batchSize = 100;
+        phoenixConfiguration.configure(zkQuorum, tableName, batchSize);
+        phoenixConfiguration.setSelectStatement("SELECT 1 from TABLE");
+        PhoenixPigConfigurationUtil util = new PhoenixPigConfigurationUtil();
+        PhoenixPigConfigurationUtil spied = Mockito.spy(util);
+        phoenixConfiguration.setUtil(spied);
+          
+        phoenixConfiguration.getSelectStatement();
+        Mockito.verify(spied,Mockito.times(1)).getSelectStatement(configuration, tableName);
+        Mockito.verifyNoMoreInteractions(util);
+     }*/
+}

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/a615cebf/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/ColumnInfoToStringEncoderDecoderTest.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/ColumnInfoToStringEncoderDecoderTest.java
b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/ColumnInfoToStringEncoderDecoderTest.java
new file mode 100644
index 0000000..9777bb5
--- /dev/null
+++ b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/ColumnInfoToStringEncoderDecoderTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.pig.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.phoenix.pig.util.ColumnInfoToStringEncoderDecoder;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.util.ColumnInfo;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Tests methods on {@link ColumnInfoToStringEncoderDecoder}
+ */
+public class ColumnInfoToStringEncoderDecoderTest {
+
+    @Test
+    public void testEncode() {
+        final ColumnInfo columnInfo = new ColumnInfo("col1", PDataType.VARCHAR.getSqlType());
+        final String encodedColumnInfo = ColumnInfoToStringEncoderDecoder.encode(Lists.newArrayList(columnInfo));
+        assertEquals(columnInfo.toString(),encodedColumnInfo);
+    }
+    
+    @Test
+    public void testDecode() {
+        final ColumnInfo columnInfo = new ColumnInfo("col1", PDataType.VARCHAR.getSqlType());
+        final String encodedColumnInfo = ColumnInfoToStringEncoderDecoder.encode(Lists.newArrayList(columnInfo));
+        assertEquals(columnInfo.toString(),encodedColumnInfo);
+    }
+    
+    @Test
+    public void testEncodeDecodeWithNulls() {
+        final ColumnInfo columnInfo1 = new ColumnInfo("col1", PDataType.VARCHAR.getSqlType());
+        final ColumnInfo columnInfo2 = null;
+        final String columnInfoStr = ColumnInfoToStringEncoderDecoder.encode(Lists.newArrayList(columnInfo1,columnInfo2));
+        final List<ColumnInfo> decodedColumnInfo = ColumnInfoToStringEncoderDecoder.decode(columnInfoStr);
+        assertEquals(1,decodedColumnInfo.size()); 
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/a615cebf/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtilTest.java
b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtilTest.java
new file mode 100644
index 0000000..310128c
--- /dev/null
+++ b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtilTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.pig.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.List;
+
+import org.apache.phoenix.pig.PhoenixPigConfiguration;
+import org.apache.phoenix.pig.util.PhoenixPigSchemaUtil;
+import org.apache.phoenix.schema.IllegalDataException;
+import org.apache.phoenix.util.ColumnInfo;
+import org.apache.pig.ResourceSchema;
+import org.apache.pig.ResourceSchema.ResourceFieldSchema;
+import org.apache.pig.data.DataType;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * 
+ * Tests on PhoenixPigSchemaUtil
+ */
+public class PhoenixPigSchemaUtilTest {
+
+    private static final ColumnInfo ID_COLUMN = new ColumnInfo("ID", Types.BIGINT);
+    private static final ColumnInfo NAME_COLUMN = new ColumnInfo("NAME", Types.VARCHAR);
+    private static final ColumnInfo LOCATION_COLUMN = new ColumnInfo("LOCATION", Types.ARRAY);
+    
+    
+    @Test
+    public void testSchema() throws SQLException, IOException {
+        
+        final PhoenixPigConfiguration configuration = mock(PhoenixPigConfiguration.class);
+        final List<ColumnInfo> columnInfos = ImmutableList.of(ID_COLUMN,NAME_COLUMN);
+        when(configuration.getSelectColumnMetadataList()).thenReturn(columnInfos);
+        final ResourceSchema actual = PhoenixPigSchemaUtil.getResourceSchema(configuration);
+        
+        // expected schema.
+        final ResourceFieldSchema[] fields = new ResourceFieldSchema[2];
+        fields[0] = new ResourceFieldSchema().setName("ID")
+                                                .setType(DataType.LONG);
+
+        fields[1] = new ResourceFieldSchema().setName("NAME")
+                                                .setType(DataType.CHARARRAY);
+        final ResourceSchema expected = new ResourceSchema().setFields(fields);
+        
+        assertEquals(expected.toString(), actual.toString());
+        
+    }
+    
+    @Test(expected=IllegalDataException.class)
+    public void testUnSupportedTypes() throws SQLException, IOException {
+        
+        final PhoenixPigConfiguration configuration = mock(PhoenixPigConfiguration.class);
+        final List<ColumnInfo> columnInfos = ImmutableList.of(ID_COLUMN,LOCATION_COLUMN);
+        when(configuration.getSelectColumnMetadataList()).thenReturn(columnInfos);
+        PhoenixPigSchemaUtil.getResourceSchema(configuration);
+        fail("We currently don't support Array type yet. WIP!!");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/a615cebf/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/QuerySchemaParserFunctionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/QuerySchemaParserFunctionTest.java
b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/QuerySchemaParserFunctionTest.java
new file mode 100644
index 0000000..3daf4e1
--- /dev/null
+++ b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/QuerySchemaParserFunctionTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.pig.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.pig.PhoenixPigConfiguration;
+import org.apache.phoenix.pig.util.QuerySchemaParserFunction;
+import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.google.common.base.Joiner;
+
+/**
+ * 
+ * Unit tests to validate the query passed to LOAD .
+ *
+ */
+public class QuerySchemaParserFunctionTest extends BaseConnectionlessQueryTest {
+
+    private PhoenixPigConfiguration phoenixConfiguration;
+    private Connection conn;
+    private QuerySchemaParserFunction function;
+    
+    @Before
+    public void setUp() throws SQLException {
+        phoenixConfiguration = Mockito.mock(PhoenixPigConfiguration.class);
+        conn = DriverManager.getConnection(getUrl());
+        Mockito.when(phoenixConfiguration.getConnection()).thenReturn(conn);
+        function = new QuerySchemaParserFunction(phoenixConfiguration);
+    }
+    
+    @Test(expected=RuntimeException.class)
+    public void testSelectQuery() {
+        final String selectQuery = "SELECT col1 FROM test";
+        function.apply(selectQuery);
+        fail("Should fail as the table [test] doesn't exist");
+   }
+    
+    @Test
+    public void testValidSelectQuery() throws SQLException {
+        String ddl = "CREATE TABLE EMPLOYEE " +
+                "  (id integer not null, name varchar, age integer,location varchar " +
+                "  CONSTRAINT pk PRIMARY KEY (id))\n";
+        createTestTable(getUrl(), ddl);
+  
+        final String selectQuery = "SELECT name,age,location FROM EMPLOYEE";
+        Pair<String,String> pair = function.apply(selectQuery);
+         
+        assertEquals(pair.getFirst(), "EMPLOYEE");
+        assertEquals(pair.getSecond(),Joiner.on(',').join("NAME","AGE","LOCATION"));
+    }
+    
+    @Test(expected=RuntimeException.class)
+    public void testUpsertQuery() throws SQLException {
+        String ddl = "CREATE TABLE EMPLOYEE " +
+                "  (id integer not null, name varchar, age integer,location varchar " +
+                "  CONSTRAINT pk PRIMARY KEY (id))\n";
+        createTestTable(getUrl(), ddl);
+  
+        final String upsertQuery = "UPSERT INTO EMPLOYEE (ID, NAME) VALUES (?, ?)";
+        
+        function.apply(upsertQuery);
+        fail(" Function call successful despite passing an UPSERT query");
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testAggregationQuery() throws SQLException {
+        String ddl = "CREATE TABLE EMPLOYEE " +
+                "  (id integer not null, name varchar, age integer,location varchar " +
+                "  CONSTRAINT pk PRIMARY KEY (id))\n";
+        createTestTable(getUrl(), ddl);
+  
+        final String selectQuery = "SELECT MAX(ID) FROM EMPLOYEE";
+        function.apply(selectQuery);
+        fail(" Function call successful despite passing an aggreagate query");
+    }
+
+    @After
+    public void tearDown() throws SQLException {
+        conn.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/a615cebf/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/TableSchemaParserFunctionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/TableSchemaParserFunctionTest.java
b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/TableSchemaParserFunctionTest.java
new file mode 100644
index 0000000..3ac0520
--- /dev/null
+++ b/phoenix-pig/src/test/java/org/apache/phoenix/pig/util/TableSchemaParserFunctionTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.pig.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.pig.util.TableSchemaParserFunction;
+import org.junit.Test;
+
+import com.google.common.base.Joiner;
+
+public class TableSchemaParserFunctionTest {
+
+    final TableSchemaParserFunction function = new TableSchemaParserFunction();
+    
+    @Test
+    public void testTableSchema() {
+        final String loadTableSchema = "EMPLOYEE/col1,col2";
+        final Pair<String,String> pair = function.apply(loadTableSchema);
+        assertEquals("EMPLOYEE", pair.getFirst());
+        assertEquals(pair.getSecond(),Joiner.on(',').join("col1","col2"));
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testEmptyTableSchema() {
+        final String loadTableSchema = "";
+        function.apply(loadTableSchema);
+    }
+    
+    @Test
+    public void testTableOnlySchema() {
+        final String loadTableSchema = "EMPLOYEE";
+        final Pair<String,String> pair = function.apply(loadTableSchema);
+        assertEquals("EMPLOYEE", pair.getFirst());
+        assertNull(pair.getSecond());
+    }
+}


Mime
View raw message