-
Notifications
You must be signed in to change notification settings - Fork 1k
PHOENIX-7753 : Allow uncovered index creation on tables with relaxed conditional TTL #2357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ | |
|
|
||
| public class ConditionalTTLExpressionTest extends BaseConnectionlessQueryTest { | ||
|
|
||
| private static void assertConditonTTL(Connection conn, String tableName, String ttlExpr) | ||
| private static void assertConditionTTL(Connection conn, String tableName, String ttlExpr) | ||
| throws SQLException { | ||
| TTLExpression expected = new ConditionalTTLExpression(ttlExpr); | ||
| assertTTL(conn, tableName, expected); | ||
|
|
@@ -105,7 +105,7 @@ public void testBasicExpression() throws SQLException { | |
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| String query = String.format("SELECT count(*) from %s where k1 > 3", tableName); | ||
| validateScan(conn, tableName, query, ttl, false, Lists.newArrayList("col1")); | ||
| } | ||
|
|
@@ -174,17 +174,17 @@ public void testSingleNonDefaultColumnFamilyIsAllowed() throws SQLException { | |
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| // create global index | ||
| String indexName = "I_" + generateUniqueName(); | ||
| ddl = String.format("create index %s on %s (col2) include(col1)", indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| // create local index | ||
| indexName = "L_" + generateUniqueName(); | ||
| ddl = String.format("create local index %s on %s (col2) include(col1)", indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -198,23 +198,23 @@ public void testDefaultColumnFamily() throws SQLException { | |
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| // create view | ||
| String viewName = "GV_" + generateUniqueName(); | ||
| ddl = String.format("create view %s (col3 varchar) as select * from %s where k1 = 2", | ||
| viewName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, viewName, ttl); | ||
| assertConditionTTL(conn, viewName, ttl); | ||
| // create global index | ||
| String indexName = "I_" + generateUniqueName(); | ||
| ddl = String.format("create index %s on %s (col2) include(col1)", indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| // create local index | ||
| indexName = "L_" + generateUniqueName(); | ||
| ddl = String.format("create local index %s on %s (col2) include(col1)", indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -301,7 +301,7 @@ public void testMultipleColumnFamilyNotAllowedOnAddColumn3() throws SQLException | |
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| // add a new column in a different column family | ||
| String alterDDL = String.format("alter table %s add A.col3 varchar", tableName); | ||
| try { | ||
|
|
@@ -369,7 +369,7 @@ public void testNullExpression() throws SQLException { | |
| String ddl = String.format(ddlTemplate, tableName, ttl); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| String query = String.format("SELECT count(*) from %s", tableName); | ||
| validateScan(conn, tableName, query, ttl, false, Lists.newArrayList("col1", "col2")); | ||
| } | ||
|
|
@@ -387,14 +387,14 @@ public void testBooleanColumn() throws SQLException { | |
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| String ddl = String.format(ddlTemplate, tableName, ttl); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
|
|
||
| query = String.format("SELECT k1, k2 from %s where (k1,k2) IN ((1,2), (3,4))", tableName); | ||
| validateScan(conn, tableName, query, ttl, false, Lists.newArrayList("expired")); | ||
|
|
||
| ddl = String.format(indexTemplate, indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
|
|
||
| // validate the scan on index | ||
| query = String.format("SELECT count(*) from %s", tableName); | ||
|
|
@@ -411,7 +411,7 @@ public void testNot() throws SQLException { | |
| String ddl = String.format(ddlTemplate, tableName, ttl); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -425,7 +425,7 @@ public void testPhoenixRowTimestamp() throws SQLException { | |
| String query; | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| query = String.format("select col1 from %s where k1 = 7 AND k2 > 12", tableName); | ||
| validateScan(conn, tableName, query, ttl, false, Lists.newArrayList("col1")); | ||
| } | ||
|
|
@@ -441,7 +441,7 @@ public void testBooleanCaseExpression() throws SQLException { | |
| String ddl = String.format(ddlTemplate, tableName, ttl); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, expectedTTLExpr); | ||
| assertConditionTTL(conn, tableName, expectedTTLExpr); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -460,7 +460,7 @@ public void testCondTTLOnTopLevelView() throws SQLException { | |
| ddl = String.format(viewTemplate, viewName, tableName, ttl); | ||
| conn.createStatement().execute(ddl); | ||
| assertTTL(conn, tableName, TTL_EXPRESSION_NOT_DEFINED); | ||
| assertConditonTTL(conn, viewName, ttl); | ||
| assertConditionTTL(conn, viewName, ttl); | ||
| String query = String.format("select k3 from %s", viewName); | ||
| validateScan(conn, viewName, query, ttl, false, Lists.newArrayList("k2", "k3")); | ||
| } | ||
|
|
@@ -487,11 +487,11 @@ public void testCondTTLOnMultiLevelView() throws SQLException { | |
| conn.createStatement().execute(ddl); | ||
| assertTTL(conn, tableName, TTL_EXPRESSION_NOT_DEFINED); | ||
| assertTTL(conn, parentView, TTL_EXPRESSION_NOT_DEFINED); | ||
| assertConditonTTL(conn, childView, ttl); | ||
| assertConditionTTL(conn, childView, ttl); | ||
| // create an index on child view | ||
| ddl = String.format(indexOnChildTemplate, indexName, childView); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -505,7 +505,7 @@ public void testInListTTLExpr() throws Exception { | |
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| query = String.format("select col1 from %s where id IN ('abc', 'fff')", tableName); | ||
| validateScan(conn, tableName, query, ttl, false, Lists.newArrayList("col1", "col2")); | ||
| } | ||
|
|
@@ -524,18 +524,18 @@ public void testPartialIndex() throws Exception { | |
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| ddl = String.format(indexTemplate, indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| query = String.format("select col3 from %s where col1 > 60", tableName); | ||
| validateScan(conn, tableName, query, ttl, true, | ||
| Lists.newArrayList("0:col2", "0:col3", "0:col4")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testUncoveredIndex() throws Exception { | ||
| public void testUncoveredIndexStrictTTL() throws Exception { | ||
| String ddlTemplate = "create table %s (id varchar not null primary key, " | ||
| + "col1 integer, col2 integer, col3 double, col4 varchar) TTL = '%s'"; | ||
| String tableName = generateUniqueName(); | ||
|
|
@@ -546,7 +546,7 @@ public void testUncoveredIndex() throws Exception { | |
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| ddl = String.format(indexTemplate, indexName, tableName); | ||
| try { | ||
| conn.createStatement().execute(ddl); | ||
|
|
@@ -557,7 +557,25 @@ public void testUncoveredIndex() throws Exception { | |
| indexTemplate = "create uncovered index %s on %s (col4, col2) "; | ||
| ddl = String.format(indexTemplate, indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, indexName, ttl); | ||
| assertConditionTTL(conn, indexName, ttl); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testUncoveredIndexRelaxedTTL() throws Exception { | ||
| String ddlTemplate = "create table %s (id varchar not null primary key, " | ||
| + "col1 integer, col2 integer, col3 double, col4 varchar) TTL = '%s', IS_STRICT_TTL=false"; | ||
| String tableName = generateUniqueName(); | ||
| String indexTemplate = "create uncovered index %s on %s (col1) "; | ||
| String indexName = generateUniqueName(); | ||
| String ttl = "col2 > 100 AND col4='expired'"; | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| conn.createStatement().execute(ddl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| ddl = String.format(indexTemplate, indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| assertTTL(conn, indexName, TTL_EXPRESSION_NOT_DEFINED); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -602,6 +620,34 @@ public void testSettingCondTTLOnTableWithIndexWithMissingExprCols() throws Excep | |
| } catch (SQLException e) { | ||
| assertTrue(e.getCause() instanceof ColumnNotFoundException); | ||
| } | ||
| // relaxed ttl | ||
| ddl = String.format("alter table %s set TTL = '%s', IS_STRICT_TTL = false", tableName, | ||
| retainSingleQuotes(ttl)); | ||
| try { | ||
| conn.createStatement().execute(ddl); | ||
| fail("Should have thrown ColumnNotFoundException"); | ||
| } catch (SQLException e) { | ||
| assertTrue(e.getCause() instanceof ColumnNotFoundException); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a test case where the table has uncovered index and a literal TTL. Now you alter the ttl to conditional with IS_STRICT_TTL set to false. Then verify that the table has conditional ttl and the uncovered index has ttl undefined. I am suspecting that while you skipped checking for uncovered indexes during the ttl validation on alter, I am not seeing that you are actually updating the ttl on uncovered index to undefined. |
||
| public void testSettingCondTTLOnTableWithRelaxedTTLAndUncoveredIndex() throws Exception { | ||
| String ddlTemplate = "create table %s (id varchar not null primary key, " | ||
| + "col1 integer, col2 integer, col3 double, col4 varchar) IS_STRICT_TTL = false"; | ||
| String tableName = generateUniqueName(); | ||
| String indexTemplate = "create uncovered index %s on %s (col1)"; | ||
| String indexName = generateUniqueName(); | ||
| String ttl = "col2 > 100 AND col4='expired'"; | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| String ddl = String.format(ddlTemplate, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| ddl = String.format(indexTemplate, indexName, tableName); | ||
| conn.createStatement().execute(ddl); | ||
| ddl = String.format("alter table %s set TTL = '%s'", tableName, retainSingleQuotes(ttl)); | ||
| conn.createStatement().execute(ddl); | ||
| assertTTL(conn, indexName, TTL_EXPRESSION_NOT_DEFINED); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -615,7 +661,7 @@ public void testScanColumns() throws Exception { | |
| String ddl = String.format(ddlTemplate, tableName, retainSingleQuotes(ttl)); | ||
| try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
| conn.createStatement().execute(ddl); | ||
| assertConditonTTL(conn, tableName, ttl); | ||
| assertConditionTTL(conn, tableName, ttl); | ||
| String query = String.format("select * from %s where k1 > 3", tableName); | ||
| // select * so all columns should be read | ||
| validateScan(conn, tableName, query, ttl, false, Collections.EMPTY_LIST); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@palashc I think it would be better if we can enhance the API
checkAndGetTTLFromHierarchyitself to return TTL_EXPRESSION_NOT_DEFINED in this case.