org.apache.calcite.sql.SqlOperatorBinding

Here are the examples of the java api org.apache.calcite.sql.SqlOperatorBinding taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

57 Examples 7

19 Source : SameOperandTypeChecker.java
with Apache License 2.0
from lealone

/**
 * Similar functionality to
 * {@link #checkOperandTypes(SqlCallBinding, boolean)}, but not part of the
 * interface, and cannot throw an error.
 */
public boolean checkOperandTypes(SqlOperatorBinding operatorBinding) {
    return checkOperandTypesImpl(operatorBinding, false, null);
}

19 Source : SqlCaseOperator.java
with Apache License 2.0
from lealone

public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    // REVIEW jvs 4-June-2005:  can't these be unified?
    if (!(opBinding instanceof SqlCallBinding)) {
        return inferTypeFromOperands(opBinding.getTypeFactory(), opBinding.collectOperandTypes());
    }
    return inferTypeFromValidator((SqlCallBinding) opBinding);
}

19 Source : SqlBetweenOperator.java
with Apache License 2.0
from lealone

public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    SqlCallBinding callBinding = (SqlCallBinding) opBinding;
    ExplicitOperatorBinding newOpBinding = new ExplicitOperatorBinding(opBinding, collectOperandTypes(callBinding.getValidator(), callBinding.getScope(), callBinding.getCall()));
    return ReturnTypes.BOOLEAN_NULLABLE.inferReturnType(newOpBinding);
}

18 Source : GenericTemplateFunction.java
with BSD 2-Clause "Simplified" License
from linkedin

@Override
public RelDataType inferReturnType(final SqlOperatorBinding opBinding) {
    return genericDataType;
}

18 Source : GenericProjectFunction.java
with BSD 2-Clause "Simplified" License
from linkedin

@Override
public RelDataType inferReturnType(final SqlOperatorBinding opBinding) {
    return tableDataType;
}

18 Source : SqlTypeTransformCascade.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    RelDataType ret = rule.inferReturnType(opBinding);
    if (ret == null) {
        // inferReturnType may return null; transformType does not accept or
        // return null types
        return null;
    }
    for (SqlTypeTransform transform : transforms) {
        ret = transform.transformType(opBinding, ret);
    }
    return ret;
}

18 Source : SqlReturnTypeInferenceChain.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    for (SqlReturnTypeInference rule : rules) {
        RelDataType ret = rule.inferReturnType(opBinding);
        if (ret != null) {
            return ret;
        }
    }
    return null;
}

18 Source : OrdinalReturnTypeInference.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    return opBinding.getOperandType(ordinal);
}

18 Source : ExplicitReturnTypeInference.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    return protoType.apply(opBinding.getTypeFactory());
}

18 Source : CursorReturnTypeInference.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    return opBinding.getCursorOperand(ordinal);
}

18 Source : SqlSubstringFunction.java
with Apache License 2.0
from lealone

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    // SUBSTRING(x FROM 0 FOR constant) has same monotonicity as x
    if (call.getOperandCount() == 3) {
        final SqlMonotonicity mono0 = call.getOperandMonotonicity(0);
        if ((mono0 != SqlMonotonicity.NOT_MONOTONIC) && call.getOperandMonotonicity(1) == SqlMonotonicity.CONSTANT && call.getOperandLiteralValue(1, BigDecimal.clreplaced).equals(BigDecimal.ZERO) && call.getOperandMonotonicity(2) == SqlMonotonicity.CONSTANT) {
            return mono0.unstrict();
        }
    }
    return super.getMonotonicity(call);
}

18 Source : SqlRowOperator.java
with Apache License 2.0
from lealone

public RelDataType inferReturnType(final SqlOperatorBinding opBinding) {
    // The type of a ROW(e1,e2) expression is a record with the types
    // {e1type,e2type}.  According to the standard, field names are
    // implementation-defined.
    return opBinding.getTypeFactory().createStructType(new AbstractList<Map.Entry<String, RelDataType>>() {

        public Map.Entry<String, RelDataType> get(int index) {
            return Pair.of(SqlUtil.deriveAliasFromOrdinal(index), opBinding.getOperandType(index));
        }

        public int size() {
            return opBinding.getOperandCount();
        }
    });
}

18 Source : SqlMultisetValueConstructor.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    RelDataType type = getComponentType(opBinding.getTypeFactory(), opBinding.collectOperandTypes());
    if (null == type) {
        return null;
    }
    return SqlTypeUtil.createMultisetType(opBinding.getTypeFactory(), type, false);
}

18 Source : SqlJsonValueFunction.java
with Apache License 2.0
from lealone

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    replacedert opBinding.getOperandCount() == 5 || opBinding.getOperandCount() == 6;
    RelDataType ret;
    if (opBinding.getOperandCount() == 6) {
        ret = opBinding.getOperandType(5);
    } else {
        ret = opBinding.getTypeFactory().createSqlType(SqlTypeName.ANY);
    }
    return opBinding.getTypeFactory().createTypeWithNullability(ret, true);
}

18 Source : SqlBaseContextVariable.java
with Apache License 2.0
from lealone

// All of the string constants are monotonic.
@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return SqlMonotonicity.CONSTANT;
}

17 Source : DrillSqlOperatorWithoutInference.java
with Apache License 2.0
from zpochen

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    return getNullableReturnDataType(opBinding.getTypeFactory());
}

17 Source : DrillCalciteSqlOperatorWrapper.java
with Apache License 2.0
from zpochen

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return operator.getMonotonicity(call);
}

17 Source : MatchReturnTypeInference.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    for (int i = start; i < opBinding.getOperandCount(); i++) {
        RelDataType argType = opBinding.getOperandType(i);
        if (SqlTypeUtil.isOfSameTypeName(typeNames, argType)) {
            return argType;
        }
    }
    return null;
}

17 Source : ComparableOperandTypeChecker.java
with Apache License 2.0
from lealone

/**
 * Similar functionality to
 * {@link #checkOperandTypes(SqlCallBinding, boolean)}, but not part of the
 * interface, and cannot throw an error.
 */
public boolean checkOperandTypes(SqlOperatorBinding callBinding) {
    boolean b = true;
    for (int i = 0; i < nOperands; ++i) {
        RelDataType type = callBinding.getOperandType(i);
        if (type.getComparability().ordinal() < requiredComparability.ordinal()) {
            b = false;
        }
    }
    if (b) {
        b = super.checkOperandTypes(callBinding);
    }
    return b;
}

17 Source : SqlMonotonicUnaryFunction.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return call.getOperandMonotonicity(0).unstrict();
}

17 Source : SqlLiteralChainOperator.java
with Apache License 2.0
from lealone

// Result type is the same as all the args, but its size is the
// total size.
// REVIEW mb 8/8/04: Possibly this can be achieved by combining
// the strategy useFirstArgType with a new transformer.
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    // Here we know all the operands have the same type,
    // which has a size (precision), but not a scale.
    RelDataType ret = opBinding.getOperandType(0);
    SqlTypeName typeName = ret.getSqlTypeName();
    replacedert typeName.allowsPrecNoScale() : "LiteralChain has impossible operand type " + typeName;
    int size = 0;
    for (RelDataType type : opBinding.collectOperandTypes()) {
        size += type.getPrecision();
        replacedert type.getSqlTypeName() == typeName;
    }
    return opBinding.getTypeFactory().createSqlType(typeName, size);
}

17 Source : SqlFloorFunction.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    // Monotonic iff its first argument is, but not strict.
    return call.getOperandMonotonicity(0).unstrict();
}

17 Source : SqlDatetimeSubtractionOperator.java
with Apache License 2.0
from lealone

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return SqlStdOperatorTable.MINUS.getMonotonicity(call);
}

17 Source : SqlDatetimePlusOperator.java
with Apache License 2.0
from lealone

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return SqlStdOperatorTable.PLUS.getMonotonicity(call);
}

17 Source : SqlCurrentDateFunction.java
with Apache License 2.0
from lealone

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return SqlMonotonicity.INCREASING;
}

17 Source : SqlAbstractTimeFunction.java
with Apache License 2.0
from lealone

// All of the time functions are increasing. Not strictly increasing.
@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    return SqlMonotonicity.INCREASING;
}

16 Source : HiveNamedStructFunction.java
with BSD 2-Clause "Simplified" License
from linkedin

