Last active
December 26, 2015 10:59
-
-
Save yssharma/7140609 to your computer and use it in GitHub Desktop.
Sample Operator Function Resolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.apache.drill.exec.resolver; | |
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| import org.apache.drill.common.expression.FunctionCall; | |
| import org.apache.drill.common.expression.LogicalExpression; | |
| import org.apache.drill.common.types.TypeProtos.MajorType; | |
| import org.apache.drill.exec.expr.fn.DrillFuncHolder; | |
| import com.google.common.collect.ImmutableList; | |
| import com.google.common.collect.Lists; | |
| public class OperatorFuncResolver implements FuncResolver{ | |
| private static final Map<String, Integer> precedenceMap; | |
| /** Would be moved to a new class, would be shared by all resolvers **/ | |
| static { | |
| precedenceMap = new HashMap<String, Integer>(); | |
| precedenceMap.put("TINYINT", 1); | |
| precedenceMap.put("SMALLINT", 2); | |
| precedenceMap.put("INT", 3); | |
| precedenceMap.put("BIGINT", 4); | |
| precedenceMap.put("FLOAT4", 5); | |
| precedenceMap.put("FLOAT8", 6); | |
| precedenceMap.put("VARCHAR", 7); | |
| } | |
| @Override | |
| public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods, FunctionCall call) { | |
| ImmutableList<LogicalExpression> args = call.args; | |
| if(args.size() != 2){ | |
| } | |
| LogicalExpression l1 = args.get(0); | |
| LogicalExpression l2 = args.get(1); | |
| int t1 = precedenceMap.get(args.get(0).getMajorType()); //BIGINT, REQUIRED | |
| int t2 = precedenceMap.get(args.get(1).getMajorType()); // FLOAT8, REQUIRED | |
| MajorType commonType = (t1 > t2) ? args.get(0).getMajorType() : args.get(1).getMajorType(); | |
| /** Convert arguments to new args and continue search of best match function **/ | |
| /*List<LogicalExpression> newargs = Lists.newArrayList(); | |
| for (int i = 0; i < call.args.size(); ++i) { | |
| LogicalExpression newExpr = // TODO | |
| args.add(newExpr); | |
| }*/ | |
| /** Conversion of call to new argument types **/ | |
| //FunctionCall modifiedCall = new FunctionCall(call.getDefinition(), newargs, call.getPosition()); | |
| for(DrillFuncHolder h : methods){ | |
| if(h.matches(call)){ | |
| return h; | |
| } | |
| } | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment