AnkitaAdvitot commented on code in PR #19586:
URL: https://github.com/apache/pinot/pull/19586#discussion_r4546523026
##########
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ArrayLiteralTransformFunction.java:
##########
@@ -134,86 +222,226 @@ public
ArrayLiteralTransformFunction(List<ExpressionContext> literalContexts) {
_longArrayLiteral = new long[0];
_floatArrayLiteral = new float[0];
_doubleArrayLiteral = new double[0];
+ _bigDecimalArrayLiteral = new BigDecimal[0];
_stringArrayLiteral = new String[0];
_bytesArrayLiteral = new byte[0][];
return;
}
+ List<LiteralContext> contexts = new ArrayList<>(literalContexts.size());
for (ExpressionContext literalContext : literalContexts) {
- Preconditions.checkState(literalContext.getType() ==
ExpressionContext.Type.LITERAL,
- "ArrayLiteralTransformFunction only takes literals as arguments,
found: %s", literalContext);
+ contexts.add(toLiteralContext(literalContext));
}
- _dataType = literalContexts.get(0).getLiteral().getType();
+ _dataType = contexts.get(0).getType();
switch (_dataType) {
case INT:
- _intArrayLiteral = new int[literalContexts.size()];
+ _intArrayLiteral = new int[contexts.size()];
for (int i = 0; i < _intArrayLiteral.length; i++) {
- _intArrayLiteral[i] =
literalContexts.get(i).getLiteral().getIntValue();
+ _intArrayLiteral[i] = contexts.get(i).getIntValue();
}
_longArrayLiteral = null;
_floatArrayLiteral = null;
_doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
_stringArrayLiteral = null;
_bytesArrayLiteral = null;
break;
case LONG:
- _longArrayLiteral = new long[literalContexts.size()];
+ _longArrayLiteral = new long[contexts.size()];
for (int i = 0; i < _longArrayLiteral.length; i++) {
- _longArrayLiteral[i] =
literalContexts.get(i).getLiteral().getLongValue();
+ _longArrayLiteral[i] = contexts.get(i).getLongValue();
}
_intArrayLiteral = null;
_floatArrayLiteral = null;
_doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
_stringArrayLiteral = null;
_bytesArrayLiteral = null;
break;
case FLOAT:
- _floatArrayLiteral = new float[literalContexts.size()];
+ _floatArrayLiteral = new float[contexts.size()];
for (int i = 0; i < _floatArrayLiteral.length; i++) {
- _floatArrayLiteral[i] =
literalContexts.get(i).getLiteral().getFloatValue();
+ _floatArrayLiteral[i] = contexts.get(i).getFloatValue();
}
_intArrayLiteral = null;
_longArrayLiteral = null;
_doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
_stringArrayLiteral = null;
_bytesArrayLiteral = null;
break;
case DOUBLE:
- _doubleArrayLiteral = new double[literalContexts.size()];
+ _doubleArrayLiteral = new double[contexts.size()];
for (int i = 0; i < _doubleArrayLiteral.length; i++) {
- _doubleArrayLiteral[i] =
literalContexts.get(i).getLiteral().getDoubleValue();
+ _doubleArrayLiteral[i] = contexts.get(i).getDoubleValue();
}
_intArrayLiteral = null;
_longArrayLiteral = null;
_floatArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
+ _stringArrayLiteral = null;
+ _bytesArrayLiteral = null;
+ break;
+ case BIG_DECIMAL:
+ _bigDecimalArrayLiteral = new BigDecimal[contexts.size()];
+ for (int i = 0; i < _bigDecimalArrayLiteral.length; i++) {
+ _bigDecimalArrayLiteral[i] = contexts.get(i).getBigDecimalValue();
+ }
+ _intArrayLiteral = null;
+ _longArrayLiteral = null;
+ _floatArrayLiteral = null;
+ _doubleArrayLiteral = null;
+ _stringArrayLiteral = null;
+ _bytesArrayLiteral = null;
+ break;
+ case BOOLEAN:
+ _intArrayLiteral = new int[contexts.size()];
+ for (int i = 0; i < _intArrayLiteral.length; i++) {
+ _intArrayLiteral[i] = contexts.get(i).getBooleanValue() ? 1 : 0;
+ }
+ _longArrayLiteral = null;
+ _floatArrayLiteral = null;
+ _doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
+ _stringArrayLiteral = null;
+ _bytesArrayLiteral = null;
+ break;
+ case TIMESTAMP:
+ _longArrayLiteral = new long[contexts.size()];
+ for (int i = 0; i < _longArrayLiteral.length; i++) {
+ _longArrayLiteral[i] = contexts.get(i).getLongValue();
+ }
+ _intArrayLiteral = null;
+ _floatArrayLiteral = null;
+ _doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
_stringArrayLiteral = null;
_bytesArrayLiteral = null;
break;
case STRING:
- _stringArrayLiteral = new String[literalContexts.size()];
+ _stringArrayLiteral = new String[contexts.size()];
for (int i = 0; i < _stringArrayLiteral.length; i++) {
- _stringArrayLiteral[i] =
literalContexts.get(i).getLiteral().getStringValue();
+ _stringArrayLiteral[i] = contexts.get(i).getStringValue();
}
_intArrayLiteral = null;
_longArrayLiteral = null;
_floatArrayLiteral = null;
_doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
_bytesArrayLiteral = null;
break;
case BYTES:
- _bytesArrayLiteral = new byte[literalContexts.size()][];
+ case UUID:
+ _bytesArrayLiteral = new byte[contexts.size()][];
for (int i = 0; i < _bytesArrayLiteral.length; i++) {
- _bytesArrayLiteral[i] =
literalContexts.get(i).getLiteral().getBytesValue();
+ _bytesArrayLiteral[i] = contexts.get(i).getBytesValue();
}
_intArrayLiteral = null;
_longArrayLiteral = null;
_floatArrayLiteral = null;
_doubleArrayLiteral = null;
+ _bigDecimalArrayLiteral = null;
_stringArrayLiteral = null;
break;
default:
throw new IllegalStateException(
"Illegal data type for ArrayLiteralTransformFunction: " +
_dataType + ", literal contexts: "
- + Arrays.toString(literalContexts.toArray()));
+ + Arrays.toString(contexts.toArray()));
+ }
+ }
+
+ private static LiteralContext toLiteralContext(ExpressionContext context) {
+ if (context.getType() == ExpressionContext.Type.LITERAL) {
+ return context.getLiteral();
+ }
+ if (context.getType() == ExpressionContext.Type.FUNCTION) {
+ FunctionContext function = context.getFunction();
+ if (function.getFunctionName().equalsIgnoreCase("cast")) {
+ List<ExpressionContext> arguments = function.getArguments();
+ Preconditions.checkArgument(arguments.size() == 2,
+ "CAST function inside array literal constructor expects 2
arguments, got: %s", arguments.size());
+ LiteralContext sourceLiteral = toLiteralContext(arguments.get(0));
+ ExpressionContext targetTypeExpr = arguments.get(1);
+ Preconditions.checkArgument(targetTypeExpr.getType() ==
ExpressionContext.Type.LITERAL,
+ "CAST target type must be a literal string, got: %s",
targetTypeExpr);
+ String targetType =
targetTypeExpr.getLiteral().getStringValue().toUpperCase();
+ return castLiteralContext(sourceLiteral, targetType);
+ }
+ }
+ throw new IllegalStateException(
+ "ArrayLiteralTransformFunction only takes literals or cast functions
as arguments, found: " + context);
+ }
+
+ private static LiteralContext castLiteralContext(LiteralContext source,
String targetType) {
+ switch (targetType) {
Review Comment:
Addressed:
Reordered the `cast` switch branches in `ArrayLiteralTransformFunction` to
follow the standard type order: `INT`, `LONG`, `FLOAT`, `DOUBLE`,
`BIG_DECIMAL`, `BOOLEAN`, `TIMESTAMP`, `STRING`, `BYTES`, `UUID`, keeping type
aliases together with each case.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]