phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravimag...@apache.org
Subject [6/6] phoenix git commit: PHOENIX-2031 - Unable to process timestamp/Date data loaded via Phoenix org.apache.phoenix.pig.PhoenixHBaseLoader - (ayingshu)
Date Fri, 21 Aug 2015 04:22:06 GMT
PHOENIX-2031 - Unable to process timestamp/Date data loaded via Phoenix org.apache.phoenix.pig.PhoenixHBaseLoader
- (ayingshu)


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

Branch: refs/heads/4.5-HBase-0.98
Commit: 782746329ed2d6717153b8b939e45d2e0c72167b
Parents: 5f04657
Author: ravimagham <ravimagham@apache.org>
Authored: Thu Aug 20 21:21:43 2015 -0700
Committer: ravimagham <ravimagham@apache.org>
Committed: Thu Aug 20 21:21:43 2015 -0700

----------------------------------------------------------------------
 .../phoenix/pig/PhoenixHBaseLoaderIT.java       | 89 +++++++++++++++++++-
 .../org/apache/phoenix/pig/util/TypeUtil.java   |  5 +-
 2 files changed, 91 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/78274632/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java b/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
index 4f57f27..6a5923c 100644
--- a/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
+++ b/phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java
@@ -19,11 +19,11 @@
  */
 package org.apache.phoenix.pig;
 
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+import static org.apache.phoenix.util.TestUtil.LOCALHOST;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
-import static org.apache.phoenix.util.TestUtil.LOCALHOST;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -51,6 +51,7 @@ import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+
 import com.google.common.base.Preconditions;
 
 /**
@@ -396,6 +397,90 @@ public class PhoenixHBaseLoaderIT extends BaseHBaseManagedTimeIT {
         List<Tuple> actualList = data.get("out");
         assertEquals(expectedList, actualList);
     }
+	 
+    @Test
+    public void testTimestampForSQLQuery() throws Exception {
+        try {
+            //create the table
+            String ddl = "CREATE TABLE TIMESTAMP_T (MYKEY VARCHAR,DATE_STP TIMESTAMP CONSTRAINT
PK PRIMARY KEY (MYKEY)) ";
+            conn.createStatement().execute(ddl);
+
+            final String dml = "UPSERT INTO TIMESTAMP_T VALUES('foo',TO_TIMESTAMP('2006-04-12
00:00:00'))";
+            conn.createStatement().execute(dml);
+            conn.commit();
+
+            //sql query
+            final String sqlQuery = " SELECT mykey, year(DATE_STP) FROM TIMESTAMP_T ";
+            pigServer.registerQuery(String.format(
+                "A = load 'hbase://query/%s' using org.apache.phoenix.pig.PhoenixHBaseLoader('%s');",
sqlQuery,
+                zkQuorum));
+
+            final Iterator<Tuple> iterator = pigServer.openIterator("A");
+            while (iterator.hasNext()) {
+                Tuple tuple = iterator.next();
+                assertEquals("foo", tuple.get(0));
+                assertEquals(2006, tuple.get(1));
+            }
+        } finally {
+            dropTable("TIMESTAMP_T");
+        }
+    }
+    
+    @Test
+    public void testDateForSQLQuery() throws Exception {
+        try {
+            //create the table
+            String ddl = "CREATE TABLE DATE_T (MYKEY VARCHAR,DATE_STP Date CONSTRAINT PK
PRIMARY KEY (MYKEY)) ";
+            conn.createStatement().execute(ddl);
+
+            final String dml = "UPSERT INTO DATE_T VALUES('foo',TO_DATE('2004-03-10 10:00:00'))";
+            conn.createStatement().execute(dml);
+            conn.commit();
+
+            //sql query
+            final String sqlQuery = " SELECT mykey, hour(DATE_STP) FROM DATE_T ";
+            pigServer.registerQuery(String.format(
+                "A = load 'hbase://query/%s' using org.apache.phoenix.pig.PhoenixHBaseLoader('%s');",
sqlQuery,
+                zkQuorum));
+
+            final Iterator<Tuple> iterator = pigServer.openIterator("A");
+            while (iterator.hasNext()) {
+                Tuple tuple = iterator.next();
+                assertEquals("foo", tuple.get(0));
+                assertEquals(10, tuple.get(1));
+            }
+        } finally {
+            dropTable("DATE_T");
+        }
+    }
+
+    @Test
+    public void testTimeForSQLQuery() throws Exception {
+        try {
+            //create the table
+            String ddl = "CREATE TABLE TIME_T (MYKEY VARCHAR,DATE_STP TIME CONSTRAINT PK
PRIMARY KEY (MYKEY)) ";
+            conn.createStatement().execute(ddl);
+
+            final String dml = "UPSERT INTO TIME_T VALUES('foo',TO_TIME('2008-05-16 00:30:00'))";
+            conn.createStatement().execute(dml);
+            conn.commit();
+
+            //sql query
+            final String sqlQuery = " SELECT mykey, minute(DATE_STP) FROM TIME_T ";
+            pigServer.registerQuery(String.format(
+                "A = load 'hbase://query/%s' using org.apache.phoenix.pig.PhoenixHBaseLoader('%s');",
sqlQuery,
+                zkQuorum));
+
+            final Iterator<Tuple> iterator = pigServer.openIterator("A");
+            while (iterator.hasNext()) {
+                Tuple tuple = iterator.next();
+                assertEquals("foo", tuple.get(0));
+                assertEquals(30, tuple.get(1));
+            }
+        } finally {
+            dropTable("TIME_T");
+        }
+    }
     
     /**
      * Tests both  {@link PhoenixHBaseLoader} and {@link PhoenixHBaseStorage} 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/78274632/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
index 5820ec6..53d3ae3 100644
--- a/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
+++ b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
@@ -278,7 +278,10 @@ public final class TypeUtil {
                     tuple.set(i, DataType.toBoolean(object));
                     break;
                 case DataType.DATETIME:
-                    tuple.set(i, DataType.toDateTime(object));
+                    if (object instanceof java.sql.Timestamp)
+                        tuple.set(i,new DateTime(((java.sql.Timestamp)object).getTime()));
+                    else
+                        tuple.set(i,new DateTime(object));
                     break;
                 case DataType.BIGDECIMAL:
                     tuple.set(i, DataType.toBigDecimal(object));


Mime
View raw message