61yao commented on code in PR #10380:
URL: https://github.com/apache/pinot/pull/10380#discussion_r1129938572


##########
pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CaseTransformFunctionTest.java:
##########
@@ -90,51 +88,53 @@ public void testCasePriorityObserved(String column, int 
threshold1, int threshol
   }
 
   @Test
-  public void testCaseTransformFunctionWithIntResults() {
-    int[] expectedIntResults = new int[NUM_ROWS];
-    Arrays.fill(expectedIntResults, 100);
-    testCaseQueryWithIntResults("true", expectedIntResults);
-    Arrays.fill(expectedIntResults, 10);
-    testCaseQueryWithIntResults("false", expectedIntResults);
+  public void testCaseTransformFunctionWithLongResults() {
+    long[] expectedLongResults = new long[NUM_ROWS];
+    Arrays.fill(expectedLongResults, 100);
+    testCaseQueryWithLongResults("true", expectedLongResults);
+    Arrays.fill(expectedLongResults, 10);
+    testCaseQueryWithLongResults("false", expectedLongResults);
 
     for (TransformFunctionType functionType : 
BINARY_OPERATOR_TRANSFORM_FUNCTIONS) {
-      testCaseQueryWithIntResults(String.format("%s(%s, %s)", 
functionType.getName(), INT_SV_COLUMN,
-          String.format("%d", _intSVValues[INDEX_TO_COMPARE])), 
getExpectedIntResults(INT_SV_COLUMN, functionType));
-      testCaseQueryWithIntResults(String.format("%s(%s, %s)", 
functionType.getName(), LONG_SV_COLUMN,
-          String.format("%d", _longSVValues[INDEX_TO_COMPARE])), 
getExpectedIntResults(LONG_SV_COLUMN, functionType));
-      testCaseQueryWithIntResults(String.format("%s(%s, %s)", 
functionType.getName(), FLOAT_SV_COLUMN,
-          String.format("%f", _floatSVValues[INDEX_TO_COMPARE])), 
getExpectedIntResults(FLOAT_SV_COLUMN, functionType));
-      testCaseQueryWithIntResults(String.format("%s(%s, %s)", 
functionType.getName(), DOUBLE_SV_COLUMN,
+      testCaseQueryWithLongResults(String.format("%s(%s, %s)", 
functionType.getName(), INT_SV_COLUMN,
+          String.format("%d", _intSVValues[INDEX_TO_COMPARE])), 
getExpectedLongResults(INT_SV_COLUMN, functionType));
+      testCaseQueryWithLongResults(String.format("%s(%s, %s)", 
functionType.getName(), LONG_SV_COLUMN,
+          String.format("%d", _longSVValues[INDEX_TO_COMPARE])), 
getExpectedLongResults(LONG_SV_COLUMN, functionType));
+      testCaseQueryWithLongResults(String.format("%s(%s, %s)", 
functionType.getName(), FLOAT_SV_COLUMN,
+              String.format("%f", _floatSVValues[INDEX_TO_COMPARE])),
+          getExpectedLongResults(FLOAT_SV_COLUMN, functionType));
+      testCaseQueryWithLongResults(String.format("%s(%s, %s)", 
functionType.getName(), DOUBLE_SV_COLUMN,
               String.format("%.20f", _doubleSVValues[INDEX_TO_COMPARE])),
-          getExpectedIntResults(DOUBLE_SV_COLUMN, functionType));
-      testCaseQueryWithIntResults(String.format("%s(%s, %s)", 
functionType.getName(), STRING_SV_COLUMN,
+          getExpectedLongResults(DOUBLE_SV_COLUMN, functionType));
+      testCaseQueryWithLongResults(String.format("%s(%s, %s)", 
functionType.getName(), STRING_SV_COLUMN,
               String.format("'%s'", _stringSVValues[INDEX_TO_COMPARE])),
-          getExpectedIntResults(STRING_SV_COLUMN, functionType));
+          getExpectedLongResults(STRING_SV_COLUMN, functionType));
     }
   }
 
   @Test
   public void testCaseTransformFunctionWithFloatResults() {

Review Comment:
   done



##########
pinot-core/src/test/java/org/apache/pinot/common/request/context/LiteralContextTest.java:
##########
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.request.context;
+
+import java.math.BigDecimal;
+import org.apache.pinot.common.request.Literal;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class LiteralContextTest {
+  @Test
+  public void testNullLiteralContext() {
+    // Create literal context from thrift
+    Literal literal = new Literal();
+    literal.setNullValue(true);
+    LiteralContext nullContext1 = new LiteralContext(literal);
+    Assert.assertEquals(nullContext1.getValue(), null);
+    Assert.assertEquals(nullContext1.toString(), "'null'");
+    Assert.assertEquals(nullContext1.getBigDecimalValue(), BigDecimal.ZERO);
+    // Create literal context from object and type
+    LiteralContext nullContext2 = new 
LiteralContext(FieldSpec.DataType.UNKNOWN, null);
+    Assert.assertEquals(nullContext2.getValue(), null);
+    Assert.assertEquals(nullContext2.toString(), "'null'");
+    Assert.assertEquals(nullContext2.getBigDecimalValue(), BigDecimal.ZERO);
+    // Check different literal objects are equal and have same hash code.
+    Assert.assertTrue(nullContext1.equals(nullContext2));
+    Assert.assertTrue(nullContext1.hashCode() == nullContext2.hashCode());
+  }
+
+  @Test
+  public void testInferDataType(){
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("abc").getLeft(),
 FieldSpec.DataType.STRING);
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("123").getLeft(),
 FieldSpec.DataType.STRING);
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("2147483649").getLeft(),
 FieldSpec.DataType.STRING);
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("1.2").getLeft(),
 FieldSpec.DataType.STRING);
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("41241241.2412").getLeft(),
+        FieldSpec.DataType.STRING);
+    // Only big decimal is allowed to pass in as string for numerical type.
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("1.7976931348623159e+308").getLeft(),
+        FieldSpec.DataType.BIG_DECIMAL);
+    
Assert.assertEquals(LiteralContext.inferLiteralDataTypeAndValue("2020-02-02 
20:20:20.20").getLeft(),
+        FieldSpec.DataType.TIMESTAMP);
+  }
+}

Review Comment:
   done



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -115,10 +171,7 @@ public boolean equals(Object o) {
 
   @Override
   public String toString() {
-    if (_value == null) {
-      return "null";
-    }
     // TODO: print out the type.
-    return '\'' + _value.toString() + '\'';
+    return '\'' + String.valueOf(_value) + '\'';
   }
-}
+}

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.

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