org.apache.calcite.sql.SqlCallBinding Java Examples

The following examples show how to use org.apache.calcite.sql.SqlCallBinding. 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: AssignableOperandTypeChecker.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  // Do not use callBinding.operands(). We have not resolved to a function
  // yet, therefore we do not know the ordered parameter names.
  final List<SqlNode> operands = callBinding.getCall().getOperandList();
  for (Pair<RelDataType, SqlNode> pair : Pair.zip(paramTypes, operands)) {
    RelDataType argType =
        callBinding.getValidator().deriveType(
            callBinding.getScope(),
            pair.right);
    if (!SqlTypeUtil.canAssignFrom(pair.left, argType)) {
      if (throwOnFailure) {
        throw callBinding.newValidationSignatureError();
      } else {
        return false;
      }
    }
  }
  return true;
}
 
Example #2
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean builtinFunctionCoercion(
    SqlCallBinding binding,
    List<RelDataType> operandTypes,
    List<SqlTypeFamily> expectedFamilies) {
  assert binding.getOperandCount() == operandTypes.size();
  if (!canImplicitTypeCast(operandTypes, expectedFamilies)) {
    return false;
  }
  boolean coerced = false;
  for (int i = 0; i < operandTypes.size(); i++) {
    RelDataType implicitType = implicitCast(operandTypes.get(i), expectedFamilies.get(i));
    coerced = null != implicitType
        && operandTypes.get(i) != implicitType
        && coerceOperandType(binding.getScope(), binding.getCall(), i, implicitType)
        || coerced;
  }
  return coerced;
}
 
Example #3
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Coerces operands in binary arithmetic expressions to NUMERIC types.
 *
 * <p>For binary arithmetic operators like [+, -, *, /, %]:
 * If the operand is VARCHAR,
 * coerce it to data type of the other operand if its data type is NUMERIC;
 * If the other operand is DECIMAL,
 * coerce the STRING operand to max precision/scale DECIMAL.
 */
public boolean binaryArithmeticCoercion(SqlCallBinding binding) {
  // Assume the operator has NUMERIC family operand type checker.
  SqlOperator operator = binding.getOperator();
  SqlKind kind = operator.getKind();
  boolean coerced = false;
  // Binary operator
  if (binding.getOperandCount() == 2) {
    final RelDataType type1 = binding.getOperandType(0);
    final RelDataType type2 = binding.getOperandType(1);
    // Special case for datetime + interval or datetime - interval
    if (kind == SqlKind.PLUS || kind == SqlKind.MINUS) {
      if (SqlTypeUtil.isInterval(type1) || SqlTypeUtil.isInterval(type2)) {
        return false;
      }
    }
    // Binary arithmetic operator like: + - * / %
    if (kind.belongsTo(SqlKind.BINARY_ARITHMETIC)) {
      coerced = binaryArithmeticWithStrings(binding, type1, type2);
    }
  }
  return coerced;
}
 
Example #4
Source File: SqlMapValueConstructor.java    From Bats with Apache License 2.0 6 votes vote down vote up
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.mapRequiresTwoOrMoreArgs());
  }
  if (argTypes.size() % 2 > 0) {
    throw callBinding.newValidationError(RESOURCE.mapRequiresEvenArgCount());
  }
  final Pair<RelDataType, RelDataType> componentType =
      getComponentTypes(
          callBinding.getTypeFactory(), argTypes);
  if (null == componentType.left || null == componentType.right) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
    }
    return false;
  }
  return true;
}
 
Example #5
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 #6
Source File: SqlMultisetQueryConstructor.java    From Bats with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: SqlPosixRegexOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  int operandCount = callBinding.getOperandCount();
  if (operandCount != 2 && operandCount != 3) {
    throw new AssertionError(
        "Unexpected number of args to " + callBinding.getCall() + ": " + operandCount);
  }

  RelDataType op1Type = callBinding.getOperandType(0);
  RelDataType op2Type = callBinding.getOperandType(1);

  if (!SqlTypeUtil.isComparable(op1Type, op2Type)) {
    throw new AssertionError(
        "Incompatible first two operand types " + op1Type + " and " + op2Type);
  }

  return SqlTypeUtil.isCharTypeComparable(
      callBinding,
      callBinding.operands().subList(0, 2),
      throwOnFailure);
}
 
Example #8
Source File: TypeInferenceOperandChecker.java    From flink with Apache License 2.0 6 votes vote down vote up
private boolean checkOperandTypesOrError(SqlCallBinding callBinding, CallContext callContext) {
	final AdaptedCallContext adaptedCallContext;
	try {
		adaptedCallContext = adaptArguments(
			typeInference,
			callContext,
			null);
	} catch (ValidationException e) {
		throw createInvalidInputException(
			typeInference,
			callContext,
			e);
	}

	insertImplicitCasts(callBinding, adaptedCallContext.getArgumentDataTypes());

	return true;
}
 
Example #9
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Datetime and STRING equality: cast STRING type to datetime type, SqlToRelConverter already
 * makes the conversion but we still keep this interface overridable
 * so user can have their custom implementation.
 */
protected boolean dateTimeStringEquality(
    SqlCallBinding binding,
    RelDataType left,
    RelDataType right) {
  // REVIEW Danny 2018-05-23 we do not need to coerce type for EQUALS
  // because SqlToRelConverter already does this.
  // REVIEW Danny 2019-09-23, we should unify the coercion rules in TypeCoercion
  // instead of SqlToRelConverter.
  if (SqlTypeUtil.isCharacter(left)
      && SqlTypeUtil.isDatetime(right)) {
    return coerceOperandType(binding.getScope(), binding.getCall(), 0, right);
  }
  if (SqlTypeUtil.isCharacter(right)
      && SqlTypeUtil.isDatetime(left)) {
    return coerceOperandType(binding.getScope(), binding.getCall(), 1, left);
  }
  return false;
}
 
Example #10
Source File: SqlPositionFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  // check that the two operands are of same type.
  switch (callBinding.getOperandCount()) {
  case 2:
    return OperandTypes.SAME_SAME.checkOperandTypes(
        callBinding, throwOnFailure)
        && super.checkOperandTypes(callBinding, throwOnFailure);

  case 3:
    return OperandTypes.SAME_SAME_INTEGER.checkOperandTypes(
        callBinding, throwOnFailure)
        && super.checkOperandTypes(callBinding, throwOnFailure);
  default:
    throw new AssertionError();
  }
}
 
Example #11
Source File: SqlLiteralChainOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
private boolean argTypesValid(SqlCallBinding callBinding) {
  if (callBinding.getOperandCount() < 2) {
    return true; // nothing to compare
  }
  RelDataType firstType = null;
  for (Ord<SqlNode> operand : Ord.zip(callBinding.operands())) {
    RelDataType type =
        callBinding.getValidator().deriveType(
            callBinding.getScope(),
            operand.e);
    if (operand.i == 0) {
      firstType = type;
    } else {
      if (!SqlTypeUtil.sameNamedType(firstType, type)) {
        return false;
      }
    }
  }
  return true;
}
 
Example #12
Source File: DremioArgChecker.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
  if (checkers.size() != callBinding.getOperandCount()) {
    // assume this is an inapplicable sub-rule of a composite rule;
    // don't throw
    return false;
  }

  for (Ord<SqlNode> op : Ord.zip(callBinding.operands())) {
    if (!checkSingleOperandType(
        callBinding,
        op.e,
        op.i,
        throwOnFailure)) {
      return false;
    }
  }
  return true;
}
 
Example #13
Source File: SqlRegexpReplaceFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
  final int operandCount = callBinding.getOperandCount();
  assert operandCount >= 3;
  if (operandCount == 3) {
    return OperandTypes.STRING_STRING_STRING
        .checkOperandTypes(callBinding, throwOnFailure);
  }
  final List<SqlTypeFamily> families = new ArrayList<>();
  families.add(SqlTypeFamily.STRING);
  families.add(SqlTypeFamily.STRING);
  families.add(SqlTypeFamily.STRING);
  for (int i = 3; i < operandCount; i++) {
    if (i == 3) {
      families.add(SqlTypeFamily.INTEGER);
    }
    if (i == 4) {
      families.add(SqlTypeFamily.INTEGER);
    }
    if (i == 5) {
      families.add(SqlTypeFamily.STRING);
    }
  }
  return OperandTypes.family(families.toArray(new SqlTypeFamily[0]))
      .checkOperandTypes(callBinding, throwOnFailure);
}
 
Example #14
Source File: SqlMultisetValueConstructor.java    From calcite with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #15
Source File: OperandTypes.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkSingleOperandType(SqlCallBinding callBinding,
    SqlNode node, int iFormalOperand, boolean throwOnFailure) {
  assert 0 == iFormalOperand;
  RelDataType type =
      callBinding.getValidator().deriveType(callBinding.getScope(), node);
  boolean valid = false;
  if (type.isStruct() && type.getFieldList().size() == 2) {
    final RelDataType t0 = type.getFieldList().get(0).getType();
    final RelDataType t1 = type.getFieldList().get(1).getType();
    if (SqlTypeUtil.isDatetime(t0)) {
      if (SqlTypeUtil.isDatetime(t1)) {
        // t0 must be comparable with t1; (DATE, TIMESTAMP) is not valid
        if (SqlTypeUtil.sameNamedType(t0, t1)) {
          valid = true;
        }
      } else if (SqlTypeUtil.isInterval(t1)) {
        valid = true;
      }
    }
  }

  if (!valid && throwOnFailure) {
    throw callBinding.newValidationSignatureError();
  }
  return valid;
}
 
Example #16
Source File: ComparableOperandTypeChecker.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  boolean b = true;
  for (int i = 0; i < nOperands; ++i) {
    RelDataType type = callBinding.getOperandType(i);
    if (!checkType(callBinding, throwOnFailure, type)) {
      b = false;
      break;
    }
  }
  if (b) {
    // Coerce type first.
    if (callBinding.isTypeCoercionEnabled()) {
      TypeCoercion typeCoercion = callBinding.getValidator().getTypeCoercion();
      // For comparison operators, i.e. >, <, =, >=, <=.
      typeCoercion.binaryComparisonCoercion(callBinding);
    }
    b = super.checkOperandTypes(callBinding, false);
  }
  if (!b && throwOnFailure) {
    throw callBinding.newValidationSignatureError();
  }
  return b;
}
 
Example #17
Source File: ComparableOperandTypeChecker.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Similar functionality to
 * {@link #checkOperandTypes(SqlCallBinding, boolean)}, but not part of the
 * interface, and cannot throw an error.
 */
public boolean checkOperandTypes(
    SqlOperatorBinding operatorBinding, SqlCallBinding callBinding) {
  boolean b = true;
  for (int i = 0; i < nOperands; ++i) {
    RelDataType type = callBinding.getOperandType(i);
    if (type.getComparability().ordinal() < requiredComparability.ordinal()) {
      b = false;
      break;
    }
  }
  if (b) {
    b = super.checkOperandTypes(operatorBinding, callBinding);
  }
  return b;
}
 
Example #18
Source File: RepeatFamilyOperandTypeChecker.java    From flink with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
	SqlCallBinding callBinding,
	boolean throwOnFailure) {

	for (Ord<SqlNode> op : Ord.zip(callBinding.operands())) {
		if (!checkSingleOperandType(
			callBinding,
			op.e,
			false)) {
			// TODO: check type coercion when we support implicit type conversion
			// recheck to validate.
			for (Ord<SqlNode> op1 : Ord.zip(callBinding.operands())) {
				if (!checkSingleOperandType(
					callBinding,
					op1.e,
					throwOnFailure)) {
					return false;
				}
			}
			return false;
		}
	}
	return true;
}
 
Example #19
Source File: CompositeOperandTypeChecker.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  if (check(callBinding)) {
    return true;
  }
  if (!throwOnFailure) {
    return false;
  }
  if (composition == Composition.OR) {
    for (SqlOperandTypeChecker allowedRule : allowedRules) {
      allowedRule.checkOperandTypes(callBinding, true);
    }
  }

  // If no exception thrown, just throw a generic validation
  // signature error.
  throw callBinding.newValidationSignatureError();
}
 
Example #20
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 #21
Source File: TypeInferenceUtils.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory factory = opBinding.getTypeFactory();
  final boolean isNullable = opBinding.getOperandType(1).isNullable();

  if (!(opBinding instanceof SqlCallBinding) || !(((SqlCallBinding) opBinding).operand(0) instanceof SqlCharStringLiteral)) {
    return createCalciteTypeWithNullability(factory,
        SqlTypeName.ANY,
        isNullable);
  }

  final String part = ((SqlCharStringLiteral) ((SqlCallBinding) opBinding).operand(0))
      .getNlsString()
      .getValue()
      .toUpperCase();

  final SqlTypeName sqlTypeName = getSqlTypeNameForTimeUnit(part);
  return createCalciteTypeWithNullability(
      factory,
      sqlTypeName,
      isNullable);
}
 
Example #22
Source File: CompositeOperandTypeChecker.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  // 1. Check eagerly for binary arithmetic expressions.
  // 2. Check the comparability.
  // 3. Check if the operands have the right type.
  if (callBinding.isTypeCoercionEnabled()) {
    final TypeCoercion typeCoercion = callBinding.getValidator().getTypeCoercion();
    typeCoercion.binaryArithmeticCoercion(callBinding);
  }
  if (check(callBinding)) {
    return true;
  }
  if (!throwOnFailure) {
    return false;
  }
  if (composition == Composition.OR) {
    for (SqlOperandTypeChecker allowedRule : allowedRules) {
      allowedRule.checkOperandTypes(callBinding, true);
    }
  }

  // If no exception thrown, just throw a generic validation
  // signature error.
  throw callBinding.newValidationSignatureError();
}
 
Example #23
Source File: SqlJsonObjectFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final int count = callBinding.getOperandCount();
  for (int i = 1; i < count; i += 2) {
    RelDataType nameType = callBinding.getOperandType(i);
    if (!SqlTypeUtil.inCharFamily(nameType)) {
      if (throwOnFailure) {
        throw callBinding.newError(RESOURCE.expectedCharacter());
      }
      return false;
    }
    if (nameType.isNullable()) {
      if (throwOnFailure) {
        throw callBinding.newError(
            RESOURCE.argumentMustNotBeNull(
                callBinding.operand(i).toString()));
      }
      return false;
    }
  }
  return true;
}
 
