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

The following examples show how to use org.apache.calcite.sql.type.SqlTypeUtil#equalSansNullability() . 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: RexSimplify.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RexNode simplifyPreservingType(RexNode e, RexUnknownAs unknownAs,
    boolean matchNullability) {
  final RexNode e2 = simplifyUnknownAs(e, unknownAs);
  if (e2.getType() == e.getType()) {
    return e2;
  }
  if (!matchNullability
      && SqlTypeUtil.equalSansNullability(rexBuilder.typeFactory, e2.getType(), e.getType())) {
    return e2;
  }
  final RexNode e3 = rexBuilder.makeCast(e.getType(), e2, matchNullability);
  if (e3.equals(e)) {
    return e;
  }
  return e3;
}
 
Example 2
Source File: RexUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Returns whether an expression is a cast just for the purposes of
 * nullability, not changing any other aspect of the type. */
public static boolean isNullabilityCast(RelDataTypeFactory typeFactory, RexNode node) {
    switch (node.getKind()) {
    case CAST:
        final RexCall call = (RexCall) node;
        final RexNode arg0 = call.getOperands().get(0);
        return SqlTypeUtil.equalSansNullability(typeFactory, arg0.getType(), call.getType());
    }
    return false;
}
 
Example 3
Source File: RexUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns whether an expression is a cast just for the purposes of
 * nullability, not changing any other aspect of the type. */
public static boolean isNullabilityCast(RelDataTypeFactory typeFactory,
    RexNode node) {
  switch (node.getKind()) {
  case CAST:
    final RexCall call = (RexCall) node;
    final RexNode arg0 = call.getOperands().get(0);
    return SqlTypeUtil.equalSansNullability(typeFactory, arg0.getType(),
        call.getType());
  }
  return false;
}
 
Example 4
Source File: RexSimplify.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * Return if the new type is the same and at most narrows the nullability.
 */
private boolean sameTypeOrNarrowsNullability(RelDataType oldType, RelDataType newType) {
    return oldType.equals(newType)
            || (SqlTypeUtil.equalSansNullability(rexBuilder.typeFactory, oldType, newType) && oldType.isNullable());
}
 
Example 5
Source File: RexSimplify.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Return if the new type is the same and at most narrows the nullability.
 */
private boolean sameTypeOrNarrowsNullability(RelDataType oldType, RelDataType newType) {
  return oldType.equals(newType)
      || (SqlTypeUtil.equalSansNullability(rexBuilder.typeFactory, oldType, newType)
          && oldType.isNullable());
}