Java Code Examples for org.apache.calcite.sql.SqlCallBinding#getCall()

The following examples show how to use org.apache.calcite.sql.SqlCallBinding#getCall() . 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: 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 2
Source File: SqlLikeOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  switch (callBinding.getOperandCount()) {
  case 2:
    if (!OperandTypes.STRING_SAME_SAME.checkOperandTypes(
        callBinding,
        throwOnFailure)) {
      return false;
    }
    break;
  case 3:
    if (!OperandTypes.STRING_SAME_SAME_SAME.checkOperandTypes(
        callBinding,
        throwOnFailure)) {
      return false;
    }

    // calc implementation should
    // enforce the escape character length to be 1
    break;
  default:
    throw new AssertionError("unexpected number of args to "
        + callBinding.getCall() + ": " + callBinding.getOperandCount());
  }

  return SqlTypeUtil.isCharTypeComparable(
      callBinding,
      callBinding.operands(),
      throwOnFailure);
}
 
Example 3
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * CASE and COALESCE type coercion, collect all the branches types including then
 * operands and else operands to find a common type, then cast the operands to the common type
 * when needed.
 */
public boolean caseWhenCoercion(SqlCallBinding callBinding) {
  // For sql statement like:
  // `case when ... then (a, b, c) when ... then (d, e, f) else (g, h, i)`
  // an exception throws when entering this method.
  SqlCase caseCall = (SqlCase) callBinding.getCall();
  SqlNodeList thenList = caseCall.getThenOperands();
  List<RelDataType> argTypes = new ArrayList<RelDataType>();
  for (SqlNode node : thenList) {
    argTypes.add(
        validator.deriveType(
            callBinding.getScope(), node));
  }
  SqlNode elseOp = caseCall.getElseOperand();
  RelDataType elseOpType = validator.deriveType(
      callBinding.getScope(), caseCall.getElseOperand());
  argTypes.add(elseOpType);
  // Entering this method means we have already got a wider type, recompute it here
  // just to make the interface more clear.
  RelDataType widerType = getWiderTypeFor(argTypes, true);
  if (null != widerType) {
    boolean coerced = false;
    for (int i = 0; i < thenList.size(); i++) {
      coerced = coerceColumnType(callBinding.getScope(), thenList, i, widerType) || coerced;
    }
    if (needToCast(callBinding.getScope(), elseOp, widerType)) {
      coerced = coerceOperandType(callBinding.getScope(), caseCall, 3, widerType)
          || coerced;
    }
    return coerced;
  }
  return false;
}
 
Example 4
Source File: SqlLikeOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  switch (callBinding.getOperandCount()) {
  case 2:
    if (!OperandTypes.STRING_SAME_SAME.checkOperandTypes(
        callBinding,
        throwOnFailure)) {
      return false;
    }
    break;
  case 3:
    if (!OperandTypes.STRING_SAME_SAME_SAME.checkOperandTypes(
        callBinding,
        throwOnFailure)) {
      return false;
    }

    // calc implementation should
    // enforce the escape character length to be 1
    break;
  default:
    throw new AssertionError("unexpected number of args to "
        + callBinding.getCall() + ": " + callBinding.getOperandCount());
  }

  return SqlTypeUtil.isCharTypeComparable(
      callBinding,
      callBinding.operands(),
      throwOnFailure);
}