Review Board 1.7.22


DRILL_259 : implicit cast support in drill.

Review Request #16490 - Created Dec. 27, 2013 and updated

Jinfeng Ni
Reviewers
drill-git
drill-git
This patch is to provide implicit cast support in Drill.

The code change is mainly in two areas:

1. Function Resolver and related type cast rules : used to choose the best matched function implementation corresponding to a function name and its list of argument types. Type promotion would be implied, if there is no function implementation whose parameter types exactly match the argument types. Type promotion is implemented using the type precedence list. Type promotion is checked against a rule which will help implement a isCastable(from, to) method.  
New files: 1) DefaultFunctionResolver.java
           2) FunctionResolver
           3) FunctionResolverFactor.java
           4) OperatorFunctionResolver.java : reserved for future use. 
           5) ResolverTypePrecedence.java
           6) TypeCastRules.java
           7) UDFFunctionResolver.java : reserved for future use. 

2. ImplicitCastBuilder : to inject implicit cast whenever necessary. After the function resolver returns a best matched function implementation, if the param type does not match the argument type, an implicit cast will be inserted on top of the argument. 
   - ImplicitCastBuilder uses a visitor to inject implicit cast. 
   - ImplicitCastBuilder will be part of ExpressionTreeMateralizer, after we materialize the expression tree.
   - ExpressionValidator will be called after implicit cast is injected, in stead of after expression materialization.
   - Because ImplicitCastBuilder requires a FunctionImplementationRegistry (to decide the best matched function implementation), and ImplicitCastBuilder is part of ExpressionTreeMaterializer, all the call of ExpressionTreeMaterializer is modified by adding a FunctionImplementationRegistry. 

New files or modified files:
            1)CastFunctionDefs.java
            2)ExpressionTreeMaterializer.java
            3)ImplicitCastBuilder.java
            4)DrillFuncHolder.java : expose param type and size
            5)FunctionImplementationRegistry.java : expose the list of function implementation.
            6) other files because of the change to ExpressionTreeMaterializer.java. 

Some other minor changes:

1. ArgumentValidator.ComparableArguments :
  change allSame from true to false, since currently we have comparison operators defined over different types of inputs.

2. VectorUtil:
  Add code to handle null value when display the result.
testImplicitCastFunctions.java is used for unit test. It uses two physical plans
1. testICastConstant.json : the input expression is a literal constants.  eg, 1 + 1.2, etc. Also, cover the nested function cases.
2. testICastMockCol.json  : the input expression is a column from mock scan operator. 

Total:
4
Open:
4
Resolved:
0
Dropped:
0
Status:
From:
Review request changed
Updated (Jan. 3, 2014, 10:57 p.m.)
Modify the code to address review comments. 
Posted (Jan. 4, 2014, 12:20 a.m.)

   

  
Would it be worth possibly using code generation for this section of the class? It would make understanding how the different types' casting rules differ if they were specified in a more concise format.
Posted (Jan. 4, 2014, 5:48 p.m.)

   

  
I'm thinking something like this, it would give a nice overview to anyone curious about the differences in what can be casted and what cannot. Doesn't look the best because of the wordwrap, but if you paste it into a local editor to see that it is aligned for easy reading. http://pastebin.com/aysWxVFx
Posted (Jan. 4, 2014, 6:02 p.m.)

   

  
Should have put that through a JSON validator before posting, here is a revised version that is valid http://pastebin.com/kaZPM9Zr
Ship it!
Posted (Jan. 14, 2014, 4:51 p.m.)
Ship It!