Skip to content

Commit

Permalink
[CALCITE-6343] Fix AS alias operator stripping MEASUREness from measures
Browse files Browse the repository at this point in the history
When inferring the return type of an operator application, don't unwrap
MEASURE types if the operator is an AS alias.
  • Loading branch information
barrkel committed Mar 26, 2024
1 parent d5b6b5c commit 8bdf2ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/java/org/apache/calcite/sql/SqlOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ public RelDataType inferReturnType(
}

// MEASURE wrapper should be removed, e.g. MEASURE<DOUBLE> should just be DOUBLE
if (isMeasure(returnType) && returnType.getMeasureElementType() != null) {
if (opBinding.getOperator().kind != SqlKind.AS
&& isMeasure(returnType)
&& returnType.getMeasureElementType() != null) {
returnType = Objects.requireNonNull(returnType.getMeasureElementType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ static class Fixture extends SqlTypeFixture {
assertThat(dataType, is(innerType));
}

@Test void testAsOperatorReturnTypeInferenceDoesNotRemoveMeasure() {
final SqlTypeFactoryImpl f = new Fixture().typeFactory;
RelDataType innerType = f.createSqlType(SqlTypeName.DOUBLE);
RelDataType measureType = f.createMeasureType(innerType);
RelDataType dataType = SqlStdOperatorTable.AS.inferReturnType(f,
Lists.newArrayList(measureType));
assertThat(dataType, is(measureType));
}

@Test void testCustomDecimalPlusReturnTypeInference() {
final SqlTypeFactoryImpl f = new Fixture().customTypeFactory;
RelDataType operand1 = f.createSqlType(SqlTypeName.DECIMAL, 38, 10);
Expand Down

0 comments on commit 8bdf2ec

Please sign in to comment.