You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by se...@apache.org on 2015/03/28 01:22:27 UTC
svn commit: r1669718 [15/29] - in /hive/branches/llap: ./
ant/src/org/apache/hadoop/hive/ant/
common/src/java/org/apache/hadoop/hive/common/
common/src/java/org/apache/hadoop/hive/common/type/
common/src/java/org/apache/hadoop/hive/conf/ common/src/jav...
Modified: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java (original)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java Sat Mar 28 00:22:15 2015
@@ -695,7 +695,7 @@ public class TestOrcFile {
assertEquals(5000, ((StringColumnStatistics)ss3.getColumnStatistics()[2]).getSum());
RecordReaderImpl recordReader = (RecordReaderImpl) reader.rows();
- OrcProto.RowIndex[] index = recordReader.readRowIndex(0, null).getRowGroupIndex();
+ OrcProto.RowIndex[] index = recordReader.readRowIndex(0, null, null).getRowGroupIndex();
assertEquals(3, index.length);
List<OrcProto.RowIndexEntry> items = index[1].getEntryList();
assertEquals(1, items.size());
@@ -705,7 +705,7 @@ public class TestOrcFile {
assertEquals(0, items.get(0).getPositions(2));
assertEquals(1,
items.get(0).getStatistics().getIntStatistics().getMinimum());
- index = recordReader.readRowIndex(1, null).getRowGroupIndex();
+ index = recordReader.readRowIndex(1, null, null).getRowGroupIndex();
assertEquals(3, index.length);
items = index[1].getEntryList();
assertEquals(2,
Added: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone1.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone1.java?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone1.java (added)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone1.java Sat Mar 28 00:22:15 2015
@@ -0,0 +1,194 @@
+/**
+ * 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.hadoop.hive.ql.io.orc;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+import java.io.File;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector;
+import org.apache.hive.common.util.HiveTestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import com.google.common.collect.Lists;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class TestOrcTimezone1 {
+ Path workDir = new Path(System.getProperty("test.tmp.dir",
+ "target" + File.separator + "test" + File.separator + "tmp"));
+ Configuration conf;
+ FileSystem fs;
+ Path testFilePath;
+ String writerTimeZone;
+ String readerTimeZone;
+ static TimeZone defaultTimeZone = TimeZone.getDefault();
+
+ public TestOrcTimezone1(String writerTZ, String readerTZ) {
+ this.writerTimeZone = writerTZ;
+ this.readerTimeZone = readerTZ;
+ }
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> data() {
+ List<Object[]> result = Arrays.asList(new Object[][]{
+ /* Extreme timezones */
+ {"GMT-12:00", "GMT+14:00"},
+ /* No difference in DST */
+ {"America/Los_Angeles", "America/Los_Angeles"}, /* same timezone both with DST */
+ {"Europe/Berlin", "Europe/Berlin"}, /* same as above but europe */
+ {"America/Phoenix", "Asia/Kolkata"} /* Writer no DST, Reader no DST */,
+ {"Europe/Berlin", "America/Los_Angeles"} /* Writer DST, Reader DST */,
+ {"Europe/Berlin", "America/Chicago"} /* Writer DST, Reader DST */,
+ /* With DST difference */
+ {"Europe/Berlin", "UTC"},
+ {"UTC", "Europe/Berlin"} /* Writer no DST, Reader DST */,
+ {"America/Los_Angeles", "Asia/Kolkata"} /* Writer DST, Reader no DST */,
+ {"Europe/Berlin", "Asia/Kolkata"} /* Writer DST, Reader no DST */,
+ /* Timezone offsets for the reader has changed historically */
+ {"Asia/Saigon", "Pacific/Enderbury"},
+ {"UTC", "Asia/Jerusalem"},
+
+ // NOTE:
+ // "1995-01-01 03:00:00.688888888" this is not a valid time in Pacific/Enderbury timezone.
+ // On 1995-01-01 00:00:00 GMT offset moved from -11:00 hr to +13:00 which makes all values
+ // on 1995-01-01 invalid. Try this with joda time
+ // new MutableDateTime("1995-01-01", DateTimeZone.forTimeZone(readerTimeZone));
+ });
+ return result;
+ }
+
+ @Rule
+ public TestName testCaseName = new TestName();
+
+ @Before
+ public void openFileSystem() throws Exception {
+ conf = new Configuration();
+ fs = FileSystem.getLocal(conf);
+ testFilePath = new Path(workDir, "TestOrcFile." +
+ testCaseName.getMethodName() + ".orc");
+ fs.delete(testFilePath, false);
+ }
+
+ @After
+ public void restoreTimeZone() {
+ TimeZone.setDefault(defaultTimeZone);
+ }
+
+ @Test
+ public void testTimestampWriter() throws Exception {
+ ObjectInspector inspector;
+ synchronized (TestOrcFile.class) {
+ inspector = ObjectInspectorFactory.getReflectionObjectInspector(Timestamp.class,
+ ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
+ }
+
+ TimeZone.setDefault(TimeZone.getTimeZone(writerTimeZone));
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf).inspector(inspector).stripeSize(100000).bufferSize(10000));
+ assertEquals(writerTimeZone, TimeZone.getDefault().getID());
+ List<String> ts = Lists.newArrayList();
+ ts.add("2003-01-01 01:00:00.000000222");
+ ts.add("1996-08-02 09:00:00.723100809");
+ ts.add("1999-01-01 02:00:00.999999999");
+ ts.add("1995-01-02 03:00:00.688888888");
+ ts.add("2002-01-01 04:00:00.1");
+ ts.add("2010-03-02 05:00:00.000009001");
+ ts.add("2005-01-01 06:00:00.000002229");
+ ts.add("2006-01-01 07:00:00.900203003");
+ ts.add("2003-01-01 08:00:00.800000007");
+ ts.add("1998-11-02 10:00:00.857340643");
+ ts.add("2008-10-02 11:00:00.0");
+ ts.add("9999-01-01 00:00:00.000999");
+ ts.add("2014-03-28 00:00:00.0");
+ for (String t : ts) {
+ writer.addRow(Timestamp.valueOf(t));
+ }
+ writer.close();
+
+ TimeZone.setDefault(TimeZone.getTimeZone(readerTimeZone));
+ Reader reader = OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+ assertEquals(readerTimeZone, TimeZone.getDefault().getID());
+ RecordReader rows = reader.rows(null);
+ int idx = 0;
+ while (rows.hasNext()) {
+ Object row = rows.next(null);
+ Timestamp got = ((TimestampWritable) row).getTimestamp();
+ assertEquals(ts.get(idx++), got.toString());
+ }
+ rows.close();
+ }
+
+ //@Test
+ public void testReadTimestampFormat_0_11() throws Exception {
+ TimeZone.setDefault(TimeZone.getTimeZone(readerTimeZone));
+ Path oldFilePath =
+ new Path(HiveTestUtils.getFileFromClasspath("orc-file-11-format.orc"));
+ Reader reader = OrcFile.createReader(oldFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+
+ StructObjectInspector readerInspector = (StructObjectInspector) reader
+ .getObjectInspector();
+ List<? extends StructField> fields = readerInspector
+ .getAllStructFieldRefs();
+ TimestampObjectInspector tso = (TimestampObjectInspector) readerInspector
+ .getStructFieldRef("ts").getFieldObjectInspector();
+
+ RecordReader rows = reader.rows();
+ Object row = rows.next(null);
+ assertNotNull(row);
+ assertEquals(Timestamp.valueOf("2000-03-12 15:00:00"),
+ tso.getPrimitiveJavaObject(readerInspector.getStructFieldData(row,
+ fields.get(12))));
+
+ // check the contents of second row
+ assertEquals(true, rows.hasNext());
+ rows.seekToRow(7499);
+ row = rows.next(null);
+ assertEquals(Timestamp.valueOf("2000-03-12 15:00:01"),
+ tso.getPrimitiveJavaObject(readerInspector.getStructFieldData(row,
+ fields.get(12))));
+
+ // handle the close up
+ assertEquals(false, rows.hasNext());
+ rows.close();
+ }
+}
Added: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone2.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone2.java?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone2.java (added)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcTimezone2.java Sat Mar 28 00:22:15 2015
@@ -0,0 +1,142 @@
+/**
+ * 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.hadoop.hive.ql.io.orc;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.io.File;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Random;
+import java.util.TimeZone;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import com.google.common.collect.Lists;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class TestOrcTimezone2 {
+ Path workDir = new Path(System.getProperty("test.tmp.dir",
+ "target" + File.separator + "test" + File.separator + "tmp"));
+ Configuration conf;
+ FileSystem fs;
+ Path testFilePath;
+ String writerTimeZone;
+ String readerTimeZone;
+ static TimeZone defaultTimeZone = TimeZone.getDefault();
+
+ public TestOrcTimezone2(String writerTZ, String readerTZ) {
+ this.writerTimeZone = writerTZ;
+ this.readerTimeZone = readerTZ;
+ }
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> data() {
+ String[] allTimeZones = TimeZone.getAvailableIDs();
+ Random rand = new Random(123);
+ int len = allTimeZones.length;
+ int n = 500;
+ Object[][] data = new Object[n][];
+ for (int i = 0; i < n; i++) {
+ int wIdx = rand.nextInt(len);
+ int rIdx = rand.nextInt(len);
+ data[i] = new Object[2];
+ data[i][0] = allTimeZones[wIdx];
+ data[i][1] = allTimeZones[rIdx];
+ }
+ return Arrays.asList(data);
+ }
+
+ @Rule
+ public TestName testCaseName = new TestName();
+
+ @Before
+ public void openFileSystem() throws Exception {
+ conf = new Configuration();
+ fs = FileSystem.getLocal(conf);
+ testFilePath = new Path(workDir, "TestOrcFile." +
+ testCaseName.getMethodName() + ".orc");
+ fs.delete(testFilePath, false);
+ }
+
+ @After
+ public void restoreTimeZone() {
+ TimeZone.setDefault(defaultTimeZone);
+ }
+
+ @Test
+ public void testTimestampWriter() throws Exception {
+ ObjectInspector inspector;
+ synchronized (TestOrcFile.class) {
+ inspector = ObjectInspectorFactory.getReflectionObjectInspector(Timestamp.class,
+ ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
+ }
+
+ TimeZone.setDefault(TimeZone.getTimeZone(writerTimeZone));
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf).inspector(inspector).stripeSize(100000).bufferSize(10000));
+ assertEquals(writerTimeZone, TimeZone.getDefault().getID());
+ List<String> ts = Lists.newArrayList();
+ ts.add("2003-01-01 01:00:00.000000222");
+ ts.add("1999-01-01 02:00:00.999999999");
+ ts.add("1995-01-02 03:00:00.688888888");
+ ts.add("2002-01-01 04:00:00.1");
+ ts.add("2010-03-02 05:00:00.000009001");
+ ts.add("2005-01-01 06:00:00.000002229");
+ ts.add("2006-01-01 07:00:00.900203003");
+ ts.add("2003-01-01 08:00:00.800000007");
+ ts.add("1996-08-02 09:00:00.723100809");
+ ts.add("1998-11-02 10:00:00.857340643");
+ ts.add("2008-10-02 11:00:00.0");
+ ts.add("9999-01-01 00:00:00.000999");
+ for (String t : ts) {
+ writer.addRow(Timestamp.valueOf(t));
+ }
+ writer.close();
+
+ TimeZone.setDefault(TimeZone.getTimeZone(readerTimeZone));
+ Reader reader = OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+ assertEquals(readerTimeZone, TimeZone.getDefault().getID());
+ RecordReader rows = reader.rows(null);
+ int idx = 0;
+ while (rows.hasNext()) {
+ Object row = rows.next(null);
+ Timestamp got = ((TimestampWritable) row).getTimestamp();
+ assertEquals(ts.get(idx++), got.toString());
+ }
+ rows.close();
+ }
+}
Modified: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/CompactorTest.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/CompactorTest.java?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/CompactorTest.java (original)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/CompactorTest.java Sat Mar 28 00:22:15 2015
@@ -99,17 +99,22 @@ public abstract class CompactorTest {
}
protected Table newTable(String dbName, String tableName, boolean partitioned) throws TException {
- return newTable(dbName, tableName, partitioned, new HashMap<String, String>(), null);
+ return newTable(dbName, tableName, partitioned, new HashMap<String, String>(), null, false);
}
protected Table newTable(String dbName, String tableName, boolean partitioned,
Map<String, String> parameters) throws TException {
- return newTable(dbName, tableName, partitioned, parameters, null);
+ return newTable(dbName, tableName, partitioned, parameters, null, false);
}
+ protected Table newTempTable(String tableName) throws TException {
+ return newTable("default", tableName, false, null, null, true);
+ }
+
protected Table newTable(String dbName, String tableName, boolean partitioned,
- Map<String, String> parameters, List<Order> sortCols)
+ Map<String, String> parameters, List<Order> sortCols,
+ boolean isTemporary)
throws TException {
Table table = new Table();
table.setTableName(tableName);
@@ -123,6 +128,7 @@ public abstract class CompactorTest {
}
table.setParameters(parameters);
+ if (isTemporary) table.setTemporary(true);
// drop the table first, in case some previous test created it
ms.dropTable(dbName, tableName);
Modified: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestInitiator.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestInitiator.java?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestInitiator.java (original)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestInitiator.java Sat Mar 28 00:22:15 2015
@@ -625,5 +625,32 @@ public class TestInitiator extends Compa
Assert.assertEquals(CompactionType.MAJOR, compacts.get(0).getType());
}
- // TODO test compactions with legacy file types
+ @Test
+ public void noCompactTableDynamicPartitioning() throws Exception {
+ Table t = newTable("default", "nctdp", true);
+ Partition p = newPartition(t, "today");
+
+ addBaseFile(t, p, 20L, 20);
+ addDeltaFile(t, p, 21L, 22L, 2);
+ addDeltaFile(t, p, 23L, 24L, 2);
+
+ burnThroughTransactions(23);
+
+ long txnid = openTxn();
+ LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default");
+ comp.setTablename("nctdp");
+ List<LockComponent> components = new ArrayList<LockComponent>(1);
+ components.add(comp);
+ LockRequest req = new LockRequest(components, "me", "localhost");
+ req.setTxnid(txnid);
+ LockResponse res = txnHandler.lock(req);
+ txnHandler.commitTxn(new CommitTxnRequest(txnid));
+
+ startInitiator();
+
+ ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
+ List<ShowCompactResponseElement> compacts = rsp.getCompacts();
+ Assert.assertEquals(0, compacts.size());
+ }
+
}
Modified: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java (original)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestWorker.java Sat Mar 28 00:22:15 2015
@@ -204,7 +204,7 @@ public class TestWorker extends Compacto
List<Order> sortCols = new ArrayList<Order>(1);
sortCols.add(new Order("b", 1));
- Table t = newTable("default", "st", false, new HashMap<String, String>(), sortCols);
+ Table t = newTable("default", "st", false, new HashMap<String, String>(), sortCols, false);
addBaseFile(t, null, 20L, 20);
addDeltaFile(t, null, 21L, 22L, 2);
@@ -229,7 +229,7 @@ public class TestWorker extends Compacto
List<Order> sortCols = new ArrayList<Order>(1);
sortCols.add(new Order("b", 1));
- Table t = newTable("default", "sp", true, new HashMap<String, String>(), sortCols);
+ Table t = newTable("default", "sp", true, new HashMap<String, String>(), sortCols, false);
Partition p = newPartition(t, "today", sortCols);
addBaseFile(t, p, 20L, 20);
Added: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFJson.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFJson.java?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFJson.java (added)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFJson.java Sat Mar 28 00:22:15 2015
@@ -0,0 +1,104 @@
+package org.apache.hadoop.hive.ql.udf;
+
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.Text;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestUDFJson {
+
+ @Test
+ public void testJson() throws HiveException {
+
+ String book0 = "{\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\""
+ + ",\"category\":\"reference\",\"price\":8.95}";
+ String backet0 = "[1,2,{\"b\":\"y\",\"a\":\"x\"}]";
+ String backet = "[" + backet0 + ",[3,4],[5,6]]";
+ String backetFlat = backet0.substring(0, backet0.length() - 1) + ",3,4,5,6]";
+
+ String book = "[" + book0 + ",{\"author\":\"Herman Melville\",\"title\":\"Moby Dick\","
+ + "\"category\":\"fiction\",\"price\":8.99"
+ + ",\"isbn\":\"0-553-21311-3\"},{\"author\":\"J. R. R. Tolkien\""
+ + ",\"title\":\"The Lord of the Rings\",\"category\":\"fiction\""
+ + ",\"reader\":[{\"age\":25,\"name\":\"bob\"},{\"age\":26,\"name\":\"jack\"}]"
+ + ",\"price\":22.99,\"isbn\":\"0-395-19395-8\"}]";
+
+ String json = "{\"store\":{\"fruit\":[{\"weight\":8,\"type\":\"apple\"},"
+ + "{\"weight\":9,\"type\":\"pear\"}],\"basket\":" + backet + ",\"book\":" + book
+ + ",\"bicycle\":{\"price\":19.95,\"color\":\"red\"}}"
+ + ",\"email\":\"amy@only_for_json_udf_test.net\""
+ + ",\"owner\":\"amy\",\"zip code\":\"94025\",\"fb:testid\":\"1234\"}";
+
+ UDFJson udf = new UDFJson();
+
+ runTest(json, "$.owner", "amy", udf);
+ runTest(json, "$.store.bicycle", "{\"price\":19.95,\"color\":\"red\"}", udf);
+ runTest(json, "$.store.book", book, udf);
+ runTest(json, "$.store.book[0]", book0, udf);
+ runTest(json, "$.store.book[*]", book, udf);
+ runTest(json, "$.store.book[0].category", "reference", udf);
+ runTest(json, "$.store.book[*].category", "[\"reference\",\"fiction\",\"fiction\"]", udf);
+ runTest(json, "$.store.book[*].reader[0].age", "25", udf);
+ runTest(json, "$.store.book[*].reader[*].age", "[25,26]", udf);
+ runTest(json, "$.store.basket[0][1]", "2", udf);
+ runTest(json, "$.store.basket[*]", backet, udf);
+ runTest(json, "$.store.basket[*][0]", "[1,3,5]", udf);
+ runTest(json, "$.store.basket[0][*]", backet0, udf);
+ runTest(json, "$.store.basket[*][*]", backetFlat, udf);
+ runTest(json, "$.store.basket[0][2].b", "y", udf);
+ runTest(json, "$.store.basket[0][*].b", "[\"y\"]", udf);
+ runTest(json, "$.non_exist_key", null, udf);
+ runTest(json, "$.store.book[10]", null, udf);
+ runTest(json, "$.store.book[0].non_exist_key", null, udf);
+ runTest(json, "$.store.basket[*].non_exist_key", null, udf);
+ runTest(json, "$.store.basket[0][*].non_exist_key", null, udf);
+ runTest(json, "$.store.basket[*][*].non_exist_key", null, udf);
+ runTest(json, "$.zip code", "94025", udf);
+ runTest(json, "$.fb:testid", "1234", udf);
+ runTest("{\"a\":\"b\nc\"}", "$.a", "b\nc", udf);
+ }
+
+ @Test
+ public void testRootArray() throws HiveException {
+ UDFJson udf = new UDFJson();
+
+ runTest("[1,2,3]", "$[0]", "1", udf);
+ runTest("[1,2,3]", "$.[0]", "1", udf);
+ runTest("[1,2,3]", "$.[1]", "2", udf);
+ runTest("[1,2,3]", "$[1]", "2", udf);
+
+ runTest("[1,2,3]", "$[3]", null, udf);
+ runTest("[1,2,3]", "$.[*]", "[1,2,3]", udf);
+ runTest("[1,2,3]", "$[*]", "[1,2,3]", udf);
+ runTest("[1,2,3]", "$", "[1,2,3]", udf);
+ runTest("[{\"k1\":\"v1\"},{\"k2\":\"v2\"},{\"k3\":\"v3\"}]", "$[2]", "{\"k3\":\"v3\"}", udf);
+ runTest("[{\"k1\":\"v1\"},{\"k2\":\"v2\"},{\"k3\":\"v3\"}]", "$[2].k3", "v3", udf);
+ runTest("[{\"k1\":[{\"k11\":[1,2,3]}]}]", "$[0].k1[0].k11[1]", "2", udf);
+ runTest("[{\"k1\":[{\"k11\":[1,2,3]}]}]", "$[0].k1[0].k11", "[1,2,3]", udf);
+ runTest("[{\"k1\":[{\"k11\":[1,2,3]}]}]", "$[0].k1[0]", "{\"k11\":[1,2,3]}", udf);
+ runTest("[{\"k1\":[{\"k11\":[1,2,3]}]}]", "$[0].k1", "[{\"k11\":[1,2,3]}]", udf);
+ runTest("[{\"k1\":[{\"k11\":[1,2,3]}]}]", "$[0]", "{\"k1\":[{\"k11\":[1,2,3]}]}", udf);
+ runTest("[[1,2,3],[4,5,6],[7,8,9]]", "$[1]", "[4,5,6]", udf);
+ runTest("[[1,2,3],[4,5,6],[7,8,9]]", "$[1][0]", "4", udf);
+ runTest("[\"a\",\"b\"]", "$[1]", "b", udf);
+ runTest("[[\"a\",\"b\"]]", "$[0][1]", "b", udf);
+
+ runTest("[1,2,3]", "[0]", null, udf);
+ runTest("[1,2,3]", "$0", null, udf);
+ runTest("[1,2,3]", "0", null, udf);
+ runTest("[1,2,3]", "$.", null, udf);
+
+ runTest("[1,2,3]", "$", "[1,2,3]", udf);
+ runTest("{\"a\":4}", "$", "{\"a\":4}", udf);
+ }
+
+ protected void runTest(String json, String path, String exp, UDFJson udf) {
+ Text res = udf.evaluate(json, path);
+ if (exp == null) {
+ Assert.assertNull(res);
+ } else {
+ Assert.assertNotNull(res);
+ Assert.assertEquals("get_json_object test", exp, res.toString());
+ }
+ }
+}
Modified: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPMinus.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPMinus.java?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPMinus.java (original)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPMinus.java Sat Mar 28 00:22:15 2015
@@ -18,17 +18,26 @@
package org.apache.hadoop.hive.ql.udf.generic;
+import java.sql.Date;
+import java.sql.Timestamp;
+
import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
import org.apache.hadoop.hive.serde2.io.ByteWritable;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
+import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable;
+import org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable;
import org.apache.hadoop.hive.serde2.io.HiveVarcharWritable;
import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
@@ -244,4 +253,143 @@ public class TestGenericUDFOPMinus exten
verifyReturnType(new GenericUDFOPMinus(), "decimal(10,2)", "decimal(10,2)", "decimal(11,2)");
}
+
+ @Test
+ public void testIntervalYearMonthMinusIntervalYearMonth() throws Exception {
+ GenericUDFOPMinus udf = new GenericUDFOPMinus();
+
+ HiveIntervalYearMonthWritable left =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("3-1"));
+ HiveIntervalYearMonthWritable right =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("1-2"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.intervalYearMonthTypeInfo, oi.getTypeInfo());
+ HiveIntervalYearMonthWritable res = (HiveIntervalYearMonthWritable) udf.evaluate(args);
+ Assert.assertEquals(HiveIntervalYearMonth.valueOf("1-11"), res.getHiveIntervalYearMonth());
+ }
+
+
+ @Test
+ public void testDateMinusIntervalYearMonth() throws Exception {
+ GenericUDFOPMinus udf = new GenericUDFOPMinus();
+
+ DateWritable left =
+ new DateWritable(Date.valueOf("2004-02-15"));
+ HiveIntervalYearMonthWritable right =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
+ DateWritable res = (DateWritable) udf.evaluate(args);
+ Assert.assertEquals(Date.valueOf("2001-06-15"), res.get());
+ }
+
+ @Test
+ public void testTimestampMinusIntervalYearMonth() throws Exception {
+ GenericUDFOPMinus udf = new GenericUDFOPMinus();
+
+ TimestampWritable left =
+ new TimestampWritable(Timestamp.valueOf("2004-01-15 01:02:03.123456789"));
+ HiveIntervalYearMonthWritable right =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2001-11-15 01:02:03.123456789"), res.getTimestamp());
+ }
+
+ @Test
+ public void testIntervalDayTimeMinusIntervalDayTime() throws Exception {
+ GenericUDFOPMinus udf = new GenericUDFOPMinus();
+
+ HiveIntervalDayTimeWritable left =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("2 2:3:4.567"));
+ HiveIntervalDayTimeWritable right =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.intervalDayTimeTypeInfo, oi.getTypeInfo());
+ HiveIntervalDayTimeWritable res = (HiveIntervalDayTimeWritable) udf.evaluate(args);
+ Assert.assertEquals(HiveIntervalDayTime.valueOf("1 0:0:0.567"), res.getHiveIntervalDayTime());
+ }
+
+ @Test
+ public void testTimestampMinusIntervalDayTime() throws Exception {
+ GenericUDFOPMinus udf = new GenericUDFOPMinus();
+
+ TimestampWritable left =
+ new TimestampWritable(Timestamp.valueOf("2001-01-02 2:3:4.567"));
+ HiveIntervalDayTimeWritable right =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2001-01-01 00:00:00"), res.getTimestamp());
+ }
+
+ @Test
+ public void testDateMinusIntervalDayTime() throws Exception {
+ GenericUDFOPMinus udf = new GenericUDFOPMinus();
+
+ DateWritable left =
+ new DateWritable(Date.valueOf("2001-01-01"));
+ HiveIntervalDayTimeWritable right =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 0:0:0.555"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2000-12-30 23:59:59.445"), res.getTimestamp());
+ }
}
Modified: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPPlus.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPPlus.java?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPPlus.java (original)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFOPPlus.java Sat Mar 28 00:22:15 2015
@@ -18,17 +18,26 @@
package org.apache.hadoop.hive.ql.udf.generic;
+import java.sql.Date;
+import java.sql.Timestamp;
+
import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
import org.apache.hadoop.hive.serde2.io.ByteWritable;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
+import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable;
+import org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable;
import org.apache.hadoop.hive.serde2.io.HiveVarcharWritable;
import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
@@ -250,4 +259,236 @@ public class TestGenericUDFOPPlus extend
verifyReturnType(new GenericUDFOPPlus(), "decimal(10,2)", "decimal(10,2)", "decimal(11,2)");
}
+
+ @Test
+ public void testIntervalYearMonthPlusIntervalYearMonth() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ HiveIntervalYearMonthWritable left =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("1-2"));
+ HiveIntervalYearMonthWritable right =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("1-11"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.intervalYearMonthTypeInfo, oi.getTypeInfo());
+ HiveIntervalYearMonthWritable res = (HiveIntervalYearMonthWritable) udf.evaluate(args);
+ Assert.assertEquals(HiveIntervalYearMonth.valueOf("3-1"), res.getHiveIntervalYearMonth());
+ }
+
+ @Test
+ public void testIntervalYearMonthPlusDate() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ HiveIntervalYearMonthWritable left =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
+ DateWritable right =
+ new DateWritable(Date.valueOf("2001-06-15"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector,
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
+ DateWritable res = (DateWritable) udf.evaluate(args);
+ Assert.assertEquals(Date.valueOf("2004-02-15"), res.get());
+ }
+
+ @Test
+ public void testDatePlusIntervalYearMonth() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ DateWritable left =
+ new DateWritable(Date.valueOf("2001-06-15"));
+ HiveIntervalYearMonthWritable right =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
+ DateWritable res = (DateWritable) udf.evaluate(args);
+ Assert.assertEquals(Date.valueOf("2004-02-15"), res.get());
+ }
+
+ @Test
+ public void testIntervalYearMonthPlusTimestamp() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ HiveIntervalYearMonthWritable left =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
+ TimestampWritable right =
+ new TimestampWritable(Timestamp.valueOf("2001-11-15 01:02:03.123456789"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector,
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp());
+ }
+
+ @Test
+ public void testTimestampPlusIntervalYearMonth() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ TimestampWritable left =
+ new TimestampWritable(Timestamp.valueOf("2001-11-15 01:02:03.123456789"));
+ HiveIntervalYearMonthWritable right =
+ new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp());
+ }
+
+ @Test
+ public void testIntervalDayTimePlusIntervalDayTime() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ HiveIntervalDayTimeWritable left =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 0:0:0.567"));
+ HiveIntervalDayTimeWritable right =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.intervalDayTimeTypeInfo, oi.getTypeInfo());
+ HiveIntervalDayTimeWritable res = (HiveIntervalDayTimeWritable) udf.evaluate(args);
+ Assert.assertEquals(HiveIntervalDayTime.valueOf("2 2:3:4.567"), res.getHiveIntervalDayTime());
+ }
+
+ @Test
+ public void testIntervalDayTimePlusTimestamp() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ HiveIntervalDayTimeWritable left =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
+ TimestampWritable right =
+ new TimestampWritable(Timestamp.valueOf("2001-01-01 00:00:00"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector,
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
+ }
+
+ @Test
+ public void testTimestampPlusIntervalDayTime() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ TimestampWritable left =
+ new TimestampWritable(Timestamp.valueOf("2001-01-01 00:00:00"));
+ HiveIntervalDayTimeWritable right =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
+ }
+
+ @Test
+ public void testIntervalDayTimePlusDate() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ HiveIntervalDayTimeWritable left =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
+ DateWritable right =
+ new DateWritable(Date.valueOf("2001-01-01"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector,
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ // Date + day-time interval = timestamp
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
+ }
+
+ @Test
+ public void testDatePlusIntervalDayTime() throws Exception {
+ GenericUDFOPPlus udf = new GenericUDFOPPlus();
+
+ DateWritable left =
+ new DateWritable(Date.valueOf("2001-01-01"));
+ HiveIntervalDayTimeWritable right =
+ new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
+ ObjectInspector[] inputOIs = {
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector,
+ PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector
+ };
+ DeferredObject[] args = {
+ new DeferredJavaObject(left),
+ new DeferredJavaObject(right),
+ };
+
+ // Date + day-time interval = timestamp
+ PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
+ Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
+ TimestampWritable res = (TimestampWritable) udf.evaluate(args);
+ Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
+ }
}
Added: hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/util/TestDateTimeMath.java
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/util/TestDateTimeMath.java?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/util/TestDateTimeMath.java (added)
+++ hive/branches/llap/ql/src/test/org/apache/hadoop/hive/ql/util/TestDateTimeMath.java Sat Mar 28 00:22:15 2015
@@ -0,0 +1,464 @@
+/**
+ * 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.hadoop.hive.ql.util;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.util.TimeZone;
+
+import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.ql.util.DateTimeMath;
+import org.junit.*;
+
+import static org.junit.Assert.*;
+
+public class TestDateTimeMath {
+
+ @Test
+ public void testTimestampIntervalYearMonthArithmetic() throws Exception {
+ char plus = '+';
+ char minus = '-';
+
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", plus, "0-0",
+ "2001-01-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.456", plus, "1-1",
+ "2002-02-01 01:02:03.456");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.456", plus, "10-0",
+ "2011-01-01 01:02:03.456");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.456", plus, "0-11",
+ "2001-12-01 01:02:03.456");
+ checkTimestampIntervalYearMonthArithmetic("2001-03-01 01:02:03.500", plus, "1-11",
+ "2003-02-01 01:02:03.500");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.500", plus, "-1-1",
+ "1999-12-01 01:02:03.500");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.500", plus, "-0-0",
+ "2001-01-01 01:02:03.500");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.123456789", plus, "-0-0",
+ "2001-01-01 01:02:03.123456789");
+
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", minus, "0-0",
+ "2001-01-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", minus, "10-0",
+ "1991-01-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", minus, "-10-0",
+ "2011-01-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", minus, "8-2",
+ "1992-11-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", minus, "-8-2",
+ "2009-03-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03.123456789", minus, "8-2",
+ "1992-11-01 01:02:03.123456789");
+
+ checkTimestampIntervalYearMonthArithmetic(null, plus, "1-1",
+ null);
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", plus, null,
+ null);
+ checkTimestampIntervalYearMonthArithmetic(null, minus, "1-1",
+ null);
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", minus, null,
+ null);
+
+ // End of the month behavior
+ checkTimestampIntervalYearMonthArithmetic("2001-01-28 01:02:03", plus, "0-1",
+ "2001-02-28 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-29 01:02:03", plus, "0-1",
+ "2001-02-28 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-30 01:02:03", plus, "0-1",
+ "2001-02-28 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-01-31 01:02:03", plus, "0-1",
+ "2001-02-28 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-02-28 01:02:03", plus, "0-1",
+ "2001-03-28 01:02:03");
+
+ // Test that timestamp arithmetic is done in UTC and then converted back to local timezone,
+ // matching Oracle behavior.
+ TimeZone originalTz = TimeZone.getDefault();
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", plus, "0-6",
+ "2001-07-01 02:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-07-01 01:02:03", plus, "0-6",
+ "2002-01-01 00:02:03");
+
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ checkTimestampIntervalYearMonthArithmetic("2001-01-01 01:02:03", plus, "0-6",
+ "2001-07-01 01:02:03");
+ checkTimestampIntervalYearMonthArithmetic("2001-07-01 01:02:03", plus, "0-6",
+ "2002-01-01 01:02:03");
+ } finally {
+ TimeZone.setDefault(originalTz);
+ }
+ }
+
+ @Test
+ public void testDateIntervalYearMonthArithmetic() throws Exception {
+ char plus = '+';
+ char minus = '-';
+
+ checkDateIntervalDayTimeArithmetic("2001-01-01", plus, "0-0", "2001-01-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", plus, "0-1", "2001-02-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", plus, "0-6", "2001-07-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", plus, "1-0", "2002-01-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", plus, "1-1", "2002-02-01");
+ checkDateIntervalDayTimeArithmetic("2001-10-10", plus, "1-6", "2003-04-10");
+ checkDateIntervalDayTimeArithmetic("2003-04-10", plus, "-1-6", "2001-10-10");
+
+ checkDateIntervalDayTimeArithmetic("2001-01-01", minus, "0-0", "2001-01-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", minus, "0-1", "2000-12-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", minus, "1-0", "2000-01-01");
+ checkDateIntervalDayTimeArithmetic("2001-01-01", minus, "1-1", "1999-12-01");
+ checkDateIntervalDayTimeArithmetic("2001-10-10", minus, "1-6", "2000-04-10");
+ checkDateIntervalDayTimeArithmetic("2003-04-10", minus, "-1-6", "2004-10-10");
+
+ // end of month behavior
+ checkDateIntervalDayTimeArithmetic("2001-01-28", plus, "0-1", "2001-02-28");
+ checkDateIntervalDayTimeArithmetic("2001-01-29", plus, "0-1", "2001-02-28");
+ checkDateIntervalDayTimeArithmetic("2001-01-30", plus, "0-1", "2001-02-28");
+ checkDateIntervalDayTimeArithmetic("2001-01-31", plus, "0-1", "2001-02-28");
+ checkDateIntervalDayTimeArithmetic("2001-01-31", plus, "0-2", "2001-03-31");
+ checkDateIntervalDayTimeArithmetic("2001-02-28", plus, "0-1", "2001-03-28");
+ // leap year
+ checkDateIntervalDayTimeArithmetic("2004-01-28", plus, "0-1", "2004-02-28");
+ checkDateIntervalDayTimeArithmetic("2004-01-29", plus, "0-1", "2004-02-29");
+ checkDateIntervalDayTimeArithmetic("2004-01-30", plus, "0-1", "2004-02-29");
+ checkDateIntervalDayTimeArithmetic("2004-01-31", plus, "0-1", "2004-02-29");
+ }
+
+ @Test
+ public void testIntervalYearMonthArithmetic() throws Exception {
+ char plus = '+';
+ char minus = '-';
+
+ checkIntervalYearMonthArithmetic("0-0", plus, "0-0", "0-0");
+ checkIntervalYearMonthArithmetic("0-0", plus, "4-5", "4-5");
+ checkIntervalYearMonthArithmetic("4-5", plus, "0-0", "4-5");
+ checkIntervalYearMonthArithmetic("0-0", plus, "1-1", "1-1");
+ checkIntervalYearMonthArithmetic("1-1", plus, "0-0", "1-1");
+
+ checkIntervalYearMonthArithmetic("0-0", minus, "0-0", "0-0");
+ checkIntervalYearMonthArithmetic("0-0", minus, "1-0", "-1-0");
+ checkIntervalYearMonthArithmetic("1-2", minus, "1-1", "0-1");
+ checkIntervalYearMonthArithmetic("0-0", minus, "1-1", "-1-1");
+ checkIntervalYearMonthArithmetic("-1-1", minus, "1-1", "-2-2");
+ checkIntervalYearMonthArithmetic("-1-1", minus, "-1-1", "0-0");
+
+ checkIntervalYearMonthArithmetic(null, plus, "1-1", null);
+ checkIntervalYearMonthArithmetic("1-1", plus, null, null);
+ checkIntervalYearMonthArithmetic(null, minus, "1-1", null);
+ checkIntervalYearMonthArithmetic("1-1", minus, null, null);
+ }
+
+ @Test
+ public void testTimestampIntervalDayTimeArithmetic() throws Exception {
+ char plus = '+';
+ char minus = '-';
+
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03", plus, "1 1:1:1",
+ "2001-01-02 02:03:04");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.456", plus, "1 1:1:1",
+ "2001-01-02 02:03:04.456");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.456", plus, "1 1:1:1.555",
+ "2001-01-02 02:03:05.011");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03", plus, "1 1:1:1.555555555",
+ "2001-01-02 02:03:04.555555555");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.456", plus, "1 1:1:1.555555555",
+ "2001-01-02 02:03:05.011555555");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.500", plus, "1 1:1:1.499",
+ "2001-01-02 02:03:04.999");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.500", plus, "1 1:1:1.500",
+ "2001-01-02 02:03:05.0");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.500", plus, "1 1:1:1.501",
+ "2001-01-02 02:03:05.001");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.500000000", plus, "1 1:1:1.4999999999",
+ "2001-01-02 02:03:04.999999999");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.500000000", plus, "1 1:1:1.500",
+ "2001-01-02 02:03:05.0");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03.500000000", plus, "1 1:1:1.500000001",
+ "2001-01-02 02:03:05.000000001");
+
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03", minus, "0 01:02:03",
+ "2001-01-01 00:00:00");
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03", minus, "0 0:0:0",
+ "2001-01-01 01:02:03");
+
+ checkTsIntervalDayTimeArithmetic(null, plus, "1 1:1:1.555555555",
+ null);
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03", plus, null,
+ null);
+ checkTsIntervalDayTimeArithmetic(null, minus, "1 1:1:1.555555555",
+ null);
+ checkTsIntervalDayTimeArithmetic("2001-01-01 01:02:03", minus, null,
+ null);
+
+ // Try some time zone boundaries
+ TimeZone originalTz = TimeZone.getDefault();
+ try {
+ // America/Los_Angeles DST dates - 2015-03-08 02:00:00/2015-11-01 02:00:00
+ TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
+
+ checkTsIntervalDayTimeArithmetic("2015-03-08 01:59:58", plus, "0 0:0:01",
+ "2015-03-08 01:59:59");
+ checkTsIntervalDayTimeArithmetic("2015-03-08 01:59:59", plus, "0 0:0:01",
+ "2015-03-08 03:00:00");
+ checkTsIntervalDayTimeArithmetic("2015-03-08 03:00:00", minus, "0 0:0:01",
+ "2015-03-08 01:59:59");
+ checkTsIntervalDayTimeArithmetic("2015-03-08 01:59:59.995", plus, "0 0:0:0.005",
+ "2015-03-08 03:00:00");
+ checkTsIntervalDayTimeArithmetic("2015-03-08 01:59:59.995", plus, "0 0:0:0.0051",
+ "2015-03-08 03:00:00.0001");
+ checkTsIntervalDayTimeArithmetic("2015-03-08 03:00:00", minus, "0 0:0:0.005",
+ "2015-03-08 01:59:59.995");
+ checkTsIntervalDayTimeArithmetic("2015-11-01 01:59:58", plus, "0 0:0:01",
+ "2015-11-01 01:59:59");
+ checkTsIntervalDayTimeArithmetic("2015-11-01 01:59:59", plus, "0 0:0:01",
+ "2015-11-01 02:00:00");
+
+ // UTC has no such adjustment
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ checkTsIntervalDayTimeArithmetic("2015-03-08 01:59:58", plus, "0 0:0:01",
+ "2015-03-08 01:59:59");
+ checkTsIntervalDayTimeArithmetic("2015-03-08 01:59:59", plus, "0 0:0:01",
+ "2015-03-08 02:00:00");
+ } finally {
+ TimeZone.setDefault(originalTz);
+ }
+ }
+
+ @Test
+ public void testIntervalDayTimeArithmetic() throws Exception {
+ char plus = '+';
+ char minus = '-';
+
+ checkIntervalDayTimeArithmetic("0 0:0:0", plus, "0 0:0:0", "0 0:0:0");
+ checkIntervalDayTimeArithmetic("0 01:02:03", plus, "6 0:0:0.0001", "6 01:02:03.0001");
+ checkIntervalDayTimeArithmetic("6 0:0:0.0001", plus, "0 01:02:03", "6 01:02:03.0001");
+ checkIntervalDayTimeArithmetic("0 01:02:03", plus, "1 10:10:10.0001", "1 11:12:13.0001");
+ checkIntervalDayTimeArithmetic("1 10:10:10.0001", plus, "0 01:02:03", "1 11:12:13.0001");
+ checkIntervalDayTimeArithmetic("0 0:0:0.900000000", plus, "0 0:0:0.099999999", "0 0:0:0.999999999");
+ checkIntervalDayTimeArithmetic("0 0:0:0.900000001", plus, "0 0:0:0.099999999", "0 0:0:1");
+ checkIntervalDayTimeArithmetic("0 0:0:0.900000002", plus, "0 0:0:0.099999999", "0 0:0:1.000000001");
+
+ checkIntervalDayTimeArithmetic("0 0:0:0", minus, "0 0:0:0", "0 0:0:0");
+ checkIntervalDayTimeArithmetic("0 0:0:0", minus, "0 0:0:0.123", "-0 0:0:0.123");
+ checkIntervalDayTimeArithmetic("3 4:5:6.789", minus, "1 1:1:1.111", "2 3:4:5.678");
+ checkIntervalDayTimeArithmetic("0 0:0:0.0", minus, "1 1:1:1.111", "-1 1:1:1.111");
+ checkIntervalDayTimeArithmetic("-1 1:1:1.222", minus, "1 1:1:1.111", "-2 2:2:2.333");
+ checkIntervalDayTimeArithmetic("-1 1:1:1.111", minus, "-1 1:1:1.111", "0 0:0:0");
+
+ checkIntervalDayTimeArithmetic(null, plus, "1 1:1:1.111", null);
+ checkIntervalDayTimeArithmetic("1 1:1:1.111", plus, null, null);
+ checkIntervalDayTimeArithmetic(null, minus, "1 1:1:1.111", null);
+ checkIntervalDayTimeArithmetic("1 1:1:1.111", minus, null, null);
+ }
+
+ @Test
+ public void testTimestampSubtraction() throws Exception {
+ checkTsArithmetic("2001-01-01 00:00:00", "2001-01-01 00:00:00", "0 0:0:0");
+ checkTsArithmetic("2002-02-02 01:01:01", "2001-01-01 00:00:00", "397 1:1:1");
+ checkTsArithmetic("2001-01-01 00:00:00", "2002-02-02 01:01:01", "-397 1:1:1");
+ checkTsArithmetic("2015-01-01 00:00:00", "2014-12-31 00:00:00", "1 0:0:0");
+ checkTsArithmetic("2014-12-31 00:00:00", "2015-01-01 00:00:00", "-1 0:0:0");
+ checkTsArithmetic("2015-01-01 00:00:00", "2014-12-31 23:59:59", "0 0:0:01");
+ checkTsArithmetic("2014-12-31 23:59:59", "2015-01-01 00:00:00", "-0 0:0:01");
+ checkTsArithmetic("2015-01-01 00:00:00", "2014-12-31 23:59:59.9999", "0 0:0:00.0001");
+ checkTsArithmetic("2014-12-31 23:59:59.9999", "2015-01-01 00:00:00", "-0 0:0:00.0001");
+ checkTsArithmetic("2015-01-01 00:00:00", "2014-12-31 11:12:13.000000001", "0 12:47:46.999999999");
+ checkTsArithmetic("2014-12-31 11:12:13.000000001", "2015-01-01 00:00:00", "-0 12:47:46.999999999");
+
+ // Test that timestamp arithmetic is done in UTC and then converted back to local timezone,
+ // matching Oracle behavior.
+ TimeZone originalTz = TimeZone.getDefault();
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
+ checkTsArithmetic("1999-12-15 00:00:00", "1999-09-15 00:00:00", "91 1:0:0");
+ checkTsArithmetic("1999-09-15 00:00:00", "1999-12-15 00:00:00", "-91 1:0:0");
+ checkTsArithmetic("1999-12-15 00:00:00", "1995-09-15 00:00:00", "1552 1:0:0");
+ checkTsArithmetic("1995-09-15 00:00:00", "1999-12-15 00:00:00", "-1552 1:0:0");
+
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ checkTsArithmetic("1999-12-15 00:00:00", "1999-09-15 00:00:00", "91 0:0:0");
+ checkTsArithmetic("1999-09-15 00:00:00", "1999-12-15 00:00:00", "-91 0:0:0");
+ checkTsArithmetic("1999-12-15 00:00:00", "1995-09-15 00:00:00", "1552 0:0:0");
+ checkTsArithmetic("1995-09-15 00:00:00", "1999-12-15 00:00:00", "-1552 0:0:0");
+ } finally {
+ TimeZone.setDefault(originalTz);
+ }
+ }
+
+ private static void checkTimestampIntervalYearMonthArithmetic(
+ String left, char operationType, String right, String expected) throws Exception {
+ Timestamp leftTs = null;
+ if (left != null) {
+ leftTs = Timestamp.valueOf(left);
+ }
+ HiveIntervalYearMonth rightInterval = null;
+ if (right != null) {
+ rightInterval = HiveIntervalYearMonth.valueOf(right);
+ }
+ Timestamp expectedResult = null;
+ if (expected != null) {
+ expectedResult = Timestamp.valueOf(expected);
+ }
+ Timestamp testResult = null;
+
+ DateTimeMath dtm = new DateTimeMath();
+ switch (operationType) {
+ case '-':
+ testResult = dtm.subtract(leftTs, rightInterval);
+ break;
+ case '+':
+ testResult = dtm.add(leftTs, rightInterval);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid operation " + operationType);
+ }
+
+ assertEquals(String.format("%s %s %s", leftTs, operationType, rightInterval),
+ expectedResult, testResult);
+ }
+
+ private static void checkDateIntervalDayTimeArithmetic(
+ String left, char operationType, String right, String expected) throws Exception {
+ Date leftDt = null;
+ if (left != null) {
+ leftDt = Date.valueOf(left);
+ }
+ HiveIntervalYearMonth rightInterval = null;
+ if (right != null) {
+ rightInterval = HiveIntervalYearMonth.valueOf(right);
+ }
+ Date expectedResult = null;
+ if (expected != null) {
+ expectedResult = Date.valueOf(expected);
+ }
+ Date testResult = null;
+
+ DateTimeMath dtm = new DateTimeMath();
+ switch (operationType) {
+ case '-':
+ testResult = dtm.subtract(leftDt, rightInterval);
+ break;
+ case '+':
+ testResult = dtm.add(leftDt, rightInterval);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid operation " + operationType);
+ }
+
+ assertEquals(String.format("%s %s %s", leftDt, operationType, rightInterval),
+ expectedResult, testResult);
+ }
+
+ private static void checkIntervalYearMonthArithmetic(
+ String left, char operationType, String right, String expected) throws Exception {
+ HiveIntervalYearMonth leftInterval = left == null ? null: HiveIntervalYearMonth.valueOf(left);
+ HiveIntervalYearMonth rightInterval = right == null ? null : HiveIntervalYearMonth.valueOf(right);
+ HiveIntervalYearMonth expectedResult = expected == null ? null : HiveIntervalYearMonth.valueOf(expected);
+ HiveIntervalYearMonth testResult = null;
+
+ DateTimeMath dtm = new DateTimeMath();
+ switch (operationType) {
+ case '-':
+ testResult = dtm.subtract(leftInterval, rightInterval);
+ break;
+ case '+':
+ testResult = dtm.add(leftInterval, rightInterval);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid operation " + operationType);
+ }
+
+ assertEquals(String.format("%s %s %s", leftInterval, operationType, rightInterval),
+ expectedResult, testResult);
+ }
+
+ private static void checkTsIntervalDayTimeArithmetic(
+ String left, char operationType, String right, String expected) throws Exception {
+ Timestamp leftTs = null;
+ if (left != null) {
+ leftTs = Timestamp.valueOf(left);
+ }
+ HiveIntervalDayTime rightInterval = right == null ? null : HiveIntervalDayTime.valueOf(right);
+ Timestamp expectedResult = null;
+ if (expected != null) {
+ expectedResult = Timestamp.valueOf(expected);
+ }
+ Timestamp testResult = null;
+
+ DateTimeMath dtm = new DateTimeMath();
+ switch (operationType) {
+ case '-':
+ testResult = dtm.subtract(leftTs, rightInterval);
+ break;
+ case '+':
+ testResult = dtm.add(leftTs, rightInterval);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid operation " + operationType);
+ }
+
+ assertEquals(String.format("%s %s %s", leftTs, operationType, rightInterval),
+ expectedResult, testResult);
+ }
+
+ private static void checkIntervalDayTimeArithmetic(
+ String left, char operationType, String right, String expected) throws Exception {
+ HiveIntervalDayTime leftInterval = left == null ? null : HiveIntervalDayTime.valueOf(left);
+ HiveIntervalDayTime rightInterval = right == null ? null : HiveIntervalDayTime.valueOf(right);
+ HiveIntervalDayTime expectedResult = expected == null ? null : HiveIntervalDayTime.valueOf(expected);
+ HiveIntervalDayTime testResult = null;
+
+ DateTimeMath dtm = new DateTimeMath();
+ switch (operationType) {
+ case '-':
+ testResult = dtm.subtract(leftInterval, rightInterval);
+ break;
+ case '+':
+ testResult = dtm.add(leftInterval, rightInterval);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid operation " + operationType);
+ }
+
+ assertEquals(String.format("%s %s %s", leftInterval, operationType, rightInterval),
+ expectedResult, testResult);
+ }
+
+ private static void checkTsArithmetic(
+ String left, String right, String expected) throws Exception {
+ Timestamp leftTs = null;
+ if (left != null) {
+ leftTs = Timestamp.valueOf(left);
+ }
+ Timestamp rightTs = null;
+ if (left != null) {
+ rightTs = Timestamp.valueOf(right);
+ }
+ HiveIntervalDayTime expectedResult = null;
+ if (expected != null) {
+ expectedResult = HiveIntervalDayTime.valueOf(expected);
+ }
+ DateTimeMath dtm = new DateTimeMath();
+ HiveIntervalDayTime testResult =
+ dtm.subtract(leftTs, rightTs);
+
+ assertEquals(String.format("%s - %s", leftTs, rightTs),
+ expectedResult, testResult);
+ }
+}
Modified: hive/branches/llap/ql/src/test/queries/clientnegative/alter_rename_partition_failure.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientnegative/alter_rename_partition_failure.q?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientnegative/alter_rename_partition_failure.q (original)
+++ hive/branches/llap/ql/src/test/queries/clientnegative/alter_rename_partition_failure.q Sat Mar 28 00:22:15 2015
@@ -1,6 +1,6 @@
create table alter_rename_partition_src ( col1 string ) stored as textfile ;
load data local inpath '../../data/files/test.dat' overwrite into table alter_rename_partition_src ;
create table alter_rename_partition ( col1 string ) partitioned by (pcol1 string , pcol2 string) stored as sequencefile;
-insert overwrite table alter_rename_partition partition (pCol1='old_part1:', pcol2='old_part2:') select col1 from alter_rename_partition_src ;
+insert overwrite table alter_rename_partition partition (pCol1='old_part1', pcol2='old_part2') select col1 from alter_rename_partition_src ;
-alter table alter_rename_partition partition (pCol1='nonexist_part1:', pcol2='nonexist_part2:') rename to partition (pCol1='new_part1:', pcol2='new_part2:');
+alter table alter_rename_partition partition (pCol1='nonexist_part1', pcol2='nonexist_part2') rename to partition (pCol1='new_part1', pcol2='new_part2');
Added: hive/branches/llap/ql/src/test/queries/clientnegative/interval_1.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientnegative/interval_1.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientnegative/interval_1.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientnegative/interval_1.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,2 @@
+-- year-month/day-time intervals not compatible
+select interval_day_time(interval '1' year) from src limit 1;
Added: hive/branches/llap/ql/src/test/queries/clientnegative/interval_2.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientnegative/interval_2.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientnegative/interval_2.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientnegative/interval_2.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,3 @@
+-- year-month/day-time intervals not compatible
+select interval '1' year - interval '365' day from src limit 1;
+
Added: hive/branches/llap/ql/src/test/queries/clientnegative/interval_3.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientnegative/interval_3.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientnegative/interval_3.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientnegative/interval_3.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,3 @@
+-- year-month/day-time intervals not compatible
+select interval '1' year + interval '365' day from src limit 1;
+
Modified: hive/branches/llap/ql/src/test/queries/clientpositive/alter_partition_update_status.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/alter_partition_update_status.q?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/alter_partition_update_status.q (original)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/alter_partition_update_status.q Sat Mar 28 00:22:15 2015
@@ -22,4 +22,16 @@ describe formatted src_stat_part_two.key
ALTER TABLE src_stat_part_two PARTITION(px=1, py='a') UPDATE STATISTICS for column key SET ('numDVs'='30','maxColLen'='40');
-describe formatted src_stat_part_two.key PARTITION(px=1, py='a');
\ No newline at end of file
+describe formatted src_stat_part_two.key PARTITION(px=1, py='a');
+
+create database if not exists dummydb;
+
+use dummydb;
+
+ALTER TABLE default.src_stat_part_two PARTITION(px=1, py='a') UPDATE STATISTICS for column key SET ('numDVs'='40','maxColLen'='50');
+
+describe formatted default.src_stat_part_two key PARTITION(px=1, py='a');
+
+use default;
+
+drop database dummydb;
\ No newline at end of file
Modified: hive/branches/llap/ql/src/test/queries/clientpositive/alter_table_update_status.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/alter_table_update_status.q?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/alter_table_update_status.q (original)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/alter_table_update_status.q Sat Mar 28 00:22:15 2015
@@ -27,4 +27,22 @@ describe formatted src_stat_int.key;
ALTER TABLE src_stat_int UPDATE STATISTICS for column key SET ('numDVs'='2222','lowValue'='333.22','highValue'='22.22');
-describe formatted src_stat_int.key;
\ No newline at end of file
+describe formatted src_stat_int.key;
+
+
+
+create database if not exists dummydb;
+
+use dummydb;
+
+ALTER TABLE default.src_stat UPDATE STATISTICS for column key SET ('numDVs'='3333','avgColLen'='2.222');
+
+describe formatted default.src_stat key;
+
+ALTER TABLE default.src_stat UPDATE STATISTICS for column value SET ('numDVs'='232','numNulls'='233','avgColLen'='2.34','maxColLen'='235');
+
+describe formatted default.src_stat value;
+
+use default;
+
+drop database dummydb;
\ No newline at end of file
Modified: hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_partlvl.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_partlvl.q?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_partlvl.q (original)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_partlvl.q Sat Mar 28 00:22:15 2015
@@ -39,3 +39,20 @@ analyze table Employee_Part compute sta
analyze table Employee_Part compute statistics for columns;
describe formatted Employee_Part.employeeID;
+
+set hive.analyze.stmt.collect.partlevel.stats=true;
+
+create database if not exists dummydb;
+
+use dummydb;
+
+analyze table default.Employee_Part partition (employeeSalary=2000.0) compute statistics for columns;
+
+describe formatted default.Employee_Part employeeID partition (employeeSalary=2000.0);
+
+analyze table default.Employee_Part compute statistics for columns;
+
+use default;
+
+drop database dummydb;
+
Modified: hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_tbllvl.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_tbllvl.q?rev=1669718&r1=1669717&r2=1669718&view=diff
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_tbllvl.q (original)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/columnstats_tbllvl.q Sat Mar 28 00:22:15 2015
@@ -24,9 +24,9 @@ analyze table UserVisits_web_text_none c
analyze table UserVisits_web_text_none compute statistics for columns sourceIP, avgTimeOnSite, adRevenue;
explain
-analyze table UserVisits_web_text_none compute statistics for columns;
+analyze table default.UserVisits_web_text_none compute statistics for columns;
-analyze table UserVisits_web_text_none compute statistics for columns;
+analyze table default.UserVisits_web_text_none compute statistics for columns;
describe formatted UserVisits_web_text_none destURL;
describe formatted UserVisits_web_text_none adRevenue;
@@ -45,3 +45,52 @@ analyze table empty_tab compute statisti
analyze table empty_tab compute statistics for columns a,b,c,d,e;
+create database if not exists dummydb;
+
+use dummydb;
+
+analyze table default.UserVisits_web_text_none compute statistics for columns destURL;
+
+describe formatted default.UserVisits_web_text_none destURL;
+
+CREATE TABLE UserVisits_in_dummy_db (
+ sourceIP string,
+ destURL string,
+ visitDate string,
+ adRevenue float,
+ userAgent string,
+ cCode string,
+ lCode string,
+ sKeyword string,
+ avgTimeOnSite int)
+row format delimited fields terminated by '|' stored as textfile;
+
+LOAD DATA LOCAL INPATH "../../data/files/UserVisits.dat" INTO TABLE UserVisits_in_dummy_db;
+
+use default;
+
+explain
+analyze table dummydb.UserVisits_in_dummy_db compute statistics for columns sourceIP, avgTimeOnSite, adRevenue;
+
+explain extended
+analyze table dummydb.UserVisits_in_dummy_db compute statistics for columns sourceIP, avgTimeOnSite, adRevenue;
+
+analyze table dummydb.UserVisits_in_dummy_db compute statistics for columns sourceIP, avgTimeOnSite, adRevenue;
+
+explain
+analyze table dummydb.UserVisits_in_dummy_db compute statistics for columns;
+
+analyze table dummydb.UserVisits_in_dummy_db compute statistics for columns;
+
+describe formatted dummydb.UserVisits_in_dummy_db destURL;
+describe formatted dummydb.UserVisits_in_dummy_db adRevenue;
+describe formatted dummydb.UserVisits_in_dummy_db avgTimeOnSite;
+
+drop table dummydb.UserVisits_in_dummy_db;
+
+drop database dummydb;
+
+
+
+
+
Added: hive/branches/llap/ql/src/test/queries/clientpositive/encryption_unencrypted_nonhdfs_external_tables.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/encryption_unencrypted_nonhdfs_external_tables.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/encryption_unencrypted_nonhdfs_external_tables.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/encryption_unencrypted_nonhdfs_external_tables.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,13 @@
+-- This test does not test encrypted data, but it makes sure that external tables out of HDFS can
+-- be queried due to internal encryption functions;
+
+DROP TABLE mydata;
+
+CREATE EXTERNAL TABLE mydata (key STRING, value STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '
+LOCATION 'pfile://${system:test.tmp.dir}/external_mydata';
+
+LOAD DATA LOCAL INPATH '../../data/files/kv1.txt' OVERWRITE INTO TABLE mydata;
+
+SELECT * from mydata;
+
+DROP TABLE mydata;
\ No newline at end of file
Added: hive/branches/llap/ql/src/test/queries/clientpositive/hybridhashjoin.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/hybridhashjoin.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/hybridhashjoin.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/hybridhashjoin.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,250 @@
+set hive.auto.convert.join=true;
+set hive.auto.convert.join.noconditionaltask.size=1300000;
+set hive.mapjoin.optimized.hashtable.wbsize=880000;
+set hive.mapjoin.hybridgrace.memcheckfrequency=1024;
+
+set hive.mapjoin.hybridgrace.hashtable=false;
+
+-- Base result for inner join
+explain
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint
+ where c.cint < 2000000000) t1
+;
+
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint
+ where c.cint < 2000000000) t1
+;
+
+set hive.mapjoin.hybridgrace.hashtable=true;
+
+-- Two partitions are created. One in memory, one on disk on creation.
+-- The one in memory will eventually exceed memory limit, but won't spill.
+explain
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint
+ where c.cint < 2000000000) t1
+;
+
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint
+ where c.cint < 2000000000) t1
+;
+
+set hive.auto.convert.join.noconditionaltask.size=3000000;
+set hive.mapjoin.optimized.hashtable.wbsize=100000;
+
+set hive.mapjoin.hybridgrace.hashtable=false;
+
+-- Base result for inner join
+explain
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+set hive.mapjoin.hybridgrace.hashtable=true;
+
+-- 16 partitions are created: 3 in memory, 13 on disk on creation.
+-- 1 partition is spilled during first round processing, which ends up having 2 in memory, 14 on disk
+explain
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ inner join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+
+
+set hive.mapjoin.hybridgrace.hashtable=false;
+
+-- Base result for outer join
+explain
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ left outer join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ left outer join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+set hive.mapjoin.hybridgrace.hashtable=true;
+
+-- 32 partitions are created. 3 in memory, 29 on disk on creation.
+explain
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ left outer join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+select count(*) from
+(select c.ctinyint
+ from alltypesorc c
+ left outer join alltypesorc cd
+ on cd.cint = c.cint) t1
+;
+
+
+-- Partitioned table
+create table parttbl (key string, value char(20)) partitioned by (dt char(10));
+insert overwrite table parttbl partition(dt='2000-01-01')
+ select * from src;
+insert overwrite table parttbl partition(dt='2000-01-02')
+ select * from src1;
+
+set hive.auto.convert.join.noconditionaltask.size=30000000;
+set hive.mapjoin.optimized.hashtable.wbsize=10000000;
+
+set hive.mapjoin.hybridgrace.hashtable=false;
+
+-- No spill, base result
+explain
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+set hive.mapjoin.hybridgrace.hashtable=true;
+
+-- No spill, 2 partitions created in memory
+explain
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+
+set hive.auto.convert.join.noconditionaltask.size=20000;
+set hive.mapjoin.optimized.hashtable.wbsize=10000;
+
+set hive.mapjoin.hybridgrace.hashtable=false;
+
+-- Spill case base result
+explain
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+set hive.mapjoin.hybridgrace.hashtable=true;
+
+-- Spill case, one partition in memory, one spilled on creation
+explain
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+select count(*) from
+(select p1.value
+ from parttbl p1
+ inner join parttbl p2
+ on p1.key = p2.key) t1
+;
+
+drop table parttbl;
+
+
+-- Test vectorization
+-- Test case borrowed from vector_decimal_mapjoin.q
+CREATE TABLE decimal_mapjoin STORED AS ORC AS
+ SELECT cdouble, CAST (((cdouble*22.1)/37) AS DECIMAL(20,10)) AS cdecimal1,
+ CAST (((cdouble*9.3)/13) AS DECIMAL(23,14)) AS cdecimal2,
+ cint
+ FROM alltypesorc;
+
+SET hive.auto.convert.join=true;
+SET hive.auto.convert.join.noconditionaltask=true;
+SET hive.auto.convert.join.noconditionaltask.size=50000000;
+set hive.mapjoin.optimized.hashtable.wbsize=10000;
+SET hive.vectorized.execution.enabled=true;
+set hive.mapjoin.hybridgrace.hashtable=false;
+
+EXPLAIN SELECT l.cint, r.cint, l.cdecimal1, r.cdecimal2
+ FROM decimal_mapjoin l
+ JOIN decimal_mapjoin r ON l.cint = r.cint
+ WHERE l.cint = 6981;
+SELECT l.cint, r.cint, l.cdecimal1, r.cdecimal2
+ FROM decimal_mapjoin l
+ JOIN decimal_mapjoin r ON l.cint = r.cint
+ WHERE l.cint = 6981;
+
+set hive.mapjoin.hybridgrace.hashtable=true;
+
+EXPLAIN SELECT l.cint, r.cint, l.cdecimal1, r.cdecimal2
+ FROM decimal_mapjoin l
+ JOIN decimal_mapjoin r ON l.cint = r.cint
+ WHERE l.cint = 6981;
+SELECT l.cint, r.cint, l.cdecimal1, r.cdecimal2
+ FROM decimal_mapjoin l
+ JOIN decimal_mapjoin r ON l.cint = r.cint
+ WHERE l.cint = 6981;
+
+DROP TABLE decimal_mapjoin;
Added: hive/branches/llap/ql/src/test/queries/clientpositive/interval_1.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/interval_1.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/interval_1.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/interval_1.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,42 @@
+select
+ interval '10-11' year to month,
+ interval '10' year,
+ interval '11' month
+from src limit 1;
+
+select
+ interval_year_month('10-11'),
+ interval_year_month(cast('10-11' as string)),
+ interval_year_month(cast('10-11' as varchar(10))),
+ interval_year_month(cast('10-11' as char(10))),
+ interval_year_month('10-11') = interval '10-11' year to month
+from src limit 1;
+
+-- Test normalization of interval values
+select
+ interval '49' month
+from src limit 1;
+
+select
+ interval '10 9:8:7.987654321' day to second,
+ interval '10' day,
+ interval '11' hour,
+ interval '12' minute,
+ interval '13' second,
+ interval '13.123456789' second
+from src limit 1;
+
+select
+ interval_day_time('2 1:2:3'),
+ interval_day_time(cast('2 1:2:3' as string)),
+ interval_day_time(cast('2 1:2:3' as varchar(10))),
+ interval_day_time(cast('2 1:2:3' as char(10))),
+ interval_day_time('2 1:2:3') = interval '2 1:2:3' day to second
+from src limit 1;
+
+-- Test normalization of interval values
+select
+ interval '49' hour,
+ interval '1470' minute,
+ interval '90061.111111111' second
+from src limit 1;
Added: hive/branches/llap/ql/src/test/queries/clientpositive/interval_2.q
URL: http://svn.apache.org/viewvc/hive/branches/llap/ql/src/test/queries/clientpositive/interval_2.q?rev=1669718&view=auto
==============================================================================
--- hive/branches/llap/ql/src/test/queries/clientpositive/interval_2.q (added)
+++ hive/branches/llap/ql/src/test/queries/clientpositive/interval_2.q Sat Mar 28 00:22:15 2015
@@ -0,0 +1,87 @@
+-- group-by/order-by/aggregation functions
+
+select
+ iym, count(*), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1
+group by iym
+order by iym asc
+limit 5;
+
+select
+ iym, count(*), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1
+group by iym
+order by iym desc
+limit 5;
+
+-- same query as previous, with having clause
+select
+ iym, count(*), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1
+group by iym
+having max(idt) > interval '496 0:0:0' day to second
+order by iym desc
+limit 5;
+
+select
+ idt, count(*), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1
+group by idt
+order by idt asc
+limit 5;
+
+select
+ idt, count(*), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1
+group by idt
+order by idt desc
+limit 5;
+
+-- same query as previous, with having clause
+select
+ idt, count(*), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1
+group by idt
+having max(iym) < interval '496-0' year to month
+order by idt desc
+limit 5;
+
+select
+ count(iym), count(idt), min(key), max(key), min(iym), max(iym), min(idt), max(idt)
+from (
+ select
+ key,
+ interval_year_month(concat(key, '-1')) as iym,
+ interval_day_time(concat(key, ' 1:1:1')) as idt
+ from src) q1;
+