Skip to content

Commit

Permalink
Cleaned up return type detection
Browse files Browse the repository at this point in the history
* It now uses the precision for integer types
  • Loading branch information
normanj-bitquill committed Sep 10, 2024
1 parent eaf996b commit ab839e3
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public static SqlCall stripSeparator(SqlCall call) {
if (SqlTypeName.INT_TYPES.contains(opType.getSqlTypeName())) {
if (integerReturnType == null) {
integerReturnType = opType;
} else if (isIntegerTypeLarger(integerReturnType, opType)) {
} else if (integerReturnType.getPrecision() < opType.getPrecision()) {
integerReturnType = opType;
}
} else {
Expand All @@ -646,26 +646,6 @@ public static SqlCall stripSeparator(SqlCall call) {
typeFactory.createSqlType(SqlTypeName.INTEGER), true);
};

/**
* Returns true if type2 is of a larger integer type than type1.
*
* @param type1 first type
* @param type2 second type
* @return true if type2 is of a larger integer type than type1
*/
private static boolean isIntegerTypeLarger(RelDataType type1, RelDataType type2) {
if (SqlTypeName.TINYINT == type1.getSqlTypeName()) {
return SqlTypeName.TINYINT != type2.getSqlTypeName();
} else if (SqlTypeName.SMALLINT == type1.getSqlTypeName()) {
return SqlTypeName.TINYINT != type2.getSqlTypeName()
&& SqlTypeName.SMALLINT != type2.getSqlTypeName();
} else if (SqlTypeName.INTEGER == type1.getSqlTypeName()) {
return SqlTypeName.BIGINT == type2.getSqlTypeName();
} else {
return false;
}
}

/**
* Returns the same type as the multiset carries. The multiset type returned
* is the least restrictive of the call's multiset operands
Expand Down

0 comments on commit ab839e3

Please sign in to comment.