yanxinyi commented on a change in pull request #724: PHOENIX-5629 Phoenix 
Function to Return HBase row timestamp
URL: https://github.com/apache/phoenix/pull/724#discussion_r405826813
 
 

 ##########
 File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRowTimestampFunctionIT.java
 ##########
 @@ -191,4 +225,130 @@ public void testRowTimestampColumn() throws Exception {
         }
     }
 
+
+    @Test
+    // case: No rows should have the phoenix_row_timestamp() = date column
+    // Since we used a future date for column PK2
+    public void testRowTimestampFunctionAndEqualPredicate() throws Exception {
+        long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() + 
TS_OFFSET;
+        String tableName = createTestData(rowTimestamp, NUM_ROWS);
+        // With phoenix_row_timestamp function only in projection
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String sql = "SELECT PHOENIX_ROW_TIMESTAMP() FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() = PK2 ";
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery(sql);
+                assertFalse(rs.next());
+                rs.close();
+            }
+        }
+
+        // With phoenix_row_timestamp function and additional columns in 
projection
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String sql = "SELECT PHOENIX_ROW_TIMESTAMP(), KV1 FROM " + 
tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() = PK2 ";
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery(sql);
+                assertFalse(rs.next());
+                rs.close();
+            }
+        }
+    }
+
+
+    @Test
+    // case: All rows selected should have the phoenix_row_timestamp() < date 
column
+    // Since we used a future date for column PK2
+    public void testRowTimestampFunctionOnlyWithLessThanPredicate() throws 
Exception {
+        long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() + 
TS_OFFSET;
+        String tableName = createTestData(rowTimestamp, NUM_ROWS);
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String sql = "SELECT PHOENIX_ROW_TIMESTAMP() FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() < PK2 ";
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery(sql);
+                int actualCount = 0;
+                while(rs.next()) {
+                    assertTrue(rs.getDate(1).before(new Date(rowTimestamp)));
+                    actualCount++;
+                }
+                assertEquals(NUM_ROWS, actualCount);
+                rs.close();
+            }
+        }
+    }
+
+    @Test
+    // case: All rows selected should have the phoenix_row_timestamp() < date 
column
+    // Since we used a future date for column PK2
+    // Additional columns should return non null values.
+    public void 
testRowTimestampFunctionAndAdditionalColsWithLessThanPredicate() throws 
Exception {
+        long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() + 
TS_OFFSET;
+        String tableName = createTestData(rowTimestamp, NUM_ROWS);
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String sql = "SELECT PHOENIX_ROW_TIMESTAMP(), KV2 FROM " + 
tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() < PK2 ";
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery(sql);
+                int actualCount = 0;
+                while(rs.next()) {
+                    assertTrue(rs.getDate(1).before(new Date(rowTimestamp)));
+                    rs.getString(2);
+                    assertFalse(rs.wasNull());
+                    actualCount++;
+                }
+                assertEquals(NUM_ROWS, actualCount);
+                rs.close();
+            }
+        }
+
+    }
+
+    @Test
+    // case: All rows selected should have the phoenix_row_timestamp() > date 
column
+    // Since we used a past date for column PK2
+    public void testRowTimestampFunctionOnlyWithGreaterThanPredicate() throws 
Exception {
+        long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() - 
TS_OFFSET;
+        String tableName = createTestData(rowTimestamp, NUM_ROWS);
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String sql = "SELECT PHOENIX_ROW_TIMESTAMP() FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() > PK2 ";
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery(sql);
+                int actualCount = 0;
+                while(rs.next()) {
+                    assertTrue(rs.getDate(1).after(new Date(rowTimestamp)));
+                    actualCount++;
+                }
+                assertEquals(NUM_ROWS, actualCount);
+                rs.close();
+            }
+        }
+    }
+
+    @Test
+    // case: All rows selected should have the phoenix_row_timestamp() > date 
column
+    // Since we used a past date for column PK2
+    // Additional columns should return non null values.
+    public void 
testRowTimestampFunctionAndAdditionalColsWithGreaterThanPredicate() throws 
Exception {
+        long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() - 
TS_OFFSET;
+        String tableName = createTestData(rowTimestamp, NUM_ROWS);
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String sql = "SELECT PHOENIX_ROW_TIMESTAMP(), KV1 FROM " + 
tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() > PK2 ";
+            try (Statement stmt = conn.createStatement()) {
+                ResultSet rs = stmt.executeQuery(sql);
+                int actualCount = 0;
+                while(rs.next()) {
+                    assertTrue(rs.getDate(1).after(new Date(rowTimestamp)));
+                    rs.getString(2);
+                    assertFalse(rs.wasNull());
+                    actualCount++;
+                }
+                assertEquals(NUM_ROWS, actualCount);
+                rs.close();
+            }
+        }
+    }
+
 
 Review comment:
   better to support test for `SELECT COLUMN_ONLY WHERE 
PHOENIX_ROW_TIMESTAMP()` predicate. 

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


With regards,
Apache Git Services

Reply via email to