drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudheeshkatkam <...@git.apache.org>
Subject [GitHub] drill pull request: Drill 4372 for review
Date Sat, 20 Feb 2016 00:41:21 GMT
Github user sudheeshkatkam commented on a diff in the pull request:

    https://github.com/apache/drill/pull/377#discussion_r53538425
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillCalciteSqlFunctionWrapper.java
---
    @@ -0,0 +1,212 @@
    +/**
    + * 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.planner.sql;
    +
    +import com.google.common.collect.ArrayListMultimap;
    +import com.google.common.collect.Lists;
    +
    +import org.apache.calcite.rel.type.RelDataType;
    +import org.apache.calcite.sql.SqlCall;
    +import org.apache.calcite.sql.SqlCallBinding;
    +import org.apache.calcite.sql.SqlFunction;
    +import org.apache.calcite.sql.SqlOperandCountRange;
    +import org.apache.calcite.sql.SqlOperator;
    +import org.apache.calcite.sql.SqlOperatorBinding;
    +import org.apache.calcite.sql.SqlSyntax;
    +import org.apache.calcite.sql.SqlWriter;
    +import org.apache.calcite.sql.fun.SqlStdOperatorTable;
    +import org.apache.calcite.sql.type.SqlOperandTypeChecker;
    +import org.apache.calcite.sql.type.SqlOperandTypeInference;
    +import org.apache.calcite.sql.type.SqlReturnTypeInference;
    +import org.apache.calcite.sql.validate.SqlMonotonicity;
    +import org.apache.calcite.sql.validate.SqlValidator;
    +import org.apache.calcite.sql.validate.SqlValidatorScope;
    +
    +import org.apache.drill.exec.expr.fn.DrillFuncHolder;
    +
    +import java.util.List;
    +
    +public class DrillCalciteSqlFunctionWrapper extends SqlFunction implements DrillCalciteSqlWrapper
 {
    +  private final SqlFunction operator;
    +  private final SqlOperandTypeChecker operandTypeChecker = new Checker();
    +  private final ArrayListMultimap<String, SqlOperator> opMap;
    +
    +  public DrillCalciteSqlFunctionWrapper(
    +      final SqlFunction wrappedFunction,
    +      final ArrayListMultimap<String, SqlOperator> opMap) {
    +    super(wrappedFunction.getName(),
    +        wrappedFunction.getSqlIdentifier(),
    +        wrappedFunction.getKind(),
    +        wrappedFunction.getReturnTypeInference(),
    +        wrappedFunction.getOperandTypeInference(),
    +        wrappedFunction.getOperandTypeChecker(),
    +        wrappedFunction.getParamTypes(),
    +        wrappedFunction.getFunctionType());
    +    this.operator = wrappedFunction;
    +    this.opMap = opMap;
    +  }
    +
    +  @Override
    +  public SqlOperator getOperator() {
    +    return operator;
    +  }
    +
    +  @Override
    +  public boolean validRexOperands(int count, boolean fail) {
    +    return true;
    +  }
    +
    +  @Override
    +  public String getAllowedSignatures(String opNameToUse) {
    +    return operator.getAllowedSignatures(opNameToUse);
    +  }
    +
    +  @Override
    +  public SqlOperandTypeInference getOperandTypeInference() {
    +    return operator.getOperandTypeInference();
    +  }
    +
    +  @Override
    +  public boolean isAggregator() {
    +    return operator.isAggregator();
    +  }
    +
    +  @Override
    +  public boolean requiresOrder() {
    +    return operator.requiresOrder();
    +  }
    +
    +  @Override
    +  public boolean allowsFraming() {
    +    return operator.allowsFraming();
    +  }
    +
    +  @Override
    +  public SqlReturnTypeInference getReturnTypeInference() {
    +    return operator.getReturnTypeInference();
    +  }
    +
    +  @Override
    +  public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    +    return operator.getMonotonicity(call);
    +  }
    +
    +  @Override
    +  public boolean isDeterministic() {
    +    return operator.isDeterministic();
    +  }
    +
    +  @Override
    +  public boolean isDynamicFunction() {
    +    return operator.isDynamicFunction();
    +  }
    +
    +  @Override
    +  public boolean requiresDecimalExpansion() {
    +    return operator.requiresDecimalExpansion();
    +  }
    +
    +  @Override
    +  public boolean argumentMustBeScalar(int ordinal) {
    +    return operator.argumentMustBeScalar(ordinal);
    +  }
    +
    +  @Override
    +  public SqlOperandTypeChecker getOperandTypeChecker() {
    +    return operandTypeChecker;
    +  }
    +
    +  @Override
    +  public SqlOperandCountRange getOperandCountRange() {
    +    return operandTypeChecker.getOperandCountRange();
    +  }
    +
    +  @Override
    +  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    +    if(operator == SqlStdOperatorTable.CAST) {
    +      return operator.inferReturnType(opBinding);
    +    } else if(operator == SqlStdOperatorTable.EXTRACT) {
    +      final RelDataType returnType = DrillExtractConvertlet.inferReturnType(
    +          opBinding.getTypeFactory(),
    +          opBinding.getOperandType(0).getIntervalQualifier().getStartUnit(),
    +          opBinding.getOperandType(1).isNullable());
    +      return returnType;
    +    }
    +
    +    final List<DrillFuncHolder> functions = Lists.newArrayList();
    +    for(SqlOperator sqlOperator : opMap.get(getOperator().getName().toLowerCase())) {
    +      if(sqlOperator instanceof DrillSqlOperator
    +          && ((DrillSqlOperator) sqlOperator).getFunctions() != null) {
    +        functions.addAll(((DrillSqlOperator) sqlOperator).getFunctions());
    +      }
    +    }
    +
    +    return TypeInferenceUtils.inferReturnType(opBinding, functions);
    +  }
    +
    +  @Override
    +  public boolean checkOperandTypes(
    +      SqlCallBinding callBinding,
    +      boolean throwOnFailure) {
    +    return true;
    --- End diff --
    
    doc


---
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