@Override
public RelDataType inferReturnType(final SqlOperatorBinding opBinding) {
    checkState(opBinding instanceof SqlCallBinding);
    final SqlCallBinding callBinding = (SqlCallBinding) opBinding;
    return opBinding.getTypeFactory().createStructType(new AbstractList<Map.Entry<String, RelDataType>>() {

        @Override
        public int size() {
            return opBinding.getOperandCount() / 2;
        }

        @Override
        public Map.Entry<String, RelDataType> get(int index) {
            String fieldName = callBinding.operand(2 * index).toString();
            // strip quotes
            String fieldNameNoQuotes = fieldName.substring(1, fieldName.length() - 1);
            // Comparable colName = opBinding.getOperandLiteralValue(2 * index);
            return Pair.of(fieldNameNoQuotes, opBinding.getOperandType(2 * index + 1));
        }
    });
}

16 Source : HiveGenericUDFReturnTypeInference.java
with BSD 2-Clause "Simplified" License
from linkedin

@Override
public RelDataType inferReturnType(SqlOperatorBinding sqlOperatorBinding) {
    int operandCount = sqlOperatorBinding.getOperandCount();
    ObjectInspector[] inputObjectInspectors = new ObjectInspector[operandCount];
    for (int i = 0; i < sqlOperatorBinding.getOperandCount(); i++) {
        inputObjectInspectors[i] = getObjectInspector(sqlOperatorBinding.getOperandType(i));
    }
    try {
        Clreplaced dynamicallyLoadedUdfClreplaced = getDynamicallyLoadedUdfClreplaced();
        return getRelDataType((ObjectInspector) dynamicallyLoadedUdfClreplaced.getMethod("initialize", getDynamicallyLoadedObjectInspectorArrayClreplaced()).invoke(dynamicallyLoadedUdfClreplaced.newInstance(), getDynamicallyLoadedObjectInspectors(inputObjectInspectors)), sqlOperatorBinding.getTypeFactory());
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Unable to find org.apache.hadoop.hive.ql.udf.generic.GenericUDF.initialize() on: " + _udfClreplacedName, e);
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException("Unable to instantiate a new instance of " + _udfClreplacedName, e);
    } catch (InvocationTargetException | IllegalArgumentException e) {
        throw new RuntimeException("Unable to call org.apache.hadoop.hive.ql.udf.generic.GenericUDF.initialize() on: " + _udfClreplacedName, e);
    } catch (ClreplacedNotFoundException e) {
        throw new RuntimeException("Could not load clreplaced  " + _udfClreplacedName, e);
    }
}

16 Source : SqlCastFunction.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    replacedert opBinding.getOperandCount() == 2;
    RelDataType ret = opBinding.getOperandType(1);
    RelDataType firstType = opBinding.getOperandType(0);
    ret = opBinding.getTypeFactory().createTypeWithNullability(ret, firstType.isNullable());
    if (opBinding instanceof SqlCallBinding) {
        SqlCallBinding callBinding = (SqlCallBinding) opBinding;
        SqlNode operand0 = callBinding.operand(0);
        // dynamic parameters and null constants need their types replacedigned
        // to them using the type they are casted to.
        if (((operand0 instanceof SqlLiteral) && (((SqlLiteral) operand0).getValue() == null)) || (operand0 instanceof SqlDynamicParam)) {
            final SqlValidatorImpl validator = (SqlValidatorImpl) callBinding.getValidator();
            validator.setValidatedNodeType(operand0, ret);
        }
    }
    return ret;
}

15 Source : SqlExtractFunction.java
with Apache License 2.0
from lealone

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    switch(call.getOperandLiteralValue(0, TimeUnitRange.clreplaced)) {
        case YEAR:
            return call.getOperandMonotonicity(1).unstrict();
        default:
            return SqlMonotonicity.NOT_MONOTONIC;
    }
}

15 Source : SqlCastFunction.java
with Apache License 2.0
from lealone

@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    RelDataTypeFamily castFrom = call.getOperandType(0).getFamily();
    RelDataTypeFamily castTo = call.getOperandType(1).getFamily();
    if (castFrom instanceof SqlTypeFamily && castTo instanceof SqlTypeFamily && nonMonotonicCasts.containsEntry(castFrom, castTo)) {
        return SqlMonotonicity.NOT_MONOTONIC;
    } else {
        return call.getOperandMonotonicity(0);
    }
}

14 Source : ScalarFunctionImpl.java
with GNU General Public License v3.0
from MyCATApache

