You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2014/01/14 17:48:30 UTC
[4/6] DRILL-259: Implicit cast functionality
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/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 76d52be..b16d1ff 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
@@ -1,3 +1,21 @@
+/**
+ * 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.exec.resolver;
import java.util.HashMap;
@@ -5,462 +23,529 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.fn.DrillFuncHolder;
public class TypeCastRules {
-
- private static Map<MinorType, Set<MinorType>> rules;
-
- public TypeCastRules(){
-
-
- rules = new HashMap<MinorType, Set<MinorType>>();
-
- Set<MinorType> rule;
-
- /** TINYINT cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.TINYINT, rule);
-
- /** SMALLINT cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.SMALLINT, rule);
-
- /** INT cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.INT, rule);
-
- /** BIGINT cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.BIGINT, rule);
-
- /** DECIMAL4 cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.DECIMAL4, rule);
-
- /** DECIMAL8 cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.DECIMAL8, rule);
-
- /** DECIMAL12 cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.DECIMAL12, rule);
-
- /** DECIMAL16 cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.DECIMAL16, rule);
-
- /** MONEY cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.MONEY, rule);
-
- /** DATE cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.DATE);
- rule.add(MinorType.DATETIME);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.DATE, rule);
-
- /** TIME cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TIME);
- rule.add(MinorType.DATETIME);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rules.put(MinorType.TIME, rule);
-
- /** DATETIME cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.DATETIME);
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.DATE);
- rule.add(MinorType.TIME);
- rule.add(MinorType.TIMESTAMP);
- rules.put(MinorType.DATETIME, rule);
-
- /** FLOAT4 cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rules.put(MinorType.FLOAT4, rule);
-
- /** FLOAT8 cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rules.put(MinorType.FLOAT8, rule);
-
- /** BIT cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rules.put(MinorType.BIT, rule);
-
- /** FIXEDCHAR cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.DATE);
- rule.add(MinorType.TIME);
- rule.add(MinorType.DATETIME);
- rules.put(MinorType.FIXEDCHAR, rule);
-
- /** FIXED16CHAR cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.DATE);
- rule.add(MinorType.TIME);
- rule.add(MinorType.DATETIME);
- rules.put(MinorType.FIXED16CHAR, rule);
-
- /** FIXEDBINARY cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rules.put(MinorType.FIXEDBINARY, rule);
-
- /** VARCHAR cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.DATE);
- rule.add(MinorType.TIME);
- rule.add(MinorType.DATETIME);
- rules.put(MinorType.VARCHAR, rule);
-
- /** VAR16CHAR cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.FIXEDCHAR);
- rule.add(MinorType.FIXED16CHAR);
- rule.add(MinorType.VARCHAR);
- rule.add(MinorType.VAR16CHAR);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rule.add(MinorType.DATE);
- rule.add(MinorType.TIME);
- rule.add(MinorType.DATETIME);
- rules.put(MinorType.VAR16CHAR, rule);
-
- /** VARBINARY cast able from **/
- rule = new HashSet<MinorType>();
- rule.add(MinorType.TINYINT);
- rule.add(MinorType.SMALLINT);
- rule.add(MinorType.INT);
- rule.add(MinorType.BIGINT);
- rule.add(MinorType.DECIMAL4);
- rule.add(MinorType.DECIMAL8);
- rule.add(MinorType.DECIMAL12);
- rule.add(MinorType.DECIMAL16);
- rule.add(MinorType.MONEY);
- rule.add(MinorType.TIMESTAMP);
- rule.add(MinorType.FLOAT4);
- rule.add(MinorType.FLOAT8);
- rule.add(MinorType.BIT);
- rule.add(MinorType.VARBINARY);
- rule.add(MinorType.FIXEDBINARY);
- rules.put(MinorType.VARBINARY, rule);
-
-
- }
-
- public static boolean isCastable(MinorType from, MinorType to){
- return rules.get(from)==null ? false: rules.get(from).contains(to);
- }
+
+ private static Map<MinorType, Set<MinorType>> rules;
+
+ public TypeCastRules() {
+ }
+
+ static {
+ initTypeRules();
+ }
+
+ private static void initTypeRules() {
+ rules = new HashMap<MinorType, Set<MinorType>>();
+
+ Set<MinorType> rule;
+
+ /** TINYINT cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.TINYINT, rule);
+
+ /** SMALLINT cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.SMALLINT, rule);
+
+ /** INT cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.INT, rule);
+
+ /** BIGINT cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.BIGINT, rule);
+
+ /** DECIMAL4 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.DECIMAL4, rule);
+
+ /** DECIMAL8 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.DECIMAL8, rule);
+
+ /** DECIMAL12 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.DECIMAL12, rule);
+
+ /** DECIMAL16 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.DECIMAL16, rule);
+
+ /** MONEY cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.MONEY, rule);
+
+ /** DATE cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.DATE);
+ rule.add(MinorType.DATETIME);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.DATE, rule);
+
+ /** TIME cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TIME);
+ rule.add(MinorType.DATETIME);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.TIME, rule);
+
+ /** DATETIME cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.DATETIME);
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.DATE);
+ rule.add(MinorType.TIME);
+ rule.add(MinorType.TIMESTAMP);
+ rules.put(MinorType.DATETIME, rule);
+
+ /** FLOAT4 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rules.put(MinorType.FLOAT4, rule);
+
+ /** FLOAT8 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rules.put(MinorType.FLOAT8, rule);
+
+ /** BIT cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rules.put(MinorType.BIT, rule);
+
+ /** FIXEDCHAR cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.DATE);
+ rule.add(MinorType.TIME);
+ rule.add(MinorType.DATETIME);
+ rules.put(MinorType.FIXEDCHAR, rule);
+
+ /** FIXED16CHAR cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.DATE);
+ rule.add(MinorType.TIME);
+ rule.add(MinorType.DATETIME);
+ rules.put(MinorType.FIXED16CHAR, rule);
+
+ /** FIXEDBINARY cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rules.put(MinorType.FIXEDBINARY, rule);
+
+ /** VARCHAR cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.DATE);
+ rule.add(MinorType.TIME);
+ rule.add(MinorType.DATETIME);
+ rules.put(MinorType.VARCHAR, rule);
+
+ /** VAR16CHAR cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.DATE);
+ rule.add(MinorType.TIME);
+ rule.add(MinorType.DATETIME);
+ rules.put(MinorType.VAR16CHAR, rule);
+
+ /** VARBINARY cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.DECIMAL4);
+ rule.add(MinorType.DECIMAL8);
+ rule.add(MinorType.DECIMAL12);
+ rule.add(MinorType.DECIMAL16);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.TIMESTAMP);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.VARBINARY);
+ rule.add(MinorType.FIXEDBINARY);
+ rules.put(MinorType.VARBINARY, rule);
+ }
+
+ public static boolean isCastable(MajorType from, MajorType to) {
+ return from.getMinorType().equals(MinorType.NULL) || //null could be casted to any other type.
+ (rules.get(to.getMinorType()) == null ? false : rules.get(to.getMinorType()).contains(from.getMinorType()));
+ }
+
+ /*
+ * code decide whether it's legal to do implicit cast. -1 : not allowed for
+ * implicit cast > 0: cost associated with implicit cast. ==0: parms are
+ * exactly same type of arg. No need of implicit.
+ */
+ public static int getCost(FunctionCall call, DrillFuncHolder holder) {
+ int cost = 0;
+
+ if (call.args.size() != holder.getParmSize()) {
+ return -1;
+ }
+
+ for (int i = 0; i < holder.getParmSize(); i++) {
+ MajorType argType = call.args.get(i).getMajorType();
+ MajorType parmType = holder.getParmMajorType(i);
+
+ if (!TypeCastRules.isCastable(argType, parmType)) {
+ return -1;
+ }
+
+ Integer parmVal = ResolverTypePrecedence.precedenceMap.get(parmType
+ .getMinorType());
+ Integer argVal = ResolverTypePrecedence.precedenceMap.get(argType
+ .getMinorType());
+
+ if (parmVal == null) {
+ throw new RuntimeException(String.format(
+ "Precedence for type %s is not defined", parmType.getMinorType()
+ .name()));
+ }
+
+ if (argVal == null) {
+ throw new RuntimeException(String.format(
+ "Precedence for type %s is not defined", argType.getMinorType()
+ .name()));
+ }
+
+ if (parmVal - argVal < 0) {
+ return -1;
+ }
+
+ // Check null vs non-null, using same logic as that in Types.softEqual()
+ // Only when the function uses NULL_IF_NULL, nullable and non-nullable are inter-changable.
+ // Otherwise, the function implementation is not a match.
+ if (argType.getMode() != parmType.getMode())
+ if (!((holder.getNullHandling() == NullHandling.NULL_IF_NULL) &&
+ (argType.getMode() == DataMode.OPTIONAL ||
+ argType.getMode() == DataMode.REQUIRED ||
+ parmType.getMode() == DataMode.OPTIONAL ||
+ parmType.getMode() == DataMode.REQUIRED )))
+ return -1;
+
+ cost += (parmVal - argVal);
+ }
+
+ return cost;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java
deleted file mode 100644
index 94ba37d..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.apache.drill.exec.resolver;
-
-import java.util.List;
-
-import org.apache.drill.common.expression.FunctionCall;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder;
-
-public class UDFFunctionResolver implements FunctionResolver {
-
- @Override
- public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods,
- FunctionCall call) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
index 8b23bcd..553e50d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
@@ -49,7 +49,11 @@ public class VectorUtil {
}
for (VectorWrapper vw : va) {
Object o = vw.getValueVector().getAccessor().getObject(row);
- if (o instanceof byte[]) {
+ if (o == null) {
+ //null value
+ System.out.printf("| %-15s", "");
+ }
+ else if (o instanceof byte[]) {
String value = new String((byte[]) o);
System.out.printf("| %-15s",value.length() <= 15 ? value : value.substring(0, 14));
} else {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
index 4bff5a3..535f892 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
@@ -50,6 +50,9 @@ import org.junit.Test;
public class ExpressionTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionTest.class);
+
+ DrillConfig c = DrillConfig.create();
+ FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
@Test
public void testBasicExpression(@Injectable RecordBatch batch) throws Exception {
@@ -105,7 +108,7 @@ public class ExpressionTest {
private String getExpressionCode(String expression, RecordBatch batch) throws Exception {
LogicalExpression expr = parseExpr(expression);
ErrorCollector error = new ErrorCollectorImpl();
- LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error);
+ LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, registry);
if (error.getErrorCount() != 0) {
logger.error("Failure while materializing expression [{}]. Errors: {}", expression, error);
assertEquals(0, error.getErrorCount());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
new file mode 100644
index 0000000..d1e1fe2
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
@@ -0,0 +1,179 @@
+/**
+ * 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.exec.physical.impl;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import com.codahale.metrics.MetricRegistry;
+
+import mockit.Injectable;
+import mockit.NonStrictExpectations;
+
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.expression.ExpressionPosition;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.physical.PhysicalPlan;
+import org.apache.drill.exec.physical.base.FragmentRoot;
+import org.apache.drill.exec.planner.PhysicalPlanReader;
+import org.apache.drill.exec.proto.CoordinationProtos;
+import org.apache.drill.exec.proto.ExecProtos;
+import org.apache.drill.exec.rpc.user.UserServer;
+import org.apache.drill.exec.server.DrillbitContext;
+import org.apache.drill.exec.vector.BigIntVector;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.exec.vector.VarCharVector;
+import org.junit.AfterClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.Assert;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class TestImplicitCastFunctions {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestImplicitCastFunctions.class);
+
+ DrillConfig c = DrillConfig.create();
+ PhysicalPlanReader reader;
+ FunctionImplementationRegistry registry;
+ FragmentContext context;
+
+ public Object[] getRunResult(SimpleRootExec exec) {
+ int size = 0;
+ for (ValueVector v : exec) {
+ size++;
+ }
+
+ Object[] res = new Object [size];
+ int i = 0;
+ for (ValueVector v : exec) {
+ res[i++] = v.getAccessor().getObject(0);
+ }
+ return res;
+ }
+
+ public void runTest(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable {
+
+ new NonStrictExpectations(){{
+ bitContext.getMetrics(); result = new MetricRegistry();
+ bitContext.getAllocator(); result = BufferAllocator.getAllocator(c);
+ bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
+ }};
+
+ String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8);
+ if(reader == null) reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
+ if(registry == null) registry = new FunctionImplementationRegistry(c);
+ if(context == null) context = new FragmentContext(bitContext, ExecProtos.FragmentHandle.getDefaultInstance(), connection, registry);
+ PhysicalPlan plan = reader.readPhysicalPlan(planString);
+ SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
+
+
+ while(exec.next()){
+ Object [] res = getRunResult(exec);
+ assertEquals("return count does not match", res.length, expectedResults.length);
+
+ for (int i = 0; i<res.length; i++) {
+ assertEquals(String.format("column %s does not match", i), res[i], expectedResults[i]);
+ }
+ }
+
+ if(context.getFailureCause() != null){
+ throw context.getFailureCause();
+ }
+
+ assertTrue(!context.isFailed());
+ }
+
+ @Test
+ public void testImplicitCastWithConstant(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ Object [] expected = new Object[21];
+ expected [0] = new Double (30.1);
+ expected [1] = new Double (30.1);
+ expected [2] = new Double (30.1);
+ expected [3] = new Double (30.1);
+ expected [4] = new Long (30);
+ expected [5] = new Long (30);
+
+ expected [6] = new Double (30.1);
+ expected [7] = new Double (30.1);
+ expected [8] = new Float (30.1);
+ expected [9] = new Float (30.1);
+ expected [10] = new Double (30.1);
+ expected [11] = new Double (30.1);
+
+ expected [12] = new Float (30.1);
+ expected [13] = new Double (30.1);
+ expected [14] = new Float (30.1);
+ expected [15] = new Double (30.1);
+
+ expected [16] = Boolean.TRUE;
+ expected [17] = Boolean.TRUE;
+ expected [18] = Boolean.TRUE;
+ expected [19] = Boolean.TRUE;
+ expected [20] = Boolean.TRUE;
+
+ runTest(bitContext, connection, expected, "functions/cast/testICastConstant.json");
+ }
+
+ @Test
+ public void testImplicitCastWithMockColumn(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ Object [] expected = new Object[5];
+ expected [0] = new Integer (0);
+ expected [1] = new Integer (0);
+ expected [2] = new Float (-4.2949673E9);
+ expected [3] = new Float (-4.2949673E9);
+ expected [4] = new Double (-9.223372036854776E18);
+
+ runTest(bitContext, connection, expected, "functions/cast/testICastMockCol.json");
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception{
+ // pause to get logger to catch up.
+ Thread.sleep(1000);
+ }
+
+ @Test
+ public void testImplicitCastWithNullExpression(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ Object [] expected = new Object[10];
+
+ expected [0] = Boolean.TRUE;
+ expected [1] = Boolean.FALSE;
+ expected [2] = Boolean.FALSE;
+ expected [3] = Boolean.TRUE;
+
+ expected [4] = null;
+ expected [5] = null;
+ expected [6] = null;
+ expected [7] = null;
+ expected [8] = null;
+ expected [9] = null;
+
+ runTest(bitContext, connection, expected, "functions/cast/testICastNullExp.json");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
index 7ee1718..b3b7536 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
@@ -26,6 +26,7 @@ import java.util.List;
import mockit.Injectable;
import mockit.NonStrictExpectations;
+import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ArgumentValidator;
import org.apache.drill.common.expression.ErrorCollector;
import org.apache.drill.common.expression.ErrorCollectorImpl;
@@ -43,6 +44,7 @@ import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.expr.ExpressionTreeMaterializer;
+import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.proto.SchemaDefProtos.FieldDef;
import org.apache.drill.exec.proto.SchemaDefProtos.NamePart;
import org.junit.Test;
@@ -58,6 +60,9 @@ public class ExpressionTreeMaterializerTest {
final MajorType bigIntType = MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(MinorType.BIGINT).build();
final MajorType intType = MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(MinorType.INT).build();
+ DrillConfig c = DrillConfig.create();
+ FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
+
private MaterializedField getField(int fieldId, String name, MajorType type) {
return new MaterializedField(FieldDef.newBuilder().setMajorType(type).addName(NamePart.newBuilder().setName(name))
.build());
@@ -68,7 +73,7 @@ public class ExpressionTreeMaterializerTest {
ErrorCollector ec = new ErrorCollectorImpl();
LogicalExpression expr = ExpressionTreeMaterializer.materialize(new ValueExpressions.LongExpression(1L,
- ExpressionPosition.UNKNOWN), batch, ec);
+ ExpressionPosition.UNKNOWN), batch, ec, registry);
assertTrue(expr instanceof ValueExpressions.LongExpression);
assertEquals(1L, ValueExpressions.LongExpression.class.cast(expr).getLong());
assertFalse(ec.hasErrors());
@@ -89,7 +94,7 @@ public class ExpressionTreeMaterializerTest {
ErrorCollector ec = new ErrorCollectorImpl();
LogicalExpression expr = ExpressionTreeMaterializer.materialize(new FieldReference("test",
- ExpressionPosition.UNKNOWN), batch, ec);
+ ExpressionPosition.UNKNOWN), batch, ec, registry);
assertEquals(bigIntType, expr.getMajorType());
assertFalse(ec.hasErrors());
}
@@ -121,7 +126,7 @@ public class ExpressionTreeMaterializerTest {
.setElse(new ValueExpressions.LongExpression(1L, ExpressionPosition.UNKNOWN)).build()) //
) //
.setElse(new ValueExpressions.LongExpression(1L, ExpressionPosition.UNKNOWN)).build();
- LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(expr, batch, ec);
+ LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(expr, batch, ec, registry);
assertTrue(newExpr instanceof IfExpression);
IfExpression newIfExpr = (IfExpression) newExpr;
assertEquals(1, newIfExpr.conditions.size());
@@ -216,7 +221,7 @@ public class ExpressionTreeMaterializerTest {
}
}, OutputTypeDeterminer.FIXED_BIT), ImmutableList.of((LogicalExpression) //
new FieldReference("test", ExpressionPosition.UNKNOWN) ), ExpressionPosition.UNKNOWN);
- LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(functionCallExpr, batch, ec);
+ LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(functionCallExpr, batch, ec, registry);
assertTrue(newExpr instanceof FunctionCall);
FunctionCall funcExpr = (FunctionCall) newExpr;
assertEquals(1, funcExpr.args.size());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/test/resources/functions/cast/testICastConstant.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/cast/testICastConstant.json b/exec/java-exec/src/test/resources/functions/cast/testICastConstant.json
new file mode 100644
index 0000000..22b868c
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/cast/testICastConstant.json
@@ -0,0 +1,54 @@
+{
+ head:{
+ type:"APACHE_DRILL_PHYSICAL",
+ version:"1",
+ generator:{
+ type:"manual"
+ }
+ },
+ graph:[
+ {
+ @id:1,
+ pop:"mock-sub-scan",
+ url: "http://apache.org",
+ entries:[
+ {records: 1, types: [
+ {name: "intColumn", type: "INT", mode: "REQUIRED"}
+ ]}
+ ]
+ },
+ {
+ @id:2,
+ child: 1,
+ pop:"project",
+ exprs: [
+ { ref: "BigIntAddFloat8", expr:"10+20.1" },
+ { ref: "Float8AddBigInt", expr:"20.1+10" },
+ { ref: "Float8AddChar", expr:"20.1 + \"10\"" },
+ { ref: "IntAddFloat8", expr:"cast(\"10\" as int) + 20.1"},
+ { ref: "IntAddBigInt", expr:"cast(\"10\" as int) + cast(\"20\" as bigint)"},
+ { ref: "BigIntAddInt", expr:"cast(\"10\" as bigint) + cast(\"20\" as int)"},
+ { ref: "IntAddFloat8", expr:"cast(\"10\" as int) + cast(\"20.1\" as float8)"},
+ { ref: "Float8AddInt", expr:"cast(\"20.1\" as float8) + cast(\"10\" as int) "},
+ { ref: "IntAddFloat4", expr:"cast(\"10\" as int) + cast(\"20.1\" as float4)"},
+ { ref: "BigIntAddFloat4", expr:"cast(\"10\" as bigint) + cast(\"20.1\" as float4)"},
+ { ref: "BigIntAddFloat8", expr:"cast(\"10\" as bigint) + cast(\"20.1\" as float8)"},
+ { ref: "Float4AddFloat8", expr:"cast(\"10\" as float4) + cast(\"20.1\" as float8)"},
+ { ref: "CharAddFloat4", expr:"\"10\" + cast(\"20.1\" as float4)"},
+ { ref: "CharAddFloat8", expr:"\"10\" + cast(\"20.1\" as float8)"},
+ { ref: "Float4AddFloat8", expr:"cast(\"10\" as float4) + \"20.1\" "},
+ { ref: "Float8AddChar", expr:"cast(\"10\" as float8) + \"20.1\" "},
+ { ref: "CompBigIntFloat8", expr:"10 < 20.1" },
+ { ref: "CompCharFloat8", expr:"\"10\" < 20.1" },
+ { ref: "CompFloat8Char", expr:"20.1 > \"10\" " },
+ { ref: "nested1", expr:" 20.1 + 10 > \"10\" " },
+ { ref: "nested2", expr:" 20.1 + 10 > \"10\" + 15.1" }
+ ]
+ },
+ {
+ @id: 3,
+ child: 2,
+ pop: "screen"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/test/resources/functions/cast/testICastMockCol.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/cast/testICastMockCol.json b/exec/java-exec/src/test/resources/functions/cast/testICastMockCol.json
new file mode 100644
index 0000000..b9fd242
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/cast/testICastMockCol.json
@@ -0,0 +1,45 @@
+{
+ head:{
+ type:"APACHE_DRILL_PHYSICAL",
+ version:"1",
+ generator:{
+ type:"manual"
+ }
+ },
+ graph:[
+ {
+ @id: 1,
+ pop:"mock-sub-scan",
+ url: "http://apache.org",
+ entries:[
+ {records: 1, types: [
+ {name: "intColumn", type: "INT", mode: "REQUIRED"},
+ {name: "bigIntColumn", type: "BIGINT", mode: "REQUIRED"},
+ {name: "float4Column", type: "FLOAT4", mode: "REQUIRED"},
+ {name: "float8Column", type: "FLOAT8", mode: "REQUIRED"},
+ {name: "intNullableColumn", type: "INT", mode: "OPTIONAL"},
+ {name: "bigIntNullableColumn", type: "BIGINT", mode: "OPTIONAL"},
+ {name: "float4NullableColumn", type: "FLOAT4", mode: "OPTIONAL"},
+ {name: "float8NullableColumn", type: "FLOAT8", mode: "OPTIONAL"}
+ ]}
+ ]
+ },
+ {
+ @id:2,
+ child: 1,
+ pop:"project",
+ exprs: [
+ { ref: "NullIntAddInt", expr:"intNullableColumn + intColumn" },
+ { ref: "IntAddNullInt", expr:"intColumn + intNullableColumn " },
+ { ref: "IntAddNullFloat4", expr:"intColumn + float4NullableColumn " },
+ { ref: "Float4AddNullInt", expr:"float4Column + intNullableColumn " },
+ { ref: "Float8AddNullBigInt", expr:"float8Column + bigIntNullableColumn " }
+ ]
+ },
+ {
+ @id: 3,
+ child: 2,
+ pop: "screen"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/exec/java-exec/src/test/resources/functions/cast/testICastNullExp.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/cast/testICastNullExp.json b/exec/java-exec/src/test/resources/functions/cast/testICastNullExp.json
new file mode 100644
index 0000000..6b8fd44
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/cast/testICastNullExp.json
@@ -0,0 +1,43 @@
+{
+ head:{
+ type:"APACHE_DRILL_PHYSICAL",
+ version:"1",
+ generator:{
+ type:"manual"
+ }
+ },
+ graph:[
+ {
+ @id:1,
+ pop:"mock-sub-scan",
+ url: "http://apache.org",
+ entries:[
+ {records: 1, types: [
+ {name: "float8Column", type: "FLOAT8", mode: "OPTIONAL"}
+ ]}
+ ]
+ },
+ {
+ @id:2,
+ child: 1,
+ pop:"project",
+ exprs: [
+ { ref: "isNullOfNullExp", expr:"isnull(unkonwCol)" },
+ { ref: "isNullOfKnowCol", expr:"isnull(float8Column)" },
+ { ref: "isNotNullOfNullExp", expr:"isnotnull(unkonwCol)" },
+ { ref: "isNotNullOfKnowCol", expr:"isnotnull(float8Column)" },
+ { ref: "BigIntAddNullExp", expr:"1 + unknowCol" },
+ { ref: "NullExpAddBigInt", expr:"unknowCol + 1" },
+ { ref: "Float8AddNullExp", expr:"1.2 + unknowCol" },
+ { ref: "NullExpAddFloat8", expr:"unknowCol + 1.2" },
+ { ref: "Float4AddNullExp", expr:"cast(1.2 as float4) + unknowCol" },
+ { ref: "NullExpAddFloat4", expr:"unknowCol +cast(1.2 as float4) " }
+ ]
+ },
+ {
+ @id: 3,
+ child: 2,
+ pop: "screen"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 09c1522..69d280c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,7 +90,6 @@
<build>
<plugins>
- <!--
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
@@ -119,8 +118,7 @@
</excludes>
</configuration>
</plugin>
- -->
-
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -187,13 +185,11 @@
<pluginManagement>
<plugins>
- <!--
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>0.10</version>
</plugin>
- -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
@@ -304,7 +300,6 @@
<ignore />
</action>
</pluginExecution>
- <!--
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.rat</groupId>
@@ -318,7 +313,6 @@
<ignore/>
</action>
</pluginExecution>
- -->
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
@@ -576,9 +570,7 @@
<id>mapr</id>
<properties>
<alt-hadoop>mapr</alt-hadoop>
- <!--
<rat.excludeSubprojects>false</rat.excludeSubprojects>
- -->
</properties>
<dependencyManagement>
<dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/db020369/sqlline
----------------------------------------------------------------------
diff --git a/sqlline b/sqlline
index 2cfbd89..8cc9531 100755
--- a/sqlline
+++ b/sqlline
@@ -26,7 +26,6 @@ fi
#exec java -Drebel.log=true -javaagent:/src/jrebel/jrebel.jar -Dlogback.configurationFile=/src/drill/sandbox/prototype/sqlparser/src/test/resources/logback.xml -cp ./:"$(cat .classpath)" sqlline.SqlLine "$@"
exec java -Xmx2G -Dlogback.configurationFile=./sqlparser/src/test/resources/logback.xml -cp ./:"$(cat .classpath)" sqlline.SqlLine --verbose=true "$@"
-#exec java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xmx2G -Dlogback.configurationFile=./sqlparser/src/test/resources/logback.xml -cp ./:"$(cat .classpath)" sqlline.SqlLine --verbose=true "$@"
# End sqlline