Example #24
Source File: SqlTypeUtil.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether the operands to a call are char type-comparable.
 *
 * @param binding        Binding of call to operands
 * @param operands       Operands to check for compatibility; usually the
 *                       operands of the bound call, but not always
 * @param throwOnFailure Whether to throw an exception on failure
 * @return whether operands are valid
 */
public static boolean isCharTypeComparable(
    SqlCallBinding binding,
    List<SqlNode> operands,
    boolean throwOnFailure) {
  final SqlValidator validator = binding.getValidator();
  final SqlValidatorScope scope = binding.getScope();
  assert operands != null;
  assert operands.size() >= 2;

  if (!isCharTypeComparable(
      deriveAndCollectTypes(validator, scope, operands))) {
    if (throwOnFailure) {
      String msg = "";
      for (int i = 0; i < operands.size(); i++) {
        if (i > 0) {
          msg += ", ";
        }
        msg += operands.get(i).toString();
      }
      throw binding.newError(RESOURCE.operandNotComparable(msg));
    }
    return false;
  }
  return true;
}
 
Example #25
Source File: ComparableOperandTypeChecker.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  boolean b = true;
  for (int i = 0; i < nOperands; ++i) {
    RelDataType type = callBinding.getOperandType(i);
    if (!checkType(callBinding, throwOnFailure, type)) {
      b = false;
    }
  }
  if (b) {
    b = super.checkOperandTypes(callBinding, false);
    if (!b && throwOnFailure) {
      throw callBinding.newValidationSignatureError();
    }
  }
  return b;
}
 
Example #26
Source File: ExplicitOperandTypeChecker.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  List<SqlTypeFamily> families = new ArrayList<>();

  List<RelDataTypeField> fieldList = type.getFieldList();
  for (int i = 0; i < fieldList.size(); i++) {
    RelDataTypeField field = fieldList.get(i);
    SqlTypeName sqlTypeName = field.getType().getSqlTypeName();
    if (sqlTypeName == SqlTypeName.ROW) {
      if (field.getType().equals(callBinding.getOperandType(i))) {
        families.add(SqlTypeFamily.ANY);
      }
    } else {
      families.add(field.getType().getSqlTypeName().getFamily());
    }
  }
  return OperandTypes.family(families).checkOperandTypes(callBinding, throwOnFailure);
}
 
Example #27
Source File: SqlMultisetQueryConstructor.java    From calcite with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #28
Source File: TypeInferenceUtils.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory factory = opBinding.getTypeFactory();
  final boolean isNullable = opBinding
      .getOperandType(0)
      .isNullable();

  RelDataType ret = factory.createTypeWithNullability(
      opBinding.getOperandType(1),
      isNullable);
  if (opBinding instanceof SqlCallBinding) {
    SqlCallBinding callBinding = (SqlCallBinding) opBinding;
    SqlNode operand0 = callBinding.operand(0);

    // dynamic parameters and null constants need their types assigned
    // to them using the type they are casted to.
    if(((operand0 instanceof SqlLiteral)
        && (((SqlLiteral) operand0).getValue() == null))
            || (operand0 instanceof SqlDynamicParam)) {
      callBinding.getValidator().setValidatedNodeType(
          operand0,
          ret);
    }
  }

  return ret;
}
 
Example #29
Source File: SqlDatePartFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  // Use #checkOperandTypes instead of #checkSingleOperandType to enable implicit
  // type coercion. REVIEW Danny 2019-09-10, because we declare that the operand
  // type family is DATETIME, that means it allows arguments of type DATE, TIME
  // or TIMESTAMP, so actually we can not figure out which type we want precisely.
  // For example, the YEAR(date) function, it actually allows a DATE/TIMESTAMP operand,
  // but we declare the required operand type family to be DATETIME.
  // We just need some refactoring for the SqlDatePartFunction.
  return OperandTypes.DATETIME.checkOperandTypes(callBinding, throwOnFailure);
}
 
Example #30
Source File: SqlMultisetMemberOfOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  if (!OperandTypes.MULTISET.checkSingleOperandType(
      callBinding,
      callBinding.operand(1),
      0,
      throwOnFailure)) {
    return false;
  }

  MultisetSqlType mt =
      (MultisetSqlType) callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(1));

  RelDataType t0 =
      callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(0));
  RelDataType t1 = mt.getComponentType();

  if (t0.getFamily() != t1.getFamily()) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(
          RESOURCE.typeNotComparableNear(t0.toString(), t1.toString()));
    }
    return false;
  }
  return true;
}