Jackie-Jiang commented on a change in pull request #6728:
URL: https://github.com/apache/incubator-pinot/pull/6728#discussion_r605186834



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/JsonExtractScalarTransformFunction.java
##########
@@ -84,41 +82,19 @@ public void init(@Nonnull List<TransformFunction> 
arguments, @Nonnull Map<String
     }
     _jsonFieldTransformFunction = firstArgument;
     _jsonPath = ((LiteralTransformFunction) arguments.get(1)).getLiteral();
-    _resultsType = ((LiteralTransformFunction) 
arguments.get(2)).getLiteral().toUpperCase();
-    boolean isSingleValue = !_resultsType.toUpperCase().endsWith("_ARRAY");
+    String resultsType = ((LiteralTransformFunction) 
arguments.get(2)).getLiteral().toUpperCase();
+    boolean isSingleValue = !resultsType.endsWith("_ARRAY");
     try {
-      FieldSpec.DataType fieldType = 
FieldSpec.DataType.valueOf(_resultsType.split("_ARRAY")[0]);
-
+      DataType dataType =
+          DataType.valueOf(isSingleValue ? resultsType : 
resultsType.substring(0, resultsType.length() - 6));
       if (arguments.size() == 4) {
-        String defaultValue = ((LiteralTransformFunction) 
arguments.get(3)).getLiteral();
-        switch (fieldType) {
-          case INT:
-            _defaultValue = Double.valueOf(defaultValue).intValue();
-            break;
-          case LONG:
-            _defaultValue = Double.valueOf(defaultValue).longValue();
-            break;
-          case FLOAT:
-            _defaultValue = Double.valueOf(defaultValue).floatValue();
-            break;
-          case DOUBLE:
-            _defaultValue = Double.valueOf(defaultValue);
-            break;
-          case BOOLEAN:
-          case STRING:
-            _defaultValue = defaultValue;
-            break;
-          case BYTES:
-            throw new UnsupportedOperationException(String.format(
-                "Unsupported results type: BYTES for 'jsonExtractScalar' Udf. 
Supported types are: 
INT/LONG/FLOAT/DOUBLE/STRING/INT_ARRAY/LONG/FLOAT_ARRAY/DOUBLE_ARRAY/STRING_ARRAY",
-                _resultsType));
-        }
+        _defaultValue = dataType.convert(((LiteralTransformFunction) 
arguments.get(3)).getLiteral());
       }
-      _resultMetadata = new TransformResultMetadata(fieldType, isSingleValue, 
false);
+      _resultMetadata = new TransformResultMetadata(dataType, isSingleValue, 
false);
     } catch (Exception e) {
-      throw new UnsupportedOperationException(String.format(
-          "Unsupported results type: %s for 'jsonExtractScalar' Udf. Supported 
types are: 
INT/LONG/FLOAT/DOUBLE/STRING/INT_ARRAY/LONG/FLOAT_ARRAY/DOUBLE_ARRAY/STRING_ARRAY",
-          _resultsType));
+      throw new IllegalStateException(String.format(
+          "Unsupported results type: %s for 'jsonExtractScalar' Udf. Supported 
types are: 
INT/LONG/FLOAT/DOUBLE/STRING/INT_ARRAY/LONG_ARRAY/FLOAT_ARRAY/DOUBLE_ARRAY/STRING_ARRAY",

Review comment:
       Done




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to