Skip to content

Commit 459ec2c

Browse files
committed
Cast tzArg to VARCHAR in DATETIME 2-arg column path
Calcite infers CHAR(N) from a literal's length, but the convert_tz yaml binds tz operands as unbounded `string` (VARCHAR). Without the cast, a user-supplied tz literal like `'+05:30'` lowers as `convert_tz(precision_timestamp, char<6>, char<6>)` — same CHAR-vs-string mismatch already fixed for the synthesised target tz literal, just from the other side. Cast the source tz to VARCHAR for symmetry; the literal target was already cast. Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
1 parent a9570fd commit 459ec2c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • sandbox/plugins/analytics-backend-datafusion/src/main/java/org/opensearch/be/datafusion

sandbox/plugins/analytics-backend-datafusion/src/main/java/org/opensearch/be/datafusion/DateTimeAdapters.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ private RexNode adaptTwoArg(RexCall original, RelOptCluster cluster) {
243243
strippedValue = value;
244244
}
245245
RexNode asTimestamp = rexBuilder.makeCall(original.getType(), LOCAL_TO_TIMESTAMP_OP, List.of(strippedValue));
246-
// makeLiteral(String) infers CHAR(N) from the literal's length; the convert_tz yaml
247-
// binds the 2nd/3rd operands as `string` (unbounded VARCHAR), so a CHAR(6) "+00:00"
248-
// would fail isthmus signature lookup (`convert_tz(precision_timestamp, char<6>, string)`).
246+
// convert_tz yaml binds tz operands as unbounded `string`; cast both away from CHAR(N).
249247
RelDataType varchar = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR);
248+
RexNode tzArgVarchar = SqlTypeName.CHAR_TYPES.contains(tzArg.getType().getSqlTypeName())
249+
? rexBuilder.makeCast(varchar, tzArg, true)
250+
: tzArg;
250251
RexNode toTz = rexBuilder.makeLiteral("+00:00", varchar, true);
251-
return rexBuilder.makeCall(original.getType(), ConvertTzAdapter.LOCAL_CONVERT_TZ_OP, List.of(asTimestamp, tzArg, toTz));
252+
return rexBuilder.makeCall(original.getType(), ConvertTzAdapter.LOCAL_CONVERT_TZ_OP, List.of(asTimestamp, tzArgVarchar, toTz));
252253
}
253254

254255
/** Plan-time fold of DATETIME(value-literal, tz-literal). Returns a typed TIMESTAMP literal or NULL on invalid input. */

0 commit comments

Comments
 (0)