kadirozde commented on code in PR #2365:
URL: https://github.com/apache/phoenix/pull/2365#discussion_r2835203338
##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java:
##########
@@ -1361,6 +1363,160 @@ public void testUnverifiedIndexRowWithSkipScanFilter2()
throws Exception {
}
}
+ @Test
+ public void testReadRepairWithDistinctPrefixFilter() throws Exception {
+ Assume.assumeTrue(async == false);
+
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String dataTableName = generateUniqueName();
+ String indexName = generateUniqueName();
+ conn.createStatement().execute("create table " + dataTableName
+ + " (id1 varchar(10) not null, id2 varchar(10) not null, val1
varchar(10), val2 varchar(10), "
+ + "val3 varchar(10), val4 varchar(10) constraint pk primary key(id1,
id2))"
+ + tableDDLOptions);
+ conn.createStatement().execute("CREATE INDEX " + indexName + " on " +
dataTableName
+ + " (val1, val2) include (val3, val4)" + this.indexDDLOptions);
+
+ // create orphan unverified index row
+ IndexRegionObserver.setFailDataTableUpdatesForTesting(true);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a2', 'val1', 'val2a', 'val3', 'val4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a3', 'a2', 'val1', 'val2a', 'val3', 'val4')");
+ commitWithException(conn);
+ IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a3', 'val1', 'val2a', 'val31', 'val4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a2', 'a1', 'val1', 'val2a', 'val31', 'val4')");
+ conn.commit();
+
+ // create an unverified update to the index row pointing to an existing
data row
+ IndexRegionObserver.setFailDataTableUpdatesForTesting(true);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a2', 'a1', 'val1', 'val1b', 'val3', 'val4')");
+ commitWithException(conn);
+ IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a2', 'a2', 'val1', 'val1b', 'val3', 'val4')");
+ conn.commit();
+
+ ArrayList<String> expectedValues = Lists.newArrayList("a1", "a2");
+ String selectSql =
+ "SELECT distinct(id1) from " + dataTableName + " WHERE val1 = 'val1'
AND val2 = 'val2a'";
+ verifyDistinctQueryOnIndex(conn, indexName, selectSql, expectedValues);
+
+ expectedValues = Lists.newArrayList("a2");
+ selectSql =
+ "SELECT distinct(id1) from " + dataTableName + " WHERE val1 = 'val1'
AND val2 = 'val1b'";
+ verifyDistinctQueryOnIndex(conn, indexName, selectSql, expectedValues);
+
+ IndexRegionObserver.setFailPostIndexUpdatesForTesting(true);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a3', 'a2', 'val1', 'val2a', 'val3', 'val4')");
+ conn.commit();
+ IndexRegionObserver.setFailPostIndexUpdatesForTesting(false);
+ expectedValues = Lists.newArrayList("a1", "a2", "a3");
+ selectSql =
+ "SELECT distinct(id1) from " + dataTableName + " WHERE val1 = 'val1'
AND val2 = 'val2a'";
+ verifyDistinctQueryOnIndex(conn, indexName, selectSql, expectedValues);
+
+ // first verified and then verified
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a4', 'a1', 'val1_4', 'val1_4', 'val1_4', 'val1_4')");
+ conn.commit();
+ IndexRegionObserver.setFailPostIndexUpdatesForTesting(true);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a4', 'a2', 'val1_4', 'val1_4', 'val1_4', 'val1_4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a5', 'a1', 'val1_4', 'val1_4', 'val1_4', 'val1_4')");
+ conn.commit();
+ IndexRegionObserver.setFailPostIndexUpdatesForTesting(false);
+ expectedValues = Lists.newArrayList("a4", "a5");
+ selectSql =
+ "SELECT distinct(id1) from " + dataTableName + " WHERE val1 = 'val1_4'
AND val2 = 'val1_4'";
+ verifyDistinctQueryOnIndex(conn, indexName, selectSql, expectedValues);
+ }
+ }
+
+ @Test
+ public void testUncoveredIndexWithDistinctPrefixFilter() throws Exception {
+ Assume.assumeTrue(async == false);
+
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String dataTableName = generateUniqueName();
+ String uncoveredIndex1 = generateUniqueName();
+ conn.createStatement().execute("create table " + dataTableName
+ + " (id1 varchar(10) not null, id2 varchar(10) not null, val1
varchar(10), val2 varchar(10), "
+ + "val3 varchar(10), val4 varchar(10) constraint pk primary key(id1,
id2))"
+ + tableDDLOptions);
+ conn.createStatement().execute("CREATE UNCOVERED INDEX " +
uncoveredIndex1 + " on "
+ + dataTableName + " (val1)" + this.indexDDLOptions);
+
+ // create orphan unverified index row
+ IndexRegionObserver.setFailDataTableUpdatesForTesting(true);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a1', 'val1a', 'val2a', 'val3', 'val4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a2', 'val1a', 'val2a', 'val3', 'val4')");
+ commitWithException(conn);
+ IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a3', 'val1a', 'val2a', 'val31', 'val4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a4', 'val1a', 'val2b', 'val31', 'val4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a1', 'a5', 'val1a', 'val2b', 'val31', 'val4')");
+ conn.createStatement().execute("upsert into " + dataTableName + " "
+ + "values ('a2', 'a1', 'val1a', 'val2a', 'val31', 'val4')");
+ conn.commit();
+
+ ArrayList<String> expectedValues = Lists.newArrayList("a1", "a2");
+ String selectSql = "SELECT distinct(id1) from " + dataTableName + "
WHERE val1 = 'val1a'";
Review Comment:
I think we need to return id2 too by using SELECT distinct(id1), id2 to
verify that the query actually uses the expected rows. For this, we can use
`List<List<String>> expectedValues`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]