walterddr commented on code in PR #11763:
URL: https://github.com/apache/pinot/pull/11763#discussion_r1352797541


##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/BooleanUtils.java:
##########
@@ -64,6 +64,13 @@ public static int toInt(String booleanString) {
     return toBoolean(booleanString) ? INTERNAL_TRUE : INTERNAL_FALSE;
   }
 
+  /**
+   * Returns the int value (1 for true, 0 for false) for the given boolean 
value.
+   */
+  public static int toInt(boolean booleanValue) {

Review Comment:
   is this used? this and the one above should be used by `toBoolean(Object 
booleanObject)` right?



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -18,179 +18,231 @@
  */
 package org.apache.pinot.common.request.context;
 
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import java.math.BigDecimal;
-import java.math.BigInteger;
 import java.sql.Timestamp;
 import java.util.Objects;
 import javax.annotation.Nullable;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.Pair;
 import org.apache.pinot.common.request.Literal;
 import org.apache.pinot.common.utils.PinotDataType;
-import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
 import org.apache.pinot.spi.utils.BigDecimalUtils;
+import org.apache.pinot.spi.utils.CommonConstants.NullValuePlaceHolder;
 
 
 /**
  * The {@code LiteralContext} class represents a literal in the query.
  * <p>This includes both value and type information. We translate thrift 
literal to this representation in server.
- * Currently, only Boolean literal is correctly encoded in thrift and passed 
in.
- * All integers are encoded as LONG in thrift, and the other numerical types 
are encoded as DOUBLE.
- * The remaining types are encoded as STRING.
  */
 public class LiteralContext {
   // TODO: Support all of the types for sql.
-  private final FieldSpec.DataType _type;
+  private final DataType _type;
   private final Object _value;
-  private final 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:
-        if (type.isNumeric()) {
-          return new BigDecimal(value.toString());
-        }
-        return BigDecimal.ZERO;
-    }
-  }
+  /**
+   * A transient field used for the type conversion, and is not included in 
{@link #equals} and {@link #hashCode}.
+   */
+  private final transient PinotDataType _pinotDataType;
 
-  @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);
-      }
-    } catch (Exception e) {
-      // Ignored
-    }
+  private Boolean _booleanValue;

Review Comment:
   these are used as cached/buffers right? (e.g. caching parsing when it 
happened the first time) --> shouldn't these fields be transient? :-P



