phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [2/3] phoenix git commit: PHOENIX-2734 Literal expressions for UNSIGNED_DATE/UNSIGNED_TIME/etc (Sergey Soldatov)
Date Mon, 28 Mar 2016 15:35:22 GMT
PHOENIX-2734 Literal expressions for UNSIGNED_DATE/UNSIGNED_TIME/etc (Sergey Soldatov)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/d4d973c7
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d4d973c7
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d4d973c7

Branch: refs/heads/master
Commit: d4d973c7b9fd5bb6bd206c9082c4c6d53e54c59b
Parents: bea110c
Author: James Taylor <jtaylor@salesforce.com>
Authored: Mon Mar 28 08:22:37 2016 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Mon Mar 28 08:22:37 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DateTimeIT.java  | 20 ++++++++++++++++++++
 .../phoenix/expression/LiteralExpression.java   | 12 ++++--------
 2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d4d973c7/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 e87d8d4..af8f0c1 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
@@ -513,6 +513,26 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT {
     }
 
     @Test
+    public void testUnsignedTimeDateWithLiteral() throws Exception {
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS UT (k1 INTEGER NOT NULL," +
+                        "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP,
unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO UT VALUES (1, " +
+                "'2010-06-20 12:00:00', '2012-07-28 12:00:00', '2015-12-25 12:00:00')";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT k1, unsignedDates, " +
+                "unsignedTimestamps, unsignedTimes FROM UT where k1 = 1");
+        assertTrue(rs.next());
+        assertEquals(DateUtil.parseDate("2010-06-20 12:00:00"), rs.getDate(2));
+        assertEquals(DateUtil.parseTimestamp("2012-07-28 12:00:00"), rs.getTimestamp(3));
+        assertEquals(DateUtil.parseTime("2015-12-25 12:00:00"), rs.getTime(4));
+        assertFalse(rs.next());
+    }
+
+    @Test
     public void testSecondFuncAgainstColumns() throws Exception {
         String ddl =
                 "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps
TIMESTAMP, times TIME, " +

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d4d973c7/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
index ad1c7c0..90882a2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
@@ -25,6 +25,7 @@ import java.sql.SQLException;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
+import org.apache.phoenix.schema.IllegalDataException;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -182,16 +183,11 @@ public class LiteralExpression extends BaseTerminalExpression {
             return getBooleanLiteralExpression((Boolean)value, determinism);
         }
         PDataType actualType = PDataType.fromLiteral(value);
-        // For array we should check individual element in it?
-        // It would be costly though!!!!!
-        // UpsertStatement can try to cast varchar to date type but PVarchar can't CoercibleTo
Date or Timestamp
-        // otherwise TO_NUMBER like functions will fail
-        if (!actualType.isCoercibleTo(type, value) &&
-                (!actualType.equals(PVarchar.INSTANCE) ||
-                        !(type.equals(PDate.INSTANCE) || type.equals(PTimestamp.INSTANCE)
|| type.equals(PTime.INSTANCE)))) {
+        try {
+            value = type.toObject(value, actualType);
+        } catch (IllegalDataException e) {
             throw TypeMismatchException.newException(type, actualType, value.toString());
         }
-        value = type.toObject(value, actualType);
         byte[] b = type.isArrayType() ? ((PArrayDataType)type).toBytes(value, PArrayDataType.arrayBaseType(type),
sortOrder, rowKeyOrderOptimizable) :
                 type.toBytes(value, sortOrder);
         if (type == PVarchar.INSTANCE || type == PChar.INSTANCE) {


Mime
View raw message