KKcorps commented on code in PR #10386:
URL: https://github.com/apache/pinot/pull/10386#discussion_r1139952560


##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -37,68 +45,116 @@ public class LiteralContext {
   private FieldSpec.DataType _type;
   private Object _value;
 
-  // TODO: Support all data types.
-  private static FieldSpec.DataType 
convertThriftTypeToDataType(Literal._Fields fields) {
-    switch (fields) {
-      case LONG_VALUE:
-        return FieldSpec.DataType.LONG;
-      case BOOL_VALUE:
-        return FieldSpec.DataType.BOOLEAN;
-      case DOUBLE_VALUE:
-        return FieldSpec.DataType.DOUBLE;
-      case STRING_VALUE:
-        return FieldSpec.DataType.STRING;
+  private BigDecimal _bigDecimalValue;
+
+  private static BigDecimal getBigDecimalValue(FieldSpec.DataType type, Object 
value) {
+    switch (type){
+      case BIG_DECIMAL:
+        return (BigDecimal) value;
+      case BOOLEAN:
+        return PinotDataType.BOOLEAN.toBigDecimal(value);
+      case TIMESTAMP:
+        return 
PinotDataType.TIMESTAMP.toBigDecimal(Timestamp.valueOf(value.toString()));
       default:
-        throw new UnsupportedOperationException("Unsupported literal type:" + 
fields);
+        if(type.isNumeric()){
+          return new BigDecimal(value.toString());
+        }
+        return BigDecimal.ZERO;
     }
   }
 
-  private static Class<?> convertDataTypeToJavaType(FieldSpec.DataType 
dataType) {
-    switch (dataType) {
-      case INT:
-        return Integer.class;
-      case LONG:
-        return Long.class;
-      case BOOLEAN:
-        return Boolean.class;
-      case FLOAT:
-        return Float.class;
-      case DOUBLE:
-        return Double.class;
-      case STRING:
-        return String.class;
-      default:
-        throw new UnsupportedOperationException("Unsupported dataType:" + 
dataType);
+  @VisibleForTesting
+  static Pair<FieldSpec.DataType, Object> inferLiteralDataTypeAndValue(String 
literal) {
+    // Try to interpret the literal as number
+    try {
+      Number number = NumberUtils.createNumber(literal);
+      if  (number instanceof BigDecimal || number instanceof BigInteger) {
+        return ImmutablePair.of(FieldSpec.DataType.BIG_DECIMAL, new 
BigDecimal(literal));
+      } else {
+        return ImmutablePair.of(FieldSpec.DataType.STRING, literal);

Review Comment:
   Is there need for this since we are already returning STRING at the end of 
the method?



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

Reply via email to