You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2017/09/26 05:36:42 UTC
[2/2] phoenix git commit: PHOENIX-4233 IndexScrutiny test tool does
not work for salted and shared index tables
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/94601de5
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/94601de5
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/94601de5
Branch: refs/heads/master
Commit: 94601de5f5f966fb8bcd1a069409bee460bf2400
Parents: d13a2e5
Author: James Taylor <jt...@salesforce.com>
Authored: Mon Sep 25 22:33:28 2017 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Mon Sep 25 22:33:28 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/94601de5/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/94601de5/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(",");
}