PHOENIX-2181: PhoenixHBaseLoader doesn't work with salted tables
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/608cb5be Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/608cb5be Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/608cb5be Branch: refs/heads/4.x-HBase-1.0 Commit: 608cb5be66994f2ebfb07c6df90f51bb4c91638e Parents: d6f9c67 Author: Ravi Magham <ravi.mag...@bazaarvoice.com> Authored: Fri Aug 14 14:21:30 2015 -0700 Committer: Ravi Magham <ravi.mag...@bazaarvoice.com> Committed: Fri Aug 14 14:21:30 2015 -0700 ---------------------------------------------------------------------- .../org/apache/phoenix/util/PhoenixRuntime.java | 4 +- .../phoenix/pig/PhoenixHBaseLoaderIT.java | 47 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/608cb5be/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java index 586cedd..4f87765 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java @@ -386,7 +386,9 @@ public class PhoenixRuntime { Set<String> unresolvedColumnNames = new TreeSet<String>(); if (columns == null || columns.isEmpty()) { // use all columns in the table - for(PColumn pColumn : table.getColumns()) { + int offset = (table.getBucketNum() == null ? 0 : 1); + for (int i = offset; i < table.getColumns().size(); i++) { + PColumn pColumn = table.getColumns().get(i); int sqlType = pColumn.getDataType().getSqlType(); columnInfoList.add(new ColumnInfo(pColumn.toString(), sqlType)); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/608cb5be/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 53a62ee..25458d6 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 @@ -582,6 +582,53 @@ public class PhoenixHBaseLoaderIT extends BaseHBaseManagedTimeIT { dropTable(INDEX_NAME); } } + + @Test + public void testLoadOfSaltTable() throws Exception { + final String TABLE = "TABLE11"; + final String sourceTableddl = "CREATE TABLE " + TABLE + + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, AGE INTEGER, SAL INTEGER) SALT_BUCKETS=2 "; + + conn.createStatement().execute(sourceTableddl); + + //prepare data with 10 rows having age 25 and the other 30. + final String dml = "UPSERT INTO " + TABLE + " VALUES(?,?,?,?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + int rows = 20; + int j = 0, k = 0; + for(int i = 0 ; i < rows; i++) { + stmt.setInt(1, i); + stmt.setString(2, "a"+i); + if(i % 2 == 0) { + stmt.setInt(3, 25); + stmt.setInt(4, 10 * 2 * j++); + } else { + stmt.setInt(3, 30); + stmt.setInt(4, 10 * 3 * k++); + } + + stmt.execute(); + } + conn.commit(); + + final Data data = Storage.resetData(pigServer); + List<Tuple> expectedList = new ArrayList<Tuple>(); + expectedList.add(Storage.tuple(25,10)); + expectedList.add(Storage.tuple(30,10)); + + pigServer.setBatchOn(); + pigServer.registerQuery(String.format( + "A = load 'hbase://table/%s' using " + PhoenixHBaseLoader.class.getName() + "('%s');", TABLE, + zkQuorum)); + + pigServer.registerQuery("B = GROUP A BY AGE;"); + pigServer.registerQuery("C = FOREACH B GENERATE group,COUNT(A);"); + pigServer.registerQuery("STORE C INTO 'out' using mock.Storage();"); + pigServer.executeBatch(); + + List<Tuple> actualList = data.get("out"); + assertEquals(expectedList.size(), actualList.size()); + } @After public void tearDown() throws Exception {