Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 30f6feb13 -> 8d3d6b0f3
PHOENIX-4233 IndexScrutiny test tool does not work for salted and shared index tables Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/d0aac8e6 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d0aac8e6 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d0aac8e6 Branch: refs/heads/4.x-HBase-0.98 Commit: d0aac8e6356e2eb0e1e38534b8599296a6e03ad2 Parents: 30f6feb Author: James Taylor <[email protected]> Authored: Mon Sep 25 22:33:28 2017 -0700 Committer: James Taylor <[email protected]> Committed: Tue Sep 26 12:24:39 2017 -0700 ---------------------------------------------------------------------- .../apache/phoenix/util/IndexScrutinyIT.java | 4 +- .../org/apache/phoenix/util/IndexScrutiny.java | 47 ++++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/d0aac8e6/phoenix-core/src/it/java/org/apache/phoenix/util/IndexScrutinyIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/util/IndexScrutinyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/util/IndexScrutinyIT.java index a5ec83f..3277e32 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/util/IndexScrutinyIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/util/IndexScrutinyIT.java @@ -35,7 +35,7 @@ public class IndexScrutinyIT extends ParallelStatsDisabledIT { String fullTableName = SchemaUtil.getTableName(schemaName, tableName); String fullIndexName = SchemaUtil.getTableName(schemaName, indexName); try (Connection conn = DriverManager.getConnection(getUrl())) { - conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); + conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true, SALT_BUCKETS=2"); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)"); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb')"); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')"); @@ -61,7 +61,7 @@ public class IndexScrutinyIT extends ParallelStatsDisabledIT { String fullIndexName = SchemaUtil.getTableName(schemaName, indexName); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v) INCLUDE (v2)"); + conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + fullTableName + " (v) INCLUDE (v2)"); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb','0')"); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','1')"); conn.commit(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d0aac8e6/phoenix-core/src/test/java/org/apache/phoenix/util/IndexScrutiny.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/IndexScrutiny.java b/phoenix-core/src/test/java/org/apache/phoenix/util/IndexScrutiny.java index c78658d..380e718 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/util/IndexScrutiny.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/util/IndexScrutiny.java @@ -25,6 +25,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.util.List; import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.schema.PColumn; @@ -39,20 +40,39 @@ public class IndexScrutiny { public static long scrutinizeIndex(Connection conn, String fullTableName, String fullIndexName) throws SQLException { PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); PTable ptable = pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)); + int tableColumnOffset = 0; + List<PColumn> tableColumns = ptable.getColumns(); + List<PColumn> tablePKColumns = ptable.getPKColumns(); + if (ptable.getBucketNum() != null) { + tableColumnOffset = 1; + tableColumns = tableColumns.subList(tableColumnOffset, tableColumns.size()); + tablePKColumns = tablePKColumns.subList(tableColumnOffset, tablePKColumns.size()); + } PTable pindex = pconn.getTable(new PTableKey(pconn.getTenantId(), fullIndexName)); + List<PColumn> indexColumns = pindex.getColumns(); + int indexColumnOffset = 0; + if (pindex.getBucketNum() != null) { + indexColumnOffset = 1; + } + if (pindex.getViewIndexId() != null) { + indexColumnOffset++; + } + if (indexColumnOffset > 0) { + indexColumns = indexColumns.subList(indexColumnOffset, indexColumns.size()); + } StringBuilder indexQueryBuf = new StringBuilder("SELECT "); - for (PColumn dcol : ptable.getPKColumns()) { + for (PColumn dcol : tablePKColumns) { indexQueryBuf.append("CAST(\"" + IndexUtil.getIndexColumnName(dcol) + "\" AS " + dcol.getDataType().getSqlTypeName() + ")"); indexQueryBuf.append(","); } - for (PColumn icol : pindex.getColumns()) { + for (PColumn icol :indexColumns) { PColumn dcol = IndexUtil.getDataColumn(ptable, icol.getName().getString()); if (SchemaUtil.isPKColumn(icol) && !SchemaUtil.isPKColumn(dcol)) { indexQueryBuf.append("CAST (\"" + icol.getName().getString() + "\" AS " + dcol.getDataType().getSqlTypeName() + ")"); indexQueryBuf.append(","); } } - for (PColumn icol : pindex.getColumns()) { + for (PColumn icol : indexColumns) { if (!SchemaUtil.isPKColumn(icol)) { PColumn dcol = IndexUtil.getDataColumn(ptable, icol.getName().getString()); indexQueryBuf.append("CAST (\"" + icol.getName().getString() + "\" AS " + dcol.getDataType().getSqlTypeName() + ")"); @@ -63,11 +83,11 @@ public class IndexScrutiny { indexQueryBuf.append("\nFROM " + fullIndexName); StringBuilder tableQueryBuf = new StringBuilder("SELECT "); - for (PColumn dcol : ptable.getPKColumns()) { + for (PColumn dcol : tablePKColumns) { tableQueryBuf.append("\"" + dcol.getName().getString() + "\""); tableQueryBuf.append(","); } - for (PColumn icol : pindex.getColumns()) { + for (PColumn icol : indexColumns) { PColumn dcol = IndexUtil.getDataColumn(ptable, icol.getName().getString()); if (SchemaUtil.isPKColumn(icol) && !SchemaUtil.isPKColumn(dcol)) { if (dcol.getFamilyName() != null) { @@ -78,7 +98,7 @@ public class IndexScrutiny { tableQueryBuf.append(","); } } - for (PColumn icol : pindex.getColumns()) { + for (PColumn icol : indexColumns) { if (!SchemaUtil.isPKColumn(icol)) { PColumn dcol = IndexUtil.getDataColumn(ptable, icol.getName().getString()); if (dcol.getFamilyName() != null) { @@ -91,13 +111,13 @@ public class IndexScrutiny { } tableQueryBuf.setLength(tableQueryBuf.length()-1); tableQueryBuf.append("\nFROM " + fullTableName + "\nWHERE ("); - for (PColumn dcol : ptable.getPKColumns()) { + for (PColumn dcol : tablePKColumns) { tableQueryBuf.append("\"" + dcol.getName().getString() + "\""); tableQueryBuf.append(","); } tableQueryBuf.setLength(tableQueryBuf.length()-1); tableQueryBuf.append(") = (("); - for (int i = 0; i < ptable.getPKColumns().size(); i++) { + for (int i = 0; i < tablePKColumns.size(); i++) { tableQueryBuf.append("?"); tableQueryBuf.append(","); } @@ -114,11 +134,12 @@ public class IndexScrutiny { while (irs.next()) { icount++; StringBuilder pkBuf = new StringBuilder("("); - for (int i = 0; i < ptable.getPKColumns().size(); i++) { - PColumn dcol = ptable.getPKColumns().get(i); - Object pkVal = irs.getObject(i+1); - PDataType pkType = PDataType.fromTypeId(irsmd.getColumnType(i + 1)); - istmt.setObject(i+1, pkVal, dcol.getDataType().getSqlType()); + for (int i = 0; i < tablePKColumns.size(); i++) { + PColumn dcol = tablePKColumns.get(i); + int offset = i+1; + Object pkVal = irs.getObject(offset); + PDataType pkType = PDataType.fromTypeId(irsmd.getColumnType(offset)); + istmt.setObject(offset, pkVal, dcol.getDataType().getSqlType()); pkBuf.append(pkType.toStringLiteral(pkVal)); pkBuf.append(","); }
