phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravimag...@apache.org
Subject git commit: PHOENIX-1317-Test on loading data from Index table
Date Tue, 07 Oct 2014 06:34:47 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.0 5668817de -> f21bf2a05


PHOENIX-1317-Test on loading data from Index table


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f21bf2a0
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f21bf2a0
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f21bf2a0

Branch: refs/heads/4.0
Commit: f21bf2a0584453b0247e03041d2acdae76531d1b
Parents: 5668817
Author: ravimagham <ravimagham@apache.org>
Authored: Mon Oct 6 23:34:05 2014 -0700
Committer: ravimagham <ravimagham@apache.org>
Committed: Mon Oct 6 23:34:05 2014 -0700

----------------------------------------------------------------------
 .../phoenix/pig/PhoenixHBaseLoaderIT.java       | 40 +++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f21bf2a0/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java b/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
index 6db97f5..7c4306f 100644
--- a/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
+++ b/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
@@ -72,6 +72,7 @@ public class PhoenixHBaseLoaderIT {
     private static final Log LOG = LogFactory.getLog(PhoenixHBaseLoaderIT.class);
     private static final String SCHEMA_NAME = "T";
     private static final String TABLE_NAME = "A";
+    private static final String INDEX_NAME = "I";
     private static final String TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, TABLE_NAME);
     private static HBaseTestingUtility hbaseTestUtil;
     private static String zkQuorum;
@@ -564,6 +565,43 @@ public class PhoenixHBaseLoaderIT {
         }
     
     }
+	 
+	 @Test
+	 public void testDataFromIndexTable() throws Exception {
+        try {
+            //create the table
+            String ddl = "CREATE TABLE " + TABLE_NAME
+                    + " (ID INTEGER NOT NULL, NAME VARCHAR NOT NULL, EMPLID INTEGER CONSTRAINT
pk PRIMARY KEY (ID, NAME)) IMMUTABLE_ROWS=true";
+                   
+            conn.createStatement().execute(ddl);
+           
+            //create a index table
+            String indexDdl = " CREATE INDEX " + INDEX_NAME + " ON " + TABLE_NAME + " (EMPLID)
INCLUDE (NAME) ";
+            conn.createStatement().execute(indexDdl);
+           
+            //upsert the data.
+            final String dml = "UPSERT INTO " + TABLE_NAME + " VALUES(?,?,?)";
+            PreparedStatement stmt = conn.prepareStatement(dml);
+            int rows = 20;
+            for(int i = 0 ; i < rows; i++) {
+                stmt.setInt(1, i);
+                stmt.setString(2, "a"+i);
+                stmt.setInt(3, i * 5);
+                stmt.execute();
+            }
+            conn.commit();
+            pigServer.registerQuery("A = load 'hbase://query/SELECT NAME , EMPLID FROM A
WHERE EMPLID = 25 ' using " + PhoenixHBaseLoader.class.getName() + "('"+zkQuorum + "')  ;");
+            Iterator<Tuple> iterator = pigServer.openIterator("A");
+            while (iterator.hasNext()) {
+                Tuple tuple = iterator.next();
+                assertEquals("a5", tuple.get(0));
+                assertEquals(25, tuple.get(1));
+            }
+        } finally {
+          dropTable(TABLE_NAME);
+          dropTable(INDEX_NAME);
+        }
+    }
     
     @After
     public void tearDown() throws Exception {
@@ -574,7 +612,7 @@ public class PhoenixHBaseLoaderIT {
 
     private void dropTable(String tableFullName) throws SQLException {
       Preconditions.checkNotNull(conn);
-      conn.createStatement().execute(String.format("DROP TABLE %s",tableFullName));
+      conn.createStatement().execute(String.format("DROP TABLE IF EXISTS %s",tableFullName));
     }
 
     @AfterClass


Mime
View raw message