You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2019/07/19 06:56:42 UTC

[phoenix] branch 4.x-HBase-1.4 updated: PHOENIX-5388 Incorrect current_date()/now() when query involves subquery(Ankit Singhal)

This is an automated email from the ASF dual-hosted git repository.

rajeshbabu pushed a commit to branch 4.x-HBase-1.4
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.4 by this push:
     new 49e04d5  PHOENIX-5388 Incorrect current_date()/now() when query involves subquery(Ankit Singhal)
49e04d5 is described below

commit 49e04d5608b8648392ca7d79d0183ef9e9615033
Author: Rajeshbabu Chintaguntla <Rajeshbabu Chintaguntla>
AuthorDate: Fri Jul 19 12:25:28 2019 +0530

    PHOENIX-5388 Incorrect current_date()/now() when query involves subquery(Ankit Singhal)
---
 .../src/it/java/org/apache/phoenix/end2end/DateTimeIT.java  | 13 +++++++++++++
 .../java/org/apache/phoenix/compile/StatementContext.java   |  7 ++++---
 .../src/main/java/org/apache/phoenix/schema/TableRef.java   |  2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index cc7c7a7..6e48d67 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -440,6 +440,19 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
     }
 
     @Test
+    public void testNowWithSubquery() throws Exception {
+        String query =
+                "SELECT now(), reference_date FROM (select now() as "
+                        + "reference_date union all select now() as reference_date) limit 1";
+        Statement statement = conn.createStatement();
+        ResultSet rs = statement.executeQuery(query);
+        assertTrue(rs.next());
+        assertTrue(Math.abs(rs.getTime(1).getTime()-rs.getTime(2).getTime())<10000);
+        assertEquals(rs.getDate(2).toString(), rs.getDate(1).toString());
+        assertFalse(rs.next());
+    }
+
+    @Test
     public void testSelectLiteralDate() throws Exception {
         String s = DateUtil.DEFAULT_DATE_FORMATTER.format(date);
         String query = "SELECT DATE '" + s + "' FROM " + this.tableName;
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
index cc38870..b477049 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
@@ -260,9 +260,10 @@ public class StatementContext {
     public long getCurrentTime() throws SQLException {
         long ts = this.getCurrentTable().getCurrentTime();
         // if the table is transactional then it is only resolved once per query, so we can't use the table timestamp
-        if (this.getCurrentTable().getTable().getType() != PTableType.PROJECTED && !this
-                .getCurrentTable().getTable().isTransactional() && ts != QueryConstants
-                .UNSET_TIMESTAMP) {
+        if (this.getCurrentTable().getTable().getType() != PTableType.SUBQUERY
+                && this.getCurrentTable().getTable().getType() != PTableType.PROJECTED
+                && !this.getCurrentTable().getTable().isTransactional()
+                && ts != QueryConstants.UNSET_TIMESTAMP) {
             return ts;
         }
         if (currentTime != QueryConstants.UNSET_TIMESTAMP) {
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableRef.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableRef.java
index b40c0b8..5f426b0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableRef.java
@@ -80,9 +80,9 @@ public class TableRef {
         boolean hasDynamicCols) {
         this.alias = alias;
         this.table = table;
-        this.currentTime = upperBoundTimeStamp;
         // if UPDATE_CACHE_FREQUENCY is set, always let the server set timestamps
         this.upperBoundTimeStamp = table.getUpdateCacheFrequency()!=0 ? QueryConstants.UNSET_TIMESTAMP : upperBoundTimeStamp;
+        this.currentTime = this.upperBoundTimeStamp;
         this.lowerBoundTimeStamp = lowerBoundTimeStamp;
         this.hasDynamicCols = hasDynamicCols;
     }