Java Code Examples for org.apache.calcite.sql.type.SqlSingleOperandTypeChecker#checkSingleOperandType()

The following examples show how to use org.apache.calcite.sql.type.SqlSingleOperandTypeChecker#checkSingleOperandType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlDotOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
@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);
  return checker.checkSingleOperandType(callBinding, right, 0,
      throwOnFailure);
}
 
Example 2
Source File: SqlDotOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
@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);
  // Actually operand0 always comes from parsing the SqlIdentifier, so there
  // is no need to make implicit type coercion.
  return checker.checkSingleOperandType(callBinding, right, 0,
      throwOnFailure);
}
 
Example 3
Source File: SqlItemOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: SqlOverlapsOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: SqlItemOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: SqlOverlapsOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
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;
}