public RelDataType getReturnType(RelDataTypeFactory typeFactory, SqlOperatorBinding opBinding) {
    // Strict and semi-strict functions can return null even if their Java
    // functions return a primitive type. Because when one of their arguments
    // is null, they won't even be called.
    final RelDataType returnType = getReturnType(typeFactory);
    switch(getNullPolicy(method)) {
        case STRICT:
            for (RelDataType type : opBinding.collectOperandTypes()) {
                if (type.isNullable()) {
                    return typeFactory.createTypeWithNullability(returnType, true);
                }
            }
            break;
        case SEMI_STRICT:
            return typeFactory.createTypeWithNullability(returnType, true);
    }
    return returnType;
}

14 Source : PrestoElementAtFunction.java
with BSD 2-Clause "Simplified" License
from linkedin

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
    final RelDataType operandType = opBinding.getOperandType(0);
    switch(operandType.getSqlTypeName()) {
        case ARRAY:
            return typeFactory.createTypeWithNullability(operandType.getComponentType(), true);
        case MAP:
            return typeFactory.createTypeWithNullability(operandType.getValueType(), true);
        case ANY:
        case DYNAMIC_STAR:
            return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.ANY), true);
        default:
            throw new replacedertionError();
    }
}

14 Source : SameOperandTypeExceptFirstOperandChecker.java
with BSD 2-Clause "Simplified" License
from linkedin

protected boolean checkOperandTypesImpl(SqlOperatorBinding opBinding, boolean throwOnFailure, SqlCallBinding callBinding) {
    int actualOperands = nOperands;
    if (actualOperands == -1) {
        actualOperands = opBinding.getOperandCount();
    }
    Preconditions.checkState(!(throwOnFailure && callBinding == null));
    RelDataType[] types = new RelDataType[actualOperands];
    final List<Integer> operandList = getOperandList(opBinding.getOperandCount());
    for (Integer i : operandList) {
        types[i] = opBinding.getOperandType(i);
    }
    if (!types[0].getSqlTypeName().equals(firstOperandTypeName)) {
        return handleError(callBinding, throwOnFailure);
    }
    // skip 0th operand from this check
    for (int i = 2; i < operandList.size(); i++) {
        if (!SqlTypeUtil.isComparable(types[i], types[i - 1])) {
            handleError(callBinding, throwOnFailure);
        }
    }
    return true;
}

14 Source : SqlDotOperator.java
with Apache License 2.0
from lealone

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
    final RelDataType recordType = opBinding.getOperandType(0);
    switch(recordType.getSqlTypeName()) {
        case ROW:
            final String fieldName = opBinding.getOperandLiteralValue(1, String.clreplaced);
            final RelDataType type = opBinding.getOperandType(0).getField(fieldName, false, false).getType();
            if (recordType.isNullable()) {
                return typeFactory.createTypeWithNullability(type, true);
            } else {
                return type;
            }
        default:
            throw new replacedertionError();
    }
}

14 Source : SqlArrayValueConstructor.java
with Apache License 2.0
from lealone

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    RelDataType type = getComponentType(opBinding.getTypeFactory(), opBinding.collectOperandTypes());
    if (null == type) {
        return null;
    }
    return SqlTypeUtil.createArrayType(opBinding.getTypeFactory(), type, false);
}

14 Source : TypeInferenceUtils.java
with Apache License 2.0
from lealone

private static DrillFuncHolder resolveDrillFuncHolder(final SqlOperatorBinding opBinding, final List<DrillFuncHolder> functions, FunctionCall functionCall) {
    final FunctionResolver functionResolver = FunctionResolverFactory.getResolver(functionCall);
    final DrillFuncHolder func = functionResolver.getBestMatch(functions, functionCall);
    // Throw an exception
    // if no DrillFuncHolder matched for the given list of operand types
    if (func == null) {
        StringBuilder operandTypes = new StringBuilder();
        for (int i = 0; i < opBinding.getOperandCount(); ++i) {
            operandTypes.append(opBinding.getOperandType(i).getSqlTypeName());
            if (i < opBinding.getOperandCount() - 1) {
                operandTypes.append(",");
            }
        }
        throw UserException.functionError().message(String.format("%s does not support operand types (%s)", opBinding.getOperator().getName(), operandTypes.toString())).build(logger);
    }
    return func;
}

