[
https://issues.apache.org/jira/browse/CALCITE-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14634558#comment-14634558
]
Julian Hyde commented on CALCITE-807:
-------------------------------------
The test case testEnsureTypeIgnoreNullability2 in my branch
https://github.com/julianhyde/incubator-calcite/tree/807-ensure-type, also
below, provides that this bug is invalid. But I agree that the parameter needs
to be renamed and have better documentation.
{code}
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-807">[CALCITE-807]
* RexBuilder.ensureType doesn't ensure type</a> that proves that existing
* functionality is correct. But the name of the {@code matchNullability}
* argument to {@link RexBuilder#ensureType(RelDataType, RexNode, boolean)}
* is very misleading and should be changed to {@code ignoreNullability}. */
@Test public void testEnsureTypeIgnoreNullability2() {
final RelDataType nonNullIntType =
typeFactory.createSqlType(SqlTypeName.INTEGER);
assertThat(nonNullIntType.getFullTypeString(), is("INTEGER NOT NULL"));
final RelDataType nonNullBigintType =
typeFactory.createSqlType(SqlTypeName.BIGINT);
assertThat(nonNullBigintType.getFullTypeString(), is("BIGINT NOT NULL"));
// Nullable BIGINT type
RelDataType bigintType =
typeFactory.createTypeWithNullability(nonNullBigintType, true);
assertThat(bigintType.getFullTypeString(), is("BIGINT"));
// Non nullable RexNode with integer return type
RexNode sumZeroFunction = rexBuilder.makeCall(nonNullIntType,
SqlStdOperatorTable.SUM0, ImmutableList.<RexNode>of());
assertThat(sumZeroFunction.getType().getFullTypeString(),
is("INTEGER NOT NULL"));
// Ignore nullability of target type.
// I.e. preserve the nullability of the expression,
// even though we are changing its type from INTEGER to BIGINT.
// Resulting expression has type BIGINT NOT NULL.
final boolean ignoreNullability = true;
RexNode ignore =
rexBuilder.ensureType(bigintType, sumZeroFunction, ignoreNullability);
assertThat(ignore.getType().getFullTypeString(),
is("BIGINT NOT NULL"));
// Do not ignore the nullability of target type.
// That is, honor the nullability of the target type.
// Resulting expression has type BIGINT (nulls allowed).
final boolean ignoreNullability2 = false;
RexNode honor =
rexBuilder.ensureType(bigintType, sumZeroFunction, ignoreNullability2);
assertThat(honor.getType(), is(bigintType));
assertThat(honor.getType().getFullTypeString(),
is("BIGINT"));
}
{code}
> RexBuilder.ensureType doesn't ensure type
> -----------------------------------------
>
> Key: CALCITE-807
> URL: https://issues.apache.org/jira/browse/CALCITE-807
> Project: Calcite
> Issue Type: Bug
> Reporter: Julian Hyde
> Assignee: Julian Hyde
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)