Repository: drill Updated Branches: refs/heads/master 6d5d7cc27 -> 357d0202c
DRILL-3554: Given types timestamp and time, implicit casting casts them to time Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/357d0202 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/357d0202 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/357d0202 Branch: refs/heads/master Commit: 357d0202cc6197921cfa50ccfcd39e2925362bce Parents: 6d5d7cc Author: Hsuan-Yi Chu <hsua...@usc.edu> Authored: Mon Jul 27 12:12:35 2015 -0700 Committer: Hsuan-Yi Chu <hsua...@usc.edu> Committed: Sun Aug 2 16:35:13 2015 -0700 ---------------------------------------------------------------------- .../exec/resolver/ResolverTypePrecedence.java | 2 +- .../drill/exec/resolver/TypeCastRules.java | 3 +- .../org/apache/drill/TestImplicitCasting.java | 41 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/357d0202/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java index ea3155d..29dd6a5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java @@ -69,11 +69,11 @@ public class ResolverTypePrecedence { precedenceMap.put(MinorType.DECIMAL38DENSE, i += 2); precedenceMap.put(MinorType.DECIMAL38SPARSE, i += 2); precedenceMap.put(MinorType.FLOAT8, i += 2); - precedenceMap.put(MinorType.TIME, i += 2); precedenceMap.put(MinorType.DATE, i += 2); precedenceMap.put(MinorType.TIMESTAMP, i += 2); precedenceMap.put(MinorType.TIMETZ, i += 2); precedenceMap.put(MinorType.TIMESTAMPTZ, i += 2); + precedenceMap.put(MinorType.TIME, i += 2); precedenceMap.put(MinorType.INTERVALDAY, i+= 2); precedenceMap.put(MinorType.INTERVALYEAR, i+= 2); precedenceMap.put(MinorType.INTERVAL, i+= 2); http://git-wip-us.apache.org/repos/asf/drill/blob/357d0202/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java index f861586..3278d3e 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java @@ -426,7 +426,6 @@ public class TypeCastRules { rule.add(MinorType.UINT4); rule.add(MinorType.UINT8); rule.add(MinorType.DATE); - rule.add(MinorType.TIME); rule.add(MinorType.TIMESTAMPTZ); rules.put(MinorType.TIMESTAMP, rule); @@ -786,7 +785,7 @@ public class TypeCastRules { } } - /* + /* * Function checks if casting is allowed from the 'from' -> 'to' minor type. If its allowed * we also check if the precedence map allows such a cast and return true if both cases are satisfied */ http://git-wip-us.apache.org/repos/asf/drill/blob/357d0202/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java b/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java new file mode 100644 index 0000000..ae94e36 --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/TestImplicitCasting.java @@ -0,0 +1,41 @@ +/** + * 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.drill; + +import org.apache.drill.common.types.MinorType; +import org.apache.drill.common.types.TypeProtos; +import org.apache.drill.exec.resolver.TypeCastRules; +import org.junit.Test; + +import com.google.common.collect.Lists; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class TestImplicitCasting { + @Test + public void testTimeStampAndTime() { + final List<TypeProtos.MinorType> inputTypes = Lists.newArrayList(); + inputTypes.add(TypeProtos.MinorType.TIME); + inputTypes.add(TypeProtos.MinorType.TIMESTAMP); + final TypeProtos.MinorType result = TypeCastRules.getLeastRestrictiveType(inputTypes); + + assertEquals(result, TypeProtos.MinorType.TIME); + } +}