13 Source : HiveUDFOperatorWithoutInference.java
with Apache License 2.0
from zpochen

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    RelDataTypeFactory factory = opBinding.getTypeFactory();
    return factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.ANY), true);
}

13 Source : SameOperandTypeChecker.java
with Apache License 2.0
from lealone

protected boolean checkOperandTypesImpl(SqlOperatorBinding operatorBinding, boolean throwOnFailure, SqlCallBinding callBinding) {
    int nOperandsActual = nOperands;
    if (nOperandsActual == -1) {
        nOperandsActual = operatorBinding.getOperandCount();
    }
    replacedert !(throwOnFailure && (callBinding == null));
    RelDataType[] types = new RelDataType[nOperandsActual];
    final List<Integer> operandList = getOperandList(operatorBinding.getOperandCount());
    for (int i : operandList) {
        types[i] = operatorBinding.getOperandType(i);
    }
    int prev = -1;
    for (int i : operandList) {
        if (prev >= 0) {
            if (!SqlTypeUtil.isComparable(types[i], types[prev])) {
                if (!throwOnFailure) {
                    return false;
                }
                // REVIEW jvs 5-June-2005: Why don't we use
                // newValidationSignatureError() here?  It gives more
                // specific diagnostics.
                throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
            }
        }
        prev = i;
    }
    return true;
}

13 Source : TypeInferenceUtils.java
with Apache License 2.0
from lealone

/**
 * Given a SqlOperatorBinding, convert it to FunctionCall
 * @param  opBinding    the given SqlOperatorBinding
 * @return FunctionCall the converted FunctionCall
 */
public static FunctionCall convertSqlOperatorBindingToFunctionCall(final SqlOperatorBinding opBinding) {
    final List<LogicalExpression> args = Lists.newArrayList();
    for (int i = 0; i < opBinding.getOperandCount(); ++i) {
        final RelDataType type = opBinding.getOperandType(i);
        final TypeProtos.MinorType minorType = getDrillTypeFromCalciteType(type);
        TypeProtos.DataMode dataMode = type.isNullable() ? TypeProtos.DataMode.OPTIONAL : TypeProtos.DataMode.REQUIRED;
        TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder().setMode(dataMode).setMinorType(minorType);
        if (Types.isDecimalType(minorType)) {
            builder.setScale(type.getScale()).setPrecision(type.getPrecision());
        }
        args.add(new MajorTypeInLogicalExpression(builder.build()));
    }
    final String drillFuncName = FunctionCallFactory.replaceOpWithFuncName(opBinding.getOperator().getName());
    return new FunctionCall(drillFuncName, args, ExpressionPosition.UNKNOWN);
}

12 Source : TypeInferenceUtils.java
with Apache License 2.0
from zpochen

private static DrillFuncHolder resolveDrillFuncHolder(final SqlOperatorBinding opBinding, final List<DrillFuncHolder> functions) {
    final FunctionCall functionCall = convertSqlOperatorBindingToFunctionCall(opBinding);
    final FunctionResolver functionResolver = FunctionResolverFactory.getResolver(functionCall);
    final DrillFuncHolder func = functionResolver.getBestMatch(functions, functionCall);
    // Throw an exception
    // if no DrillFuncHolder matched for the given list of operand types
    if (func == null) {
        String operandTypes = "";
        for (int i = 0; i < opBinding.getOperandCount(); ++i) {
            operandTypes += opBinding.getOperandType(i).getSqlTypeName();
            if (i < opBinding.getOperandCount() - 1) {
                operandTypes += ",";
            }
        }
        throw UserException.functionError().message(String.format("%s does not support operand types (%s)", opBinding.getOperator().getName(), operandTypes)).build(logger);
    }
    return func;
}

12 Source : SqlMapValueConstructor.java
with Apache License 2.0
from lealone

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    Pair<RelDataType, RelDataType> type = getComponentTypes(opBinding.getTypeFactory(), opBinding.collectOperandTypes());
    if (null == type) {
        return null;
    }
    return SqlTypeUtil.createMapType(opBinding.getTypeFactory(), type.left, type.right, false);
}

12 Source : NumericOrDefaultReturnTypeInference.java
with Apache License 2.0
from flink-tpc-ds

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    int nOperands = opBinding.getOperandCount();
    List<RelDataType> types = new ArrayList<>();
    for (int i = startTypeIdx; i < nOperands; i++) {
        RelDataType type = opBinding.getOperandType(i);
        if (SqlTypeUtil.isNumeric(type)) {
            types.add(type);
        } else {
            return opBinding.getOperandType(defaultTypeIdx);
        }
    }
    return opBinding.getTypeFactory().leastRestrictive(types);
}

12 Source : TypeInferenceUtils.java
with Apache License 2.0
from dremio

private static AbstractFunctionHolder resolveFunctionHolder(final SqlOperatorBinding opBinding, final List<AbstractFunctionHolder> functions, boolean isDecimalV2On) {
    final FunctionCall functionCall = convertSqlOperatorBindingToFunctionCall(opBinding);
    final FunctionResolver functionResolver = FunctionResolverFactory.getResolver(functionCall);
    final AbstractFunctionHolder func = functionResolver.getBestMatch(functions, functionCall);
    // Throw an exception
    // if no BaseFunctionHolder matched for the given list of operand types
    if (func == null) {
        String operandTypes = "";
        for (int i = 0; i < opBinding.getOperandCount(); ++i) {
            operandTypes += opBinding.getOperandType(i).getSqlTypeName();
            if (i < opBinding.getOperandCount() - 1) {
                operandTypes += ",";
            }
        }
        throw UserException.functionError().message(String.format("%s does not support operand types (%s)", opBinding.getOperator().getName(), operandTypes)).build(logger);
    }
    return func;
}

11 Source : HiveExplodeOperator.java
with BSD 2-Clause "Simplified" License
from linkedin

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    RelDataType operandType = opBinding.getOperandType(0);
    final RelDataTypeFactory.Builder builder = opBinding.getTypeFactory().builder();
    if (operandType instanceof ArraySqlType) {
        builder.add(SqlUtil.deriveAliasFromOrdinal(0), operandType.getComponentType());
    } else {
        // map type
        builder.add(MAP_KEY_COLUMN_NAME, operandType.getKeyType());
        builder.add(MAP_VALUE_COLUMN_NAME, operandType.getValueType());
    }
    return builder.build();
}

11 Source : SqlMonotonicBinaryOperator.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
@Override
public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
    final SqlMonotonicity mono0 = call.getOperandMonotonicity(0);
    final SqlMonotonicity mono1 = call.getOperandMonotonicity(1);
    // constant <op> constant --> constant
    if ((mono1 == SqlMonotonicity.CONSTANT) && (mono0 == SqlMonotonicity.CONSTANT)) {
        return SqlMonotonicity.CONSTANT;
    }
    // monotonic <op> constant
    if (mono1 == SqlMonotonicity.CONSTANT) {
        // mono0 + constant --> mono0
        // mono0 - constant --> mono0
        if (getName().equals("-") || getName().equals("+")) {
            return mono0;
        }
        replacedert getName().equals("*");
        BigDecimal value = call.getOperandLiteralValue(1, BigDecimal.clreplaced);
        switch(value == null ? 1 : value.signum()) {
            case -1:
                // mono0 * negative constant --> reverse mono0
                return mono0.reverse();
            case 0:
                // mono0 * 0 --> constant (zero)
                return SqlMonotonicity.CONSTANT;
            default:
                // mono0 * positive constant --> mono0
                return mono0;
        }
    }
    // constant <op> mono
    if (mono0 == SqlMonotonicity.CONSTANT) {
        if (getName().equals("-")) {
            // constant - mono1 --> reverse mono1
            return mono1.reverse();
        }
        if (getName().equals("+")) {
            // constant + mono1 --> mono1
            return mono1;
        }
        replacedert getName().equals("*");
        if (!call.isOperandNull(0, true)) {
            BigDecimal value = call.getOperandLiteralValue(0, BigDecimal.clreplaced);
            switch(value == null ? 1 : value.signum()) {
                case -1:
                    // negative constant * mono1 --> reverse mono1
                    return mono1.reverse();
                case 0:
                    // 0 * mono1 --> constant (zero)
                    return SqlMonotonicity.CONSTANT;
                default:
                    // positive constant * mono1 --> mono1
                    return mono1;
            }
        }
    }
    // strictly asc + strictly asc --> strictly asc
    // e.g. 2 * orderid + 3 * orderid
    // is strictly increasing if orderid is strictly increasing
    // asc + asc --> asc
    // e.g. 2 * orderid + 3 * orderid
    // is increasing if orderid is increasing
    // asc + desc --> not monotonic
    // e.g. 2 * orderid + (-3 * orderid) is not monotonic
    if (getName().equals("+")) {
        if (mono0 == mono1) {
            return mono0;
        } else if (mono0.unstrict() == mono1.unstrict()) {
            return mono0.unstrict();
        } else {
            return SqlMonotonicity.NOT_MONOTONIC;
        }
    }
    if (getName().equals("-")) {
        if (mono0 == mono1.reverse()) {
            return mono0;
        } else if (mono0.unstrict() == mono1.reverse().unstrict()) {
            return mono0.unstrict();
        } else {
            return SqlMonotonicity.NOT_MONOTONIC;
        }
    }
    if (getName().equals("*")) {
        return SqlMonotonicity.NOT_MONOTONIC;
    }
    return super.getMonotonicity(call);
}

11 Source : SqlDatetimePlusOperator.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
    final RelDataType leftType = opBinding.getOperandType(0);
    final IntervalSqlType unitType = (IntervalSqlType) opBinding.getOperandType(1);
    final TimeUnit timeUnit = unitType.getIntervalQualifier().getStartUnit();
    return SqlTimestampAddFunction.deduceType(typeFactory, timeUnit, unitType, leftType);
}

11 Source : SqlAbstractTimeFunction.java
with Apache License 2.0
from lealone

public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    // REVIEW jvs 20-Feb-2005: Need to take care of time zones.
    int precision = 0;
    if (opBinding.getOperandCount() == 1) {
        RelDataType type = opBinding.getOperandType(0);
        if (SqlTypeUtil.isNumeric(type)) {
            precision = opBinding.getOperandLiteralValue(0, Integer.clreplaced);
        }
    }
    replacedert precision >= 0;
    if (precision > SqlTypeName.MAX_DATETIME_PRECISION) {
        throw opBinding.newError(RESOURCE.argumentMustBeValidPrecision(opBinding.getOperator().getName(), 0, SqlTypeName.MAX_DATETIME_PRECISION));
    }
    return opBinding.getTypeFactory().createSqlType(typeName, precision);
}

11 Source : HiveSqlCastFunction.java
with Apache License 2.0
from 51nb

@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    replacedert opBinding.getOperandCount() == 2;
    RelDataType ret = opBinding.getOperandType(1);
    ret = opBinding.getTypeFactory().createTypeWithNullability(ret, true);
    if (opBinding instanceof SqlCallBinding) {
        SqlCallBinding callBinding = (SqlCallBinding) opBinding;
        SqlNode operand0 = callBinding.operand(0);
        // dynamic parameters and null constants need their types replacedigned
        // to them using the type they are casted to.
        if (((operand0 instanceof SqlLiteral) && (((SqlLiteral) operand0).getValue() == null)) || (operand0 instanceof SqlDynamicParam)) {
            final SqlValidatorImpl validator = (SqlValidatorImpl) callBinding.getValidator();
            validator.setValidatedNodeType(operand0, ret);
        }
    }
    return ret;
}

10 Source : TypeInferenceUtils.java
with Apache License 2.0
from zpochen

/**
 * Given a SqlOperatorBinding, convert it to FunctionCall
 * @param  opBinding    the given SqlOperatorBinding
 * @return FunctionCall the converted FunctionCall
 */
public static FunctionCall convertSqlOperatorBindingToFunctionCall(final SqlOperatorBinding opBinding) {
    final List<LogicalExpression> args = Lists.newArrayList();
    for (int i = 0; i < opBinding.getOperandCount(); ++i) {
        final RelDataType type = opBinding.getOperandType(i);
        final TypeProtos.MinorType minorType = getDrillTypeFromCalciteType(type);
        final TypeProtos.MajorType majorType;
        if (type.isNullable()) {
            majorType = Types.optional(minorType);
        } else {
            majorType = Types.required(minorType);
        }
        args.add(new MajorTypeInLogicalExpression(majorType));
    }
    final String drillFuncName = FunctionCallFactory.replaceOpWithFuncName(opBinding.getOperator().getName());
    final FunctionCall functionCall = new FunctionCall(drillFuncName, args, ExpressionPosition.UNKNOWN);
    return functionCall;
}

See More Examples