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:54:22 UTC
[phoenix] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 86f158b PHOENIX-5388 Incorrect current_date()/now() when query involves subquery(Ankit Singhal)
86f158b is described below
commit 86f158bd613c8e0df927cd35d8442863886983e5
Author: Rajeshbabu Chintaguntla <Rajeshbabu Chintaguntla>
AuthorDate: Fri Jul 19 12:24:11 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 df94a70..c76481e 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
@@ -441,6 +441,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 bbbfc5e..bfaa066 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;
}