Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.0 2f114d2b2 -> 01cc2a02b
PHOENIX-2878 CURRENT_TIME fails to provide correct time when projected table is using Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/01cc2a02 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/01cc2a02 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/01cc2a02 Branch: refs/heads/4.x-HBase-1.0 Commit: 01cc2a02b8bca652b592a4455f378a8a1be11ad6 Parents: 2f114d2 Author: maryannxue <[email protected]> Authored: Thu May 5 10:49:42 2016 -0400 Committer: maryannxue <[email protected]> Committed: Thu May 5 10:49:42 2016 -0400 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/DateTimeIT.java | 17 +++++++++++++++++ .../apache/phoenix/compile/StatementContext.java | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/01cc2a02/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java ---------------------------------------------------------------------- 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 7e407bc..461816a 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 @@ -715,4 +715,21 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { assertEquals(111111113, rs.getTimestamp(2).getNanos()); assertFalse(rs.next()); } + + @Test + public void testCurrentTimeWithProjectedTable () throws Exception { + String ddl = "CREATE TABLE T1 ( ID integer primary key)"; + conn.createStatement().execute(ddl); + ddl = "CREATE TABLE T2 ( ID integer primary key)"; + conn.createStatement().execute(ddl); + String ups = "UPSERT INTO T1 VALUES (1)"; + conn.createStatement().execute(ups); + ups = "UPSERT INTO T2 VALUES (1)"; + conn.createStatement().execute(ups); + conn.commit(); + ResultSet rs = conn.createStatement().executeQuery("select /*+ USE_SORT_MERGE_JOIN */ op" + + ".id, current_time() from t1 op where op.id in (select id from t2)"); + assertTrue(rs.next()); + assertEquals(new java.util.Date().getYear(),rs.getTimestamp(2).getYear()); + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/01cc2a02/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java ---------------------------------------------------------------------- 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 9f4562a..8ced589 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 @@ -39,6 +39,7 @@ import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.schema.MetaDataClient; import org.apache.phoenix.schema.PColumn; import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.schema.PTableType; import org.apache.phoenix.schema.TableRef; import org.apache.phoenix.util.DateUtil; import org.apache.phoenix.util.NumberUtil; @@ -253,7 +254,9 @@ public class StatementContext { public long getCurrentTime() throws SQLException { long ts = this.getCurrentTable().getTimeStamp(); // 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().isTransactional() && ts != QueryConstants.UNSET_TIMESTAMP) { + if (this.getCurrentTable().getTable().getType() != PTableType.PROJECTED && !this + .getCurrentTable().getTable().isTransactional() && ts != QueryConstants + .UNSET_TIMESTAMP) { return ts; } if (currentTime != QueryConstants.UNSET_TIMESTAMP) {
