drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansinha100 <...@git.apache.org>
Subject [GitHub] drill pull request: Drill 4372 review
Date Wed, 02 Mar 2016 07:33:55 GMT
Github user amansinha100 commented on a diff in the pull request:

    https://github.com/apache/drill/pull/397#discussion_r54688304
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
---
    @@ -92,38 +94,110 @@ public DrillFunctionRegistry(ScanResult classpathScan) {
       }
     
       public int size(){
    -    return methods.size();
    +    return registeredFunctions.size();
       }
     
       /** Returns functions with given name. Function name is case insensitive. */
       public List<DrillFuncHolder> getMethods(String name) {
    -    return this.methods.get(name.toLowerCase());
    +    return this.registeredFunctions.get(name.toLowerCase());
    +  }
    +
    +  public Collection<DrillFuncHolder> getAllMethods() {
    +    return Collections.unmodifiableCollection(registeredFunctions.values());
       }
     
       public void register(DrillOperatorTable operatorTable) {
    -    SqlOperator op;
    -    for (Entry<String, Collection<DrillFuncHolder>> function : methods.asMap().entrySet())
{
    -      Set<Integer> argCounts = Sets.newHashSet();
    -      String name = function.getKey().toUpperCase();
    +    for (Entry<String, Collection<DrillFuncHolder>> function : registeredFunctions.asMap().entrySet())
{
    +      final ArrayListMultimap<Pair<Integer, Integer>, DrillFuncHolder> functions
= ArrayListMultimap.create();
    +      final ArrayListMultimap<Integer, DrillFuncHolder> aggregateFunctions = ArrayListMultimap.create();
    +      final String name = function.getKey().toUpperCase();
    +      boolean isDeterministic = true;
           for (DrillFuncHolder func : function.getValue()) {
    -        if (argCounts.add(func.getParamCount())) {
    -          if (func.isAggregating()) {
    -            op = new DrillSqlAggOperator(name, func.getParamCount());
    -          } else {
    -            boolean isDeterministic;
    -            // prevent Drill from folding constant functions with types that cannot be
materialized
    -            // into literals
    -            if (DrillConstExecutor.NON_REDUCIBLE_TYPES.contains(func.getReturnType().getMinorType()))
{
    -              isDeterministic = false;
    -            } else {
    -              isDeterministic = func.isDeterministic();
    -            }
    -            op = new DrillSqlOperator(name, func.getParamCount(), func.getReturnType(),
isDeterministic);
    -          }
    -          operatorTable.add(function.getKey(), op);
    +        final int paramCount = func.getParamCount();
    +        if(func.isAggregating()) {
    +          aggregateFunctions.put(paramCount, func);
    +        } else {
    +          final Pair<Integer, Integer> argNumerRange = getArgNumerRange(name, func);
    +          functions.put(argNumerRange, func);
             }
    +
    +        if(!func.isDeterministic()) {
    +          isDeterministic = false;
    +        }
    +      }
    +      for (Entry<Pair<Integer, Integer>, Collection<DrillFuncHolder>>
entry : functions.asMap().entrySet()) {
    +        final DrillSqlOperator drillSqlOperator;
    +        final Pair<Integer, Integer> range = entry.getKey();
    +        final int max = range.getRight();
    +        final int min = range.getLeft();
    +        drillSqlOperator = new DrillSqlOperator(
    +            name,
    +            Lists.newArrayList(entry.getValue()),
    +            min,
    +            max,
    +            isDeterministic);
    +        operatorTable.add(name, drillSqlOperator);
    +      }
    +      for (Entry<Integer, Collection<DrillFuncHolder>> entry : aggregateFunctions.asMap().entrySet())
{
    +        operatorTable.add(name, new DrillSqlAggOperator(name, Lists.newArrayList(entry.getValue()),
entry.getKey()));
           }
         }
    +
    +    registerCalcitePlaceHolderFunction(operatorTable);
    +  }
    +
    +  /**
    +   * These {@link DrillSqlOperator} merely act as a placeholder so that Calcite
    +   * allows convert_to(), convert_from(), flatten(), date_part() functions in SQL.
    +   */
    +  private void registerCalcitePlaceHolderFunction(DrillOperatorTable operatorTable) {
    +    final String convert_to = "CONVERT_TO";
    --- End diff --
    
    There ought to be a more declarative way to populate the operator table with these types
of functions.  Here you have listed 4 such functions but what if there are a lot more ?  You
should only need to call operatorTable.add(arg1, arg2) once inside a loop and pass in different
values of arg1, arg2 based on a statically populated structure. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message