You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/03/13 20:27:38 UTC

[GitHub] [phoenix] ChinmaySKulkarni commented on a change in pull request #724: PHOENIX-5629 Phoenix Function to Return HBase row timestamp

ChinmaySKulkarni 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_r392448417
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRowTimestampFunctionIT.java
 ##########
 @@ -191,4 +192,158 @@ public void testRowTimestampColumn() throws Exception {
         }
     }
 
+    @Test
+    public void testRowTimestampColumnAndPredicates() throws Exception {
+        String tableName =  generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
+                    + " (PK1 INTEGER NOT NULL, PK2 DATE NOT NULL, KV1 VARCHAR, KV2 VARCHAR"
+                    + " CONSTRAINT PK PRIMARY KEY(PK1, PK2))" + this.tableDDLOptions;
+            conn.createStatement().execute(ddl);
+
+            String dml = "UPSERT INTO " + tableName + " (PK1, PK2, KV1, KV2) VALUES (?, ?, ?, ?)";
+
+            long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis();
+            Date rowTimestampDate1 = new Date(rowTimestamp - 120000);
+            PreparedStatement stmt = conn.prepareStatement(dml);
+
+            int count = 5;
+            for (int id = 0; id < count; ++id) {
+                int idValue = id;
+                stmt.setInt(1, idValue);
+                stmt.setDate(2, rowTimestampDate1);
+                stmt.setString(3, "KV1_" + idValue);
+                stmt.setString(4, "KV2_" + idValue);
+                stmt.executeUpdate();
+            }
+            conn.commit();
+
+            // case: No rows should be selected
+            // Since we used a past date for column PK2
+            String dql1 = "SELECT PHOENIX_ROW_TIMESTAMP(), KV1 FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() = PK2";
+
+            ResultSet rs1 = conn.createStatement().executeQuery(dql1);
+            assertTrue(!rs1.next());
+            rs1.close();
+
+            // case: All rows selected should have the phoenix_row_timestamp() > date column
+            // Since we used a past date for column PK2
+            String dql2 = "SELECT PHOENIX_ROW_TIMESTAMP(), KV1 FROM " + tableName +
+                    " WHERE PK2 < PHOENIX_ROW_TIMESTAMP() ";
+
+            ResultSet rs2 = conn.createStatement().executeQuery(dql2);
+            int actualCount2 = 0;
+            while(rs2.next()) {
+                assertTrue(rs2.getDate(1).after(rowTimestampDate1));
+                actualCount2++;
+            }
+            assertEquals(count, actualCount2);
+            rs2.close();
+
+            // case: All rows selected should have the phoenix_row_timestamp() < date column
+            // So using a future date.
+            Date rowTimestampDate2 = new Date(rowTimestamp + 120000);
+            for (int id = 0; id < count; ++id) {
+                int idValue = id + 100;
+                stmt.setInt(1, idValue);
+                stmt.setDate(2, rowTimestampDate2);
+                stmt.setString(3, "KV1_" + idValue);
+                stmt.setString(4, "KV2_" + idValue);
+                stmt.executeUpdate();
+            }
+            conn.commit();
+
+            String dql3 = "SELECT PHOENIX_ROW_TIMESTAMP(), KV2 FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() < PK2";
+
+            ResultSet rs3 = conn.createStatement().executeQuery(dql3);
+            int actualCount3 = 0;
+            while(rs3.next()) {
+                assertTrue(rs3.getDate(1).before(rowTimestampDate2));
+                actualCount3++;
+            }
+            assertEquals(count, actualCount3);
+            rs3.close();
+        }
+    }
+
+    @Ignore("Fails when encoding=NON_ENCODED_QUALIFIERS and PHOENIX_ROW_TIMESTAMP "
+            + "is the only select column"
+            + "Expected rows do match expected:<5> but was:<0>")
+    public void testRowTimestampColumnOnlyAndPredicates() throws Exception {
+        String tableName =  generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
+                    + " (PK1 INTEGER NOT NULL, PK2 DATE NOT NULL, KV1 VARCHAR, KV2 VARCHAR"
+                    + " CONSTRAINT PK PRIMARY KEY(PK1, PK2))" + this.tableDDLOptions;
+            conn.createStatement().execute(ddl);
+
+            String dml = "UPSERT INTO " + tableName + " (PK1, PK2, KV1, KV2) VALUES (?, ?, ?, ?)";
+
+            long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis();
+            Date rowTimestampDate1 = new Date(rowTimestamp - 120000);
+            PreparedStatement stmt = conn.prepareStatement(dml);
+
+            int count = 5;
+            for (int id = 0; id < count; ++id) {
+                int idValue = id;
+                stmt.setInt(1, idValue);
+                stmt.setDate(2, rowTimestampDate1);
+                stmt.setString(3, "KV1_" + idValue);
+                stmt.setString(4, "KV2_" + idValue);
+                stmt.executeUpdate();
+            }
+            conn.commit();
+
+            // case: No rows should be selected
+            // Since we used a past date for column PK2
+            String dql1 = "SELECT PHOENIX_ROW_TIMESTAMP() FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() = PK2";
+
+            ResultSet rs1 = conn.createStatement().executeQuery(dql1);
+            assertTrue(!rs1.next());
+            rs1.close();
+
+            // case: All rows selected should have the phoenix_row_timestamp() > date column
+            // Since we used a past date for column PK2
+            String dql2 = "SELECT PHOENIX_ROW_TIMESTAMP() FROM " + tableName +
+                    " WHERE PK2 < PHOENIX_ROW_TIMESTAMP() ";
+
+            ResultSet rs2 = conn.createStatement().executeQuery(dql2);
+            int actualCount2 = 0;
+            while(rs2.next()) {
+                assertTrue(rs2.getDate(1).after(rowTimestampDate1));
+                actualCount2++;
+            }
+            assertEquals(count, actualCount2);
+            rs2.close();
+
+            // case: All rows selected should have the phoenix_row_timestamp() < date column
+            // So using a future date.
+            Date rowTimestampDate2 = new Date(rowTimestamp + 120000);
+            for (int id = 0; id < count; ++id) {
+                int idValue = id + 100;
+                stmt.setInt(1, idValue);
+                stmt.setDate(2, rowTimestampDate2);
+                stmt.setString(3, "KV1_" + idValue);
+                stmt.setString(4, "KV2_" + idValue);
+                stmt.executeUpdate();
+            }
+            conn.commit();
+
+            String dql3 = "SELECT PHOENIX_ROW_TIMESTAMP() FROM " + tableName +
+                    " WHERE PHOENIX_ROW_TIMESTAMP() < PK2";
+
+            ResultSet rs3 = conn.createStatement().executeQuery(dql3);
+            int actualCount3 = 0;
+            while(rs3.next()) {
+                assertTrue(rs3.getDate(1).before(rowTimestampDate2));
+                actualCount3++;
+            }
+            assertEquals(count, actualCount3);
+            rs3.close();
+        }
+    }
+
 }
 
 Review comment:
   @jpisaac  Since we rely on the empty column timestamp to be reflected as the `PHOENIX_ROW_TIMESTAMP()`, should we add tests to confirm this? Also perhaps add tests that confirm that this is modified whenever a row is updated

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services