[
https://issues.apache.org/jira/browse/CALCITE-5183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17551198#comment-17551198
]
Steven Talbot commented on CALCITE-5183:
----------------------------------------
^^ regardless of the ergonomics of that interval creation API for the
RelBuilder, it doesn't work here.
(in Kotlin)
{code:java}
val literal = relBuilder.literal(1)
relBuilder.values(listOf(listOf(literal)),
relBuilder.typeFactory.createStructType(listOf(literal.type), listOf("n")))
val intervalQualifier = SqlIntervalQualifier(TimeUnit.DAY, null,
SqlParserPos.ZERO)
val intervalLiteral =
relBuilder.rexBuilder.makeIntervalLiteral(intervalQualifier)
relBuilder.call(SqlStdOperatorTable.INTERVAL, relBuilder.field(0),
intervalLiteral){code}
produces
{noformat}
cannot convert SYMBOL literal to class
org.apache.calcite.sql.SqlIntervalQualifier
java.lang.AssertionError: cannot convert SYMBOL literal to class
org.apache.calcite.sql.SqlIntervalQualifier
at org.apache.calcite.rex.RexLiteral.getValueAs(RexLiteral.java:1143)
at
org.apache.calcite.rex.RexCallBinding.getOperandLiteralValue(RexCallBinding.java:100)
at
org.apache.calcite.sql.validate.SqlNonNullableAccessors.getOperandLiteralValueOrThrow(SqlNonNullableAccessors.java:108)
at
org.apache.calcite.sql.fun.SqlIntervalOperator.returnType(SqlIntervalOperator.java:59)
at
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:58)
at org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:537)
at org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:290)
at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:689)
at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:667){noformat}
(the call to makeLiteral without a number for the interval basically produces
the same thing as RexBuilder.makeFlag(TimeUnit))
OR, even if you try to fake the "number" for the interval qualifier, it still
doesn't work
{code:java}
val literal = relBuilder.literal(1)
relBuilder.values(listOf(listOf(literal)),
relBuilder.typeFactory.createStructType(listOf(literal.type), listOf("n")))
val intervalQualifier = SqlIntervalQualifier(TimeUnit.DAY, null,
SqlParserPos.ZERO)
val ignored = BigDecimal(13)
val intervalLiteral = relBuilder.rexBuilder.makeIntervalLiteral(ignored,
intervalQualifier)
relBuilder.call(SqlStdOperatorTable.INTERVAL, relBuilder.field(0),
intervalLiteral){code}
produces
{noformat}
cannot convert INTERVAL_DAY literal to class
org.apache.calcite.sql.SqlIntervalQualifier
java.lang.AssertionError: cannot convert INTERVAL_DAY literal to class
org.apache.calcite.sql.SqlIntervalQualifier
at org.apache.calcite.rex.RexLiteral.getValueAs(RexLiteral.java:1143)
at
org.apache.calcite.rex.RexCallBinding.getOperandLiteralValue(RexCallBinding.java:100)
at
org.apache.calcite.sql.validate.SqlNonNullableAccessors.getOperandLiteralValueOrThrow(SqlNonNullableAccessors.java:108)
at
org.apache.calcite.sql.fun.SqlIntervalOperator.returnType(SqlIntervalOperator.java:59)
at
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:58)
at org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:537)
at org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:290)
at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:689)
at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:667){noformat}
> Impossible condition in return type inference for SqlIntervalOperator?
> ----------------------------------------------------------------------
>
> Key: CALCITE-5183
> URL: https://issues.apache.org/jira/browse/CALCITE-5183
> Project: Calcite
> Issue Type: Bug
> Reporter: Steven Talbot
> Priority: Major
>
> I could be wrong here, but I don't see how to make this work, and I don't see
> any tests for it being used on the relBuilder side of the fence (where the
> "impossible" type inference is invoked for me).
>
> [https://github.com/apache/calcite/commit/03c76a7d2b896042ab417ddc36f1849f874ad3dd#diff-f6836cabfabc14be277e9f7406ab38996aaa45bac86969cecd64189c2fd7c745R57]
> requires the second argument to the Interval call to be literal wrapper
> around a SqlIntervalQualifier. In the context of RexCallBinding, I don't
> believe this is possible, since the argument has to be a RexLiteral, and
> RexLiteral exposes no way to directly wrap a value as a SqlIntervalQualifier
> like this. Again, this is where my reading of the code gets uncertain, but
> neither signature of RexBuilder.makeIntervalLiteral will give you what you
> want, and I don't see any way this could be possible.
>
> This issue means that there seems to be no way to use
> `SqlStdOperatorTable.INTERVAL` with RelBuilder.call.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)