Search in sources :

Example 1 with SqlSingleOperandTypeChecker

use of org.apache.calcite.sql.type.SqlSingleOperandTypeChecker 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 2 with SqlSingleOperandTypeChecker

use of org.apache.calcite.sql.type.SqlSingleOperandTypeChecker 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 3 with SqlSingleOperandTypeChecker

use of org.apache.calcite.sql.type.SqlSingleOperandTypeChecker in project flink by apache.

the class SqlDotOperator method checkOperandTypes.

@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    final SqlNode left = callBinding.operand(0);
    final SqlNode right = callBinding.operand(1);
    final RelDataType type = callBinding.getValidator().deriveType(callBinding.getScope(), left);
    if (type.getSqlTypeName() != SqlTypeName.ROW) {
        return false;
    } else if (type.getSqlIdentifier().isStar()) {
        return false;
    }
    final RelDataType operandType = callBinding.getOperandType(0);
    final SqlSingleOperandTypeChecker checker = getChecker(operandType);
    // is no need to make implicit type coercion.
    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 4 with SqlSingleOperandTypeChecker

use of org.apache.calcite.sql.type.SqlSingleOperandTypeChecker in project flink 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 SqlSingleOperandTypeChecker checker = getChecker(callBinding);
    return checker.checkSingleOperandType(callBinding, right, 0, throwOnFailure);
}
Also used : SqlSingleOperandTypeChecker(org.apache.calcite.sql.type.SqlSingleOperandTypeChecker) SqlNode(org.apache.calcite.sql.SqlNode)

Example 5 with SqlSingleOperandTypeChecker

use of org.apache.calcite.sql.type.SqlSingleOperandTypeChecker in project calcite by apache.

the class SqlDotOperator method checkOperandTypes.

@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    final SqlNode left = callBinding.operand(0);
    final SqlNode right = callBinding.operand(1);
    final RelDataType type = callBinding.getValidator().deriveType(callBinding.getScope(), left);
    if (type.getSqlTypeName() != SqlTypeName.ROW) {
        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)

Aggregations

SqlSingleOperandTypeChecker (org.apache.calcite.sql.type.SqlSingleOperandTypeChecker)5 RelDataType (org.apache.calcite.rel.type.RelDataType)4 SqlNode (org.apache.calcite.sql.SqlNode)4