tanclary commented on code in PR #3677:
URL: https://github.com/apache/calcite/pull/3677#discussion_r1522177576
##########
core/src/main/java/org/apache/calcite/util/format/FormatModels.java:
##########
@@ -142,9 +142,7 @@ MI, literalElement(":"), SS, literalElement(" "),
map.put("%Y", YYYY);
map.put("%y", YY);
map.put("%Z", TZR);
- BIG_QUERY = create(map);
- map.clear();
Review Comment:
why get rid of this
##########
testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java:
##########
@@ -6218,6 +6218,22 @@ private static Matcher<SqlNode> isCharLiteral(String s) {
.ok("CAST(`A` AS MAP< VARCHAR MULTISET, MAP< INTEGER, INTEGER > >)");
}
+ @Test void testFormatClauseInCast() {
Review Comment:
while adding comments may as well add one here to case
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -3262,11 +3262,21 @@ private static class CastImplementor extends
AbstractRexCallImplementor {
@Override Expression implementSafe(final RexToLixTranslator translator,
final RexCall call, final List<Expression> argValueList) {
- assert call.getOperands().size() == 1;
+ assert call.operandCount() <= 2;
final RelDataType sourceType = call.getOperands().get(0).getType();
- // Short-circuit if no cast is required
RexNode arg = call.getOperands().get(0);
+ ConstantExpression formatExpr;
+ if (call.operandCount() == 2) {
Review Comment:
comment here could be good
##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -826,12 +852,31 @@ public RexNode makeAbstractCast(RelDataType type, RexNode
exp) {
* @return Call to CAST operator
*/
public RexNode makeAbstractCast(RelDataType type, RexNode exp, boolean safe)
{
- SqlOperator operator =
+ final SqlOperator operator =
safe ? SqlLibraryOperators.SAFE_CAST
: SqlStdOperatorTable.CAST;
return new RexCall(type, operator, ImmutableList.of(exp));
}
+ /**
+ * Creates a call to CAST or SAFE_CAST operator with a FORMAT clause.
+ *
+ * @param type Type to cast to
+ * @param exp Expression being cast
+ * @param safe Whether to return NULL if cast fails
+ * @param format Conversion format for target type
+ * @return Call to CAST operator
+ */
+ public RexNode makeAbstractCast(RelDataType type, RexNode exp, boolean safe,
RexLiteral format) {
Review Comment:
does this need to be nullable
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java:
##########
@@ -239,6 +245,12 @@ private static RelDataType
createTypeWithNullabilityFromExpr(RelDataTypeFactory
}
return false;
}
+
+ // Validate format argument is string type if included
Review Comment:
can this be `return <insert conditions>`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]