This is an automated email from the ASF dual-hosted git repository.
larsh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 3113307 PHOENIX-6097 Improve LOCAL index consistency tests.
3113307 is described below
commit 3113307a313c409343255c84f17e766ebdbd1d8a
Author: Lars <[email protected]>
AuthorDate: Mon Aug 24 09:47:20 2020 -0700
PHOENIX-6097 Improve LOCAL index consistency tests.
---
.../apache/phoenix/end2end/index/LocalIndexIT.java | 61 +++++++++++++++++-----
1 file changed, 47 insertions(+), 14 deletions(-)
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index 0965ce1..3d5a323 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -113,25 +113,58 @@ public class LocalIndexIT extends BaseLocalIndexIT {
Connection conn = getConnection();
conn.setAutoCommit(true);
- conn.createStatement().execute("CREATE TABLE " + tableName + " (pk
INTEGER PRIMARY KEY, v1 FLOAT) SPLIT ON (2000)");
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (pk
INTEGER PRIMARY KEY, v1 FLOAT) SPLIT ON (4000)");
conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + "
ON " + tableName + "(v1)");
- conn.createStatement().execute("UPSERT INTO " + tableName + "
VALUES(rand() * 4000, rand())");
+ conn.createStatement().execute("UPSERT INTO " + tableName + "
VALUES(rand() * 8000, rand())");
- ResultSet rs;
- for (int i=0; i<15; i++) {
- conn.createStatement().execute("UPSERT INTO " + tableName + "
SELECT rand() * 4000, rand() FROM " + tableName);
+ for (int i=0; i<16; i++) {
+ conn.createStatement().execute("UPSERT INTO " + tableName + "
SELECT rand() * 8000, rand() FROM " + tableName);
+ assertEquals(getCountViaIndex(conn, tableName, null),
getCountViaIndex(conn, tableName, indexName));
+ }
+ }
- rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " +
tableName);
- rs.next();
- int indexCount = rs.getInt(1);
- rs.close();
+ @Test
+ public void testLocalIndexConsistencyWithGlobalMix() throws Exception {
+ if (isNamespaceMapped) {
+ return;
+ }
+ String tableName = schemaName + "." + generateUniqueName();
+ String localIndexNames[] = {"L_" + generateUniqueName(), "L_" +
generateUniqueName()};
+ String globalIndexNames[] = {"G_" + generateUniqueName(), "G_" +
generateUniqueName()};
- rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */
COUNT(*) FROM " + tableName);
- rs.next();
- int tableCount = rs.getInt(1);
- rs.close();
+ Connection conn = getConnection();
+ conn.setAutoCommit(true);
- assertEquals(indexCount, tableCount);
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (pk
INTEGER PRIMARY KEY, v1 FLOAT, v2 FLOAT, v3 FLOAT, v4 FLOAT) SPLIT ON (4000)");
+
+ int idx=1;
+ for (String indexName : localIndexNames) {
+ conn.createStatement().execute("CREATE LOCAL INDEX " + indexName +
" ON " + tableName + "(v" + idx++ +")");
+ }
+ for (String indexName : globalIndexNames) {
+ conn.createStatement().execute("CREATE INDEX " + indexName + " ON
" + tableName + "(v" + idx++ +")");
+ }
+ conn.createStatement().execute("UPSERT INTO " + tableName + "
VALUES(rand() * 8000, rand())");
+
+ for (int i=0; i<16; i++) {
+ conn.createStatement().execute("UPSERT INTO " + tableName + "
SELECT rand() * 8000, rand() FROM " + tableName);
+
+ int count = getCountViaIndex(conn, tableName, null);
+ for (String indexName : localIndexNames) {
+ assertEquals(count, getCountViaIndex(conn, tableName,
indexName));
+ }
+
+ for (String indexName : globalIndexNames) {
+ assertEquals(count, getCountViaIndex(conn, tableName,
indexName));
+ }
+ }
+ }
+
+ private int getCountViaIndex(Connection conn, String tableName, String
indexName) throws SQLException {
+ String hint = indexName == null ? "NO_INDEX" : "INDEX(" + tableName +
" " + indexName + ")";
+ try (ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ "
+ hint + " */ COUNT(*) FROM " + tableName)) {
+ rs.next();
+ return rs.getInt(1);
}
}