Java Code Examples for org.apache.calcite.sql.type.SqlTypeUtil#deriveAndCollectTypes()

The following examples show how to use org.apache.calcite.sql.type.SqlTypeUtil#deriveAndCollectTypes() . 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: 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 2
Source File: SqlMultisetValueConstructor.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.requireAtLeastOneArg());
  }
  final RelDataType componentType =
      getComponentType(
          callBinding.getTypeFactory(),
          argTypes);
  if (null == componentType) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
    }
    return false;
  }
  return true;
}
 
Example 3
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 4
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 5
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 6
Source File: SqlMapValueConstructor.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.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 7
Source File: SqlBetweenOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
private List<RelDataType> collectOperandTypes(
    SqlValidator validator,
    SqlValidatorScope scope,
    SqlCall call) {
  List<RelDataType> argTypes =
      SqlTypeUtil.deriveAndCollectTypes(
          validator, scope, call.getOperandList());
  return ImmutableNullableList.of(
      argTypes.get(VALUE_OPERAND),
      argTypes.get(LOWER_OPERAND),
      argTypes.get(UPPER_OPERAND));
}