yanxinyi commented on a change in pull request #799:
URL: https://github.com/apache/phoenix/pull/799#discussion_r441089327



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java
##########
@@ -333,4 +356,120 @@ public void testFindAllRelativesForTenantConnection() 
throws Exception {
             }
         }
     }
+
+    @Test public void testGetViewWhereWithViewTTL() throws Exception {
+        String tenantId = generateUniqueName();
+        Properties tenantProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        String schema = generateUniqueName();
+
+        String multiTenantTableName = schema + "." + generateUniqueName();
+        String globalViewName = schema + "." + generateUniqueName();
+
+        String view1 = generateUniqueName();
+        String view2 = generateUniqueName();
+        String customObjectView1 = schema + "." + view1;
+        String customObjectView2 = schema + "." + view2;
+
+        String tenantView = generateUniqueName();
+        String tenantViewOnGlobalView = schema + "." + tenantView;
+        String tenantViewIndex = tenantView + "_INDEX";
+        String tenantIndex = schema + "." + tenantViewIndex;
+
+        String
+                multiTenantTableDDL =
+                "CREATE TABLE IF NOT EXISTS " + multiTenantTableName
+                        + "(TENANT_ID CHAR(15) NOT NULL, KP CHAR(3) NOT NULL, 
ID VARCHAR, NUM BIGINT "
+                        + "CONSTRAINT PK PRIMARY KEY (TENANT_ID, KP)) 
MULTI_TENANT=true";
+
+        String
+                globalViewDDL =
+                "CREATE VIEW IF NOT EXISTS " + globalViewName + "(G1 BIGINT, 
G2 BIGINT) "
+                        + "AS SELECT * FROM " + multiTenantTableName + " WHERE 
KP = '001' VIEW_TTL=30";
+
+        String viewDDL = "CREATE VIEW IF NOT EXISTS %s (V1 BIGINT, V2 BIGINT) 
AS SELECT * FROM %s VIEW_TTL=30";
+        String
+                viewIndexDDL =
+                "CREATE INDEX IF NOT EXISTS " + tenantViewIndex + " ON " + 
tenantViewOnGlobalView
+                        + "(NUM DESC) INCLUDE (ID)";
+
+        String
+                customObjectViewDDL =
+                "CREATE VIEW IF NOT EXISTS %s (V1 BIGINT, V2 BIGINT) " + "AS 
SELECT * FROM "
+                        + multiTenantTableName + " WHERE KP = '%s' 
VIEW_TTL=30";
+
+        String selectFromViewSQL = "SELECT * FROM %s";
+
+        List<String> dmls = Arrays.asList(new String[] {
+                String.format(viewDDL, tenantViewOnGlobalView, globalViewName),
+                String.format(customObjectViewDDL, customObjectView1, view1),
+                String.format(customObjectViewDDL, customObjectView2, view2),
+                viewIndexDDL
+        });
+
+        // Create the various tables and views
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Base table.
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute(multiTenantTableDDL);
+            }
+            // Global view.
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute(globalViewDDL);
+            }
+            // Tenant views and indexes.
+            try (Connection tenantConn = DriverManager.getConnection(getUrl(), 
tenantProps)) {
+                for (String dml : dmls) {
+                    try (Statement stmt = tenantConn.createStatement()) {
+                        stmt.execute(dml);
+                    }
+                }
+            }
+        }
+
+        List<String> sqls = Arrays.asList(new String[] {
+                String.format(selectFromViewSQL, tenantViewOnGlobalView),
+                String.format(selectFromViewSQL, customObjectView1),
+                String.format(selectFromViewSQL, customObjectView2),
+                String.format(selectFromViewSQL, tenantIndex)
+        });
+
+        // Validate the view where clause for the above sqls.
+        try (Connection tenantConn = DriverManager.getConnection(getUrl(), 
tenantProps)) {
+            for (String sql : sqls) {
+                try (Statement stmt = tenantConn.createStatement()) {
+                    PhoenixStatement pstmt = 
stmt.unwrap(PhoenixStatement.class);
+                    QueryPlan plan = pstmt.compileQuery(sql);
+                    validatePhoenixRowTimestampParseNodeExists(plan);
+                }
+            }
+        }
+
+    }
+

Review comment:
       can we add one more test for view without ttl but calling 
`getViewWhereWithPhoenixTTL` method to validate the right behavior?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to