##########
pinot-common/src/main/java/org/apache/pinot/common/utils/http/HttpClient.java:
##########
@@ -493,9 +493,13 @@ private static String getErrorMessage(HttpUriRequest 
request, CloseableHttpRespo
     String reason;
     try {
       String entityStr = EntityUtils.toString(response.getEntity());
-      reason = JsonUtils.stringToObject(entityStr, 
SimpleHttpErrorInfo.class).getError();
+      try {
+        reason = JsonUtils.stringToObject(entityStr, 
SimpleHttpErrorInfo.class).getError();
+      } catch (Exception e) {
+        reason = entityStr;
+      }

Review Comment:
   is this relevant?



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/GeoSpatialTest.java:
##########
@@ -304,11 +304,11 @@ public void testStPointFunctionWithV2(boolean 
useMultiStageQueryEngine)
     {
       String query =
           String.format("Select "
-                  + "ST_Point(a.st_x, a.st_y, -1), "
+                  + "ST_Point(a.st_x, a.st_y, 0), "

Review Comment:
   instead of changing it we should add one more for -1 to make sure the 
results is actually considered as true 



##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactory.java:
##########
@@ -111,8 +111,8 @@ public static AggregationFunction 
getAggregationFunction(FunctionContext functio
         } else if (numArguments == 2) {
           // Double arguments percentile (e.g. percentile(foo, 99), 
percentileTDigest(bar, 95), etc.) where the
           // second argument is a decimal number from 0.0 to 100.0.
-          // Have to use literal string because we need to cast int to double 
here.
-          double percentile = 
parsePercentileToDouble(arguments.get(1).getLiteral().getStringValue());
+          double percentile = arguments.get(1).getLiteral().getDoubleValue();

Review Comment:
   i dont really think `.` can be added in function name `percentile99.5(col)` 
is not valid. (https://www.postgresql.org/docs/current/xfunc-sql.html)



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java:
##########
@@ -255,7 +255,8 @@ private static List<Expression> 
computeInOperands(List<Object[]> dataContainer,
         }
         Arrays.sort(arrFloat);
         for (int rowIdx = 0; rowIdx < numRows; rowIdx++) {
-          expressions.add(RequestUtils.getLiteralExpression(arrFloat[rowIdx]));
+          // TODO: Create float literal when it is supported
+          
expressions.add(RequestUtils.getLiteralExpression(Double.parseDouble(Float.toString(arrFloat[rowIdx]))));

Review Comment:
   is this even needed? we should handle it in RequestUtils 
   - AFAIK the arrFloat[rowIdx] will point to the double signature, 
   - once uncomment the TODO it will use the float signature?



##########
pinot-core/src/main/java/org/apache/pinot/core/geospatial/transform/function/StPointFunction.java:
##########
@@ -65,7 +65,7 @@ public void init(List<TransformFunction> arguments, 
Map<String, ColumnContext> c
     if (arguments.size() == 3) {
       transformFunction = arguments.get(2);
       Preconditions.checkArgument(transformFunction instanceof 
LiteralTransformFunction,
-          "Third argument must be a literal of integer: %s", getName());
+          "Third argument must be a literal of boolean: %s", getName());

Review Comment:
   ST_POINT is ANY on 3rd argument, should it be boolean or integer?



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -18,179 +18,231 @@
  */
 package org.apache.pinot.common.request.context;
 
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import java.math.BigDecimal;
-import java.math.BigInteger;
 import java.sql.Timestamp;
 import java.util.Objects;
 import javax.annotation.Nullable;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.Pair;
 import org.apache.pinot.common.request.Literal;
 import org.apache.pinot.common.utils.PinotDataType;
-import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
 import org.apache.pinot.spi.utils.BigDecimalUtils;
+import org.apache.pinot.spi.utils.CommonConstants.NullValuePlaceHolder;
 
 
 /**
  * The {@code LiteralContext} class represents a literal in the query.
  * <p>This includes both value and type information. We translate thrift 
literal to this representation in server.
- * Currently, only Boolean literal is correctly encoded in thrift and passed 
in.
- * All integers are encoded as LONG in thrift, and the other numerical types 
are encoded as DOUBLE.
- * The remaining types are encoded as STRING.
  */
 public class LiteralContext {
   // TODO: Support all of the types for sql.
-  private final FieldSpec.DataType _type;
+  private final DataType _type;
   private final Object _value;
-  private final 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:
-        if (type.isNumeric()) {
-          return new BigDecimal(value.toString());
-        }
-        return BigDecimal.ZERO;
-    }
-  }
+  /**
+   * A transient field used for the type conversion, and is not included in 
{@link #equals} and {@link #hashCode}.
+   */
+  private final transient PinotDataType _pinotDataType;

Review Comment:
   the field is not used in equals and hashCode. do we need to declare this 
transient?
   
   `_type` is final. that means `_pinotDataType = getPinotDataType(_type)` is 
also final right? any chance we will change it?



##########
pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java:
##########
@@ -116,15 +116,22 @@ public static Expression getLiteralExpression(SqlLiteral 
node) {
     Expression expression = new Expression(ExpressionType.LITERAL);
     Literal literal = new Literal();
     if (node instanceof SqlNumericLiteral) {
-      // TODO: support different integer and floating point type.
-      // Mitigate calcite NPE bug, we need to check if 
SqlNumericLiteral.getScale() is null before calling
-      // SqlNumericLiteral.isInteger(). TODO: Undo this fix once a Calcite 
release that contains CALCITE-4199 is
-      // available and Pinot has been upgraded to use such a release.
+      BigDecimal bigDecimalValue = node.bigDecimalValue();
+      assert bigDecimalValue != null;
       SqlNumericLiteral sqlNumericLiteral = (SqlNumericLiteral) node;
-      if (sqlNumericLiteral.getScale() != null && 
sqlNumericLiteral.isInteger()) {
-        literal.setLongValue(node.bigDecimalValue().longValue());
+      if (sqlNumericLiteral.isExact() && sqlNumericLiteral.isInteger()) {

Review Comment:
   ```
   if (sqlNumericLiteral.isExact()) {
     if (sqlNumericLiteral.isInteger()) {
       // long/int
     } else {
       // float/double
     }
   } else {
     // TODO support exact decimal
     // decimal
   }
   ```
   



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to