phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffr...@apache.org
Subject [46/50] [abbrv] git commit: Add test case for PHOENIX-3 TRUNC method doesn't work on column of datatype timestamp
Date Wed, 05 Mar 2014 22:55:32 GMT
Add test case for PHOENIX-3 TRUNC method doesn't work on column of datatype timestamp


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

Branch: refs/heads/4.0
Commit: b36daea7f6408cf249a25663803f9ed1b8db608c
Parents: 953795c
Author: maryannxue <maryannxue@apache.org>
Authored: Tue Mar 4 21:50:36 2014 -0500
Committer: maryannxue <maryannxue@apache.org>
Committed: Tue Mar 4 21:50:36 2014 -0500

----------------------------------------------------------------------
 .../phoenix/end2end/TruncateFunctionTest.java   | 121 +++++++++++++++++++
 1 file changed, 121 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b36daea7/phoenix-core/src/test/java/org/apache/phoenix/end2end/TruncateFunctionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/TruncateFunctionTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/end2end/TruncateFunctionTest.java
new file mode 100644
index 0000000..70555b8
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/TruncateFunctionTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.PhoenixRuntime.CURRENT_SCN_ATTRIB;
+import static org.apache.phoenix.util.TestUtil.ATABLE_NAME;
+import static org.apache.phoenix.util.TestUtil.ROW1;
+import static org.apache.phoenix.util.TestUtil.ROW2;
+import static org.apache.phoenix.util.TestUtil.ROW3;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Timestamp;
+import java.text.Format;
+import java.text.ParseException;
+import java.util.Properties;
+
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.DateUtil;
+import org.junit.Test;
+
+public class TruncateFunctionTest extends BaseClientManagedTimeTest {
+    private static Format format = DateUtil.getDateParser(DateUtil.DEFAULT_MS_DATE_FORMAT);
+    private static final String DS1 = "1970-01-10 00:58:01.587";
+    private static final String DS2 = "1970-01-20 01:02:45.906";
+    private static final String DS3 = "1970-01-30 01:30:24.353";
+    
+    private static Date toDate(String s) throws ParseException {
+        return (Date) (format.parseObject(s));
+    }
+    
+    private static Timestamp toTimestamp(String s) throws ParseException {
+        return new Timestamp(((Date) (format.parseObject(s))).getTime());
+    }
+    
+    @Test
+    public void testTruncate() throws Exception {
+        long ts = nextTimestamp();
+        String tenantId = getOrganizationId();
+        ensureTableCreated(getUrl(), ATABLE_NAME, ts-5);
+        Properties props = new Properties();
+        props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts-3));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement stmt = conn.prepareStatement(
+                    "upsert into " +
+                    "ATABLE(" +
+                    "    ORGANIZATION_ID, " +
+                    "    ENTITY_ID, " +
+                    "    A_DATE, " +
+                    "    A_TIMESTAMP)" +
+                    "VALUES (?, ?, ?, ?)");
+            stmt.setString(1, tenantId);
+            stmt.setString(2, ROW1);
+            stmt.setDate(3, toDate(DS1));
+            stmt.setTimestamp(4, toTimestamp(DS1));
+            stmt.execute();
+            stmt.setString(1, tenantId);
+            stmt.setString(2, ROW2);
+            stmt.setDate(3, toDate(DS2));
+            stmt.setTimestamp(4, toTimestamp(DS2));
+            stmt.execute();
+            stmt.setString(1, tenantId);
+            stmt.setString(2, ROW3);
+            stmt.setDate(3, toDate(DS3));
+            stmt.setTimestamp(4, toTimestamp(DS3));
+            stmt.execute();
+            conn.commit();
+            conn.close();
+            
+            props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts+1));
+            conn = DriverManager.getConnection(getUrl(), props);
+            String query = "SELECT entity_id, trunc(a_date, 'day', 7), trunc(a_timestamp,
'second', 10) FROM ATABLE WHERE organization_id = ?";
+            PreparedStatement statement = conn.prepareStatement(query);
+            statement.setString(1, tenantId);
+            ResultSet rs = statement.executeQuery();
+            
+            assertTrue (rs.next());
+            assertEquals(ROW1, rs.getString(1));
+            assertEquals(new Date((long) 7 * QueryConstants.MILLIS_IN_DAY), rs.getDate(2));
+            assertEquals(toTimestamp("1970-01-10 00:58:00.000"), rs.getTimestamp(3));
+            
+            assertTrue (rs.next());
+            assertEquals(ROW2, rs.getString(1));
+            assertEquals(new Date((long) 14 * QueryConstants.MILLIS_IN_DAY), rs.getDate(2));
+            assertEquals(toTimestamp("1970-01-20 01:02:40.000"), rs.getTimestamp(3));
+            
+            assertTrue (rs.next());
+            assertEquals(ROW3, rs.getString(1));
+            assertEquals(new Date((long) 28 * QueryConstants.MILLIS_IN_DAY), rs.getDate(2));
+            assertEquals(toTimestamp("1970-01-30 01:30:20.000"), rs.getTimestamp(3));
+            
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+    }
+
+}
+


Mime
View raw message