Search in sources :

Example 46 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.

the class SqlCastFunction method inferReturnType.

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    assert 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);
        // 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;
}
Also used : SqlValidatorImpl(org.apache.calcite.sql.validate.SqlValidatorImpl) SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlNode(org.apache.calcite.sql.SqlNode)

Example 47 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.

the class SqlMultisetValueConstructor method checkOperandTypes.

public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    final List<RelDataType> argTypes = SqlTypeUtil.deriveAndCollectTypes(callBinding.getValidator(), callBinding.getScope(), callBinding.operands());
    if (argTypes.size() == 0) {
        throw callBinding.newValidationError(RESOURCE.requireAtLeastOneArg());
    }
    final RelDataType componentType = getComponentType(callBinding.getTypeFactory(), argTypes);
    if (null == componentType) {
        if (throwOnFailure) {
            throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
        }
        return false;
    }
    return true;
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 48 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.

the class SqlOverlapsOperator method checkOperandTypes.

public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    if (!OperandTypes.PERIOD.checkSingleOperandType(callBinding, callBinding.operand(0), 0, throwOnFailure)) {
        return false;
    }
    final SqlSingleOperandTypeChecker rightChecker;
    switch(kind) {
        case CONTAINS:
            rightChecker = OperandTypes.PERIOD_OR_DATETIME;
            break;
        default:
            rightChecker = OperandTypes.PERIOD;
            break;
    }
    if (!rightChecker.checkSingleOperandType(callBinding, callBinding.operand(1), 0, throwOnFailure)) {
        return false;
    }
    final RelDataType t0 = callBinding.getOperandType(0);
    final RelDataType t1 = callBinding.getOperandType(1);
    if (!SqlTypeUtil.isDatetime(t1)) {
        final RelDataType t00 = t0.getFieldList().get(0).getType();
        final RelDataType t10 = t1.getFieldList().get(0).getType();
        if (!SqlTypeUtil.sameNamedType(t00, t10)) {
            if (throwOnFailure) {
                throw callBinding.newValidationSignatureError();
            }
            return false;
        }
    }
    return true;
}
Also used : SqlSingleOperandTypeChecker(org.apache.calcite.sql.type.SqlSingleOperandTypeChecker) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 49 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.

the class SqlDatetimePlusOperator method inferReturnType.

// ~ 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);
    switch(unitType.getIntervalQualifier().getStartUnit()) {
        case HOUR:
        case MINUTE:
        case SECOND:
        case MILLISECOND:
        case MICROSECOND:
            return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP), leftType.isNullable() || unitType.isNullable());
        default:
            return leftType;
    }
}
Also used : IntervalSqlType(org.apache.calcite.sql.type.IntervalSqlType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 50 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.

the class SqlDotOperator method deriveType.

@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
    RelDataType nodeType = validator.deriveType(scope, call.getOperandList().get(0));
    assert nodeType != null;
    final String fieldName = call.getOperandList().get(1).toString();
    RelDataTypeField field = nodeType.getField(fieldName, false, false);
    if (field == null) {
        throw SqlUtil.newContextException(SqlParserPos.ZERO, Static.RESOURCE.unknownField(fieldName));
    }
    RelDataType type = field.getType();
    // Validate and determine coercibility and resulting collation
    // name of binary operator if needed.
    type = adjustType(validator, call, type);
    SqlValidatorUtil.checkCharsetAndCollateConsistentIfCharType(type);
    return type;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelDataType (org.apache.calcite.rel.type.RelDataType)834 RexNode (org.apache.calcite.rex.RexNode)268 ArrayList (java.util.ArrayList)214 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)209 RelNode (org.apache.calcite.rel.RelNode)153 SqlNode (org.apache.calcite.sql.SqlNode)143 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)123 RexBuilder (org.apache.calcite.rex.RexBuilder)118 Test (org.junit.Test)62 ImmutableList (com.google.common.collect.ImmutableList)58 RexInputRef (org.apache.calcite.rex.RexInputRef)57 List (java.util.List)51 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)45 RexLiteral (org.apache.calcite.rex.RexLiteral)44 SqlNodeList (org.apache.calcite.sql.SqlNodeList)42 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)40 AggregateCall (org.apache.calcite.rel.core.AggregateCall)39 BitString (org.apache.calcite.util.BitString)38 BigDecimal (java.math.BigDecimal)35 RelBuilder (org.apache.calcite.tools.RelBuilder)34