This is an automated email from the ASF dual-hosted git repository. yanxinyi pushed a commit to branch 4.x in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push: new 6ecc667 PHOENIX-5935 Select with non primary keys and PHOENIX_ROW_TIMESTAMP() in where clause fails 6ecc667 is described below commit 6ecc66738e576a5349605c2f5b20003df03f95de Author: Jacob Isaac <jis...@salesforce.com> AuthorDate: Tue Jun 2 20:48:49 2020 -0700 PHOENIX-5935 Select with non primary keys and PHOENIX_ROW_TIMESTAMP() in where clause fails Signed-off-by: Xinyi Yan <yanxi...@apache.org> --- .../end2end/PhoenixRowTimestampFunctionIT.java | 21 +++++++++++++++++++++ .../function/PhoenixRowTimestampFunction.java | 9 ++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRowTimestampFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRowTimestampFunctionIT.java index d28a929..8b4dfb6 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRowTimestampFunctionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRowTimestampFunctionIT.java @@ -415,6 +415,27 @@ public class PhoenixRowTimestampFunctionIT extends ParallelStatsDisabledIT { } @Test + // case: Select with non primary keys in where clause. + public void testSelectWithMultiplePredicates() throws Exception { + long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() - TS_OFFSET; + String tableName = createTestData(rowTimestamp, NUM_ROWS); + try (Connection conn = DriverManager.getConnection(getUrl())) { + String sql = "SELECT COUNT(*) FROM " + tableName + + " WHERE PHOENIX_ROW_TIMESTAMP() > PK2 AND KV1 = 'KV1_1'"; + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery(sql); + while(rs.next()) { + int rowCount = rs.getInt(1); + assertFalse(rs.wasNull()); + assertTrue(rowCount == 1); + } + rs.close(); + } + } + } + + + @Test // case: Comparision with TO_TIME() public void testTimestampComparePredicate() throws Exception { long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis() - TS_OFFSET; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PhoenixRowTimestampFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PhoenixRowTimestampFunction.java index b98fc83..050a046 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PhoenixRowTimestampFunction.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PhoenixRowTimestampFunction.java @@ -95,11 +95,18 @@ public class PhoenixRowTimestampFunction extends ScalarFunction { byte[] emptyCF = ((KeyValueColumnExpression)children.get(0)).getColumnFamily(); byte[] emptyCQ = ((KeyValueColumnExpression)children.get(0)).getColumnQualifier(); - long ts = tuple.getValue(0).getTimestamp(); + long ts; + // Currently there is no good way to figure out if this function is being evaluated during + // result or filter processing. + // For now relying on whether empty column exists, + // if true indicates filter processing else result processing. Cell emptyColumnKV = tuple.getValue(emptyCF, emptyCQ); if ((emptyColumnKV != null) && CellUtil.matchingColumn(emptyColumnKV, emptyCF, emptyCQ)) { ts = emptyColumnKV.getTimestamp(); + } else { + ts = tuple.getValue(0).getTimestamp(); } + Date rowTimestamp = new Date(ts); ptr.set(PDate.INSTANCE.toBytes(rowTimestamp)); return true;