drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hsuanyi <...@git.apache.org>
Subject [GitHub] drill pull request: Drill 4372 for review
Date Tue, 23 Feb 2016 09:45:10 GMT
Github user hsuanyi commented on a diff in the pull request:

    https://github.com/apache/drill/pull/377#discussion_r53756495
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/TypeInferenceUtils.java
---
    @@ -0,0 +1,196 @@
    +/**
    + * 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.Lists;
    +import com.google.common.collect.Sets;
    +import org.apache.calcite.avatica.util.TimeUnit;
    +import org.apache.calcite.rel.type.RelDataType;
    +import org.apache.calcite.rel.type.RelDataTypeFactory;
    +import org.apache.calcite.sql.SqlIntervalQualifier;
    +import org.apache.calcite.sql.SqlOperatorBinding;
    +import org.apache.calcite.sql.parser.SqlParserPos;
    +import org.apache.calcite.sql.type.SqlTypeName;
    +import org.apache.drill.common.expression.DumbLogicalExpression;
    +import org.apache.drill.common.expression.ExpressionPosition;
    +import org.apache.drill.common.expression.FunctionCall;
    +import org.apache.drill.common.expression.LogicalExpression;
    +import org.apache.drill.common.types.TypeProtos;
    +import org.apache.drill.common.types.Types;
    +import org.apache.drill.exec.expr.fn.DrillFuncHolder;
    +import org.apache.drill.exec.planner.logical.DrillConstExecutor;
    +import org.apache.drill.exec.resolver.FunctionResolver;
    +import org.apache.drill.exec.resolver.FunctionResolverFactory;
    +
    +import java.util.List;
    +import java.util.Set;
    +
    +public class TypeInferenceUtils {
    +  public static final TypeProtos.MajorType NONE = TypeProtos.MajorType.getDefaultInstance();
    +  public static final int MAX_VARCHAR_LENGTH = 65535;
    +
    +  private static final Set<String> setFnWithDynamicTypes = Sets.newHashSet();
    +  static {
    +    setFnWithDynamicTypes.add("FALTTEN");
    +    setFnWithDynamicTypes.add("KVGEN");
    +    setFnWithDynamicTypes.add("CONVERT_FROM");
    +  }
    +
    +  public static RelDataType inferReturnType(final SqlOperatorBinding opBinding, final
List<DrillFuncHolder> functions) {
    +    if(functions == null
    +        || functions.isEmpty()
    +            || setFnWithDynamicTypes.contains(opBinding.getOperator().getName().toUpperCase()))
{
    +      return opBinding.getTypeFactory()
    +          .createTypeWithNullability(opBinding.getTypeFactory().createSqlType(SqlTypeName.ANY),
true);
    +    }
    +
    +    final RelDataTypeFactory factory = opBinding.getTypeFactory();
    +    final String name = opBinding.getOperator().getName().toUpperCase();
    +    if(name.equals("CONCAT")) {
    +    final RelDataType type = factory.createSqlType(SqlTypeName.VARCHAR, MAX_VARCHAR_LENGTH);
    +      if(opBinding.getOperandType(0).isNullable()) {
    +        return factory.createTypeWithNullability(type, true);
    +      } else {
    +        return type;
    +      }
    +    }
    +
    +    boolean allBooleanOutput = true;
    --- End diff --
    
    In general, that is not safe. Specifically, what if one of the ANY column turns out to
be a type which a function does not support. 
    
    For boolean, we have not choice since if this function is in WHERE-CLAUSE, Calcite forbidden
ANY type appearing over there.


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