Jackie-Jiang commented on code in PR #18872:
URL: https://github.com/apache/pinot/pull/18872#discussion_r3668253042


##########
pinot-common/src/main/java/org/apache/pinot/common/function/FunctionUtils.java:
##########
@@ -184,6 +189,8 @@ public static RelDataType getRelDataType(RelDataTypeFactory 
typeFactory, Class<?
       case STRING:
       case JSON:
         return typeFactory.createSqlType(SqlTypeName.VARCHAR);
+      case UUID:

Review Comment:
   Move it below BYTES



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -140,8 +141,11 @@ public LiteralContext(Literal literal) {
   @VisibleForTesting
   public LiteralContext(DataType type, @Nullable Object value) {
     _type = type;
-    _value = value;
-    _pinotDataType = getPinotDataType(type, value);
+    // UUID values flow through the type system as java.util.UUID (canonical 
form). Normalize string/byte inputs here
+    // so getStringValue() renders canonical lowercase and getBytesValue() 
(PinotDataType.UUID.toBytes casts to UUID)
+    // does not throw.
+    _value = (type == DataType.UUID && value != null) ? 
UuidUtils.toUUID(value) : value;

Review Comment:
   The value conversion shouldn't flow into this class. Here the value should 
already be the canonical format



##########
pinot-core/src/main/java/org/apache/pinot/core/common/DataFetcher.java:
##########
@@ -416,6 +422,23 @@ void readBigDecimalValues(int[] docIds, int length, 
BigDecimal[] valueBuffer) {
     void readStringValues(int[] docIds, int length, String[] valueBuffer) {
       Tracing.activeRecording().setInputDataType(_storedType, _singleValue);
       ForwardIndexReaderContext readerContext = getReaderContext();
+      // A UUID column is stored as BYTES, so both paths below would render it 
as hex -- the dictionary is a
+      // BytesDictionary whose getStringValue() is toHexString(). Render the 
canonical form here, at the only layer
+      // that still knows the column's logical type, so every 
getStringValuesSV() caller gets it right.
+      if (_dataType == DataType.UUID) {

Review Comment:
   Will this be hit? The abstraction should already cover the type conversion. 
E.g. we don't really need to any special handling on BOOLEAN and TIMESTAMP



##########
pinot-common/src/test/java/org/apache/pinot/common/request/context/RequestContextUtilsTest.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.util.List;
+import java.util.Locale;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests filter conversion for UUID literals on the right-hand side of a 
predicate.
+ *
+ * <p>{@code CAST(<literal> AS UUID)} is folded to a plain literal by {@code 
CompileTimeFunctionsInvoker}, one of the
+ * query rewriters, so the predicate ends up carrying the canonical UUID 
string that the UUID predicate evaluators
+ * can parse. These tests deliberately go through the full {@link 
CalciteSqlParser#compileToPinotQuery} path rather
+ * than {@code compileToExpression}, because the folding only happens once the 
rewriter chain has run — asserting
+ * against the un-rewritten expression would test a shape the server never 
actually receives.
+ */
+public class RequestContextUtilsTest {
+  private static final String UUID_1 = "550e8400-e29b-41d4-a716-446655440000";
+  private static final String UUID_2 = "550e8400-e29b-41d4-a716-446655440001";
+
+  private static FilterContext compileFilter(String whereClause) {
+    return RequestContextUtils.getFilter(
+        CalciteSqlParser.compileToPinotQuery("SELECT * FROM mytable WHERE " + 
whereClause).getFilterExpression());
+  }
+
+  @Test
+  public void testGetFilterWithUuidCastLiteralRhs() {
+    FilterContext filter = compileFilter("uuidCol = CAST('" + UUID_1 + "' AS 
UUID)");
+
+    Assert.assertEquals(filter.getType(), FilterContext.Type.PREDICATE);
+    EqPredicate predicate = (EqPredicate) filter.getPredicate();
+    Assert.assertEquals(predicate.getLhs().getIdentifier(), "uuidCol");

Review Comment:
   (minor) Use static import, same for other places



##########
pinot-common/src/test/java/org/apache/pinot/common/request/context/RequestContextUtilsTest.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.util.List;
+import java.util.Locale;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**

Review Comment:
   (minor) Use markdown, same for other places



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