Search in sources :

Example 41 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 RexUtil method compatibleTypes.

/**
 * Returns whether the type of an array of expressions is compatible with a
 * struct type.
 *
 * @param exprs Array of expressions
 * @param type  Type
 * @param litmus What to do if an error is detected (there is a mismatch)
 *
 * @return Whether every expression has the same type as the corresponding
 * member of the struct type
 *
 * @see RelOptUtil#eq(String, RelDataType, String, RelDataType, org.apache.calcite.util.Litmus)
 */
public static boolean compatibleTypes(List<RexNode> exprs, RelDataType type, Litmus litmus) {
    final List<RelDataTypeField> fields = type.getFieldList();
    if (exprs.size() != fields.size()) {
        return litmus.fail("rowtype mismatches expressions");
    }
    for (int i = 0; i < fields.size(); i++) {
        final RelDataType exprType = exprs.get(i).getType();
        final RelDataType fieldType = fields.get(i).getType();
        if (!RelOptUtil.eq("type1", exprType, "type2", fieldType, litmus)) {
            return litmus.fail(null);
        }
    }
    return litmus.succeed();
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 42 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 SqlItemOperator method checkOperandTypes.

@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    final SqlNode left = callBinding.operand(0);
    final SqlNode right = callBinding.operand(1);
    if (!ARRAY_OR_MAP.checkSingleOperandType(callBinding, left, 0, throwOnFailure)) {
        return false;
    }
    final RelDataType operandType = callBinding.getOperandType(0);
    final SqlSingleOperandTypeChecker checker = getChecker(operandType);
    return checker.checkSingleOperandType(callBinding, right, 0, throwOnFailure);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) SqlSingleOperandTypeChecker(org.apache.calcite.sql.type.SqlSingleOperandTypeChecker) SqlNode(org.apache.calcite.sql.SqlNode)

Example 43 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 SqlLiteralChainOperator method inferReturnType.

// 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();
    assert typeName.allowsPrecNoScale() : "LiteralChain has impossible operand type " + typeName;
    int size = 0;
    for (RelDataType type : opBinding.collectOperandTypes()) {
        size += type.getPrecision();
        assert type.getSqlTypeName() == typeName;
    }
    return opBinding.getTypeFactory().createSqlType(typeName, size);
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 44 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 SqlMultisetQueryConstructor method checkOperandTypes.

public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    final List<RelDataType> argTypes = SqlTypeUtil.deriveAndCollectTypes(callBinding.getValidator(), callBinding.getScope(), callBinding.operands());
    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 45 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 checkOperandTypes.

/**
 * Makes sure that the number and types of arguments are allowable.
 * Operators (such as "ROW" and "AS") which do not check their arguments can
 * override this method.
 */
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    final SqlNode left = callBinding.operand(0);
    final SqlNode right = callBinding.operand(1);
    if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
        return true;
    }
    RelDataType validatedNodeType = callBinding.getValidator().getValidatedNodeType(left);
    RelDataType returnType = callBinding.getValidator().deriveType(callBinding.getScope(), right);
    if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
        if (throwOnFailure) {
            throw callBinding.newError(RESOURCE.cannotCastValue(validatedNodeType.toString(), returnType.toString()));
        }
        return false;
    }
    if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
        if (throwOnFailure) {
            // set mismatch.
            throw callBinding.newError(RESOURCE.cannotCastValue(validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
        }
        return false;
    }
    return true;
}
Also used : SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

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