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


##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -0,0 +1,126 @@
+/**
+ * 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 com.google.common.base.Preconditions;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.request.Literal;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * 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 FieldSpec.DataType _type;
+  private Object _value;
+
+  private static FieldSpec.DataType 
convertThriftTypeToDataType(Literal._Fields fields) {
+    switch (fields) {
+      case SHORT_VALUE:
+      case INT_VALUE:
+        return FieldSpec.DataType.INT;
+      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;
+      default:
+        throw new UnsupportedOperationException("Unsupported literal type:" + 
fields);
+    }
+  }
+
+  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);
+    }
+  }
+
+  public LiteralContext(Literal literal) {
+    _type = convertThriftTypeToDataType(literal.getSetField());
+    _value = literal.getFieldValue();
+  }
+
+  public FieldSpec.DataType getType() {
+    return _type;
+  }
+
+  @Nullable
+  public Object getValue() {
+    return _value;
+  }
+
+  public LiteralContext(FieldSpec.DataType type, Object value) {
+    Preconditions.checkArgument(convertDataTypeToJavaType(type) == 
value.getClass(),
+        "Unmatched data type: " + type + " java type: " + value.getClass());
+    _type = type;
+    _value = value;
+  }
+
+  @Override
+  public int hashCode() {
+    if (_value == null) {
+      return 31 * 31 * _type.hashCode();
+    }
+    return 31 * 31 * _type.hashCode() + 31 * _value.hashCode();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof LiteralContext)) {
+      return false;
+    }
+    LiteralContext that = (LiteralContext) o;
+    return _type.equals(that._type) && Objects.equals(_value, that._value);
+  }
+
+  @Override
+  public String toString() {
+    if (_value == null) {

Review Comment:
   Then we should return `"null"` instead of `"''"`



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,41 +33,58 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,

Review Comment:
   (minor) revert



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java:
##########
@@ -0,0 +1,126 @@
+/**
+ * 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 com.google.common.base.Preconditions;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.request.Literal;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * 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 FieldSpec.DataType _type;
+  private Object _value;
+
+  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;
+      default:
+        throw new UnsupportedOperationException("Unsupported literal type:" + 
fields);
+    }
+  }
+
+  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);
+    }
+  }
+
+  public LiteralContext(Literal literal) {
+    _type = convertThriftTypeToDataType(literal.getSetField());
+    _value = literal.getFieldValue();
+  }
+
+  public FieldSpec.DataType getType() {
+    return _type;
+  }
+
+  @Nullable
+  public Object getValue() {
+    return _value;
+  }
+
+  public LiteralContext(FieldSpec.DataType type, Object value) {
+    Preconditions.checkArgument(convertDataTypeToJavaType(type) == 
value.getClass(),
+        "Unmatched data type: " + type + " java type: " + value.getClass());
+    _type = type;
+    _value = value;
+  }
+
+  @Override
+  public int hashCode() {
+    if (_value == null) {
+      return 31 * 31 * _type.hashCode();
+    }
+    return 31 * 31 * _type.hashCode() + 31 * _value.hashCode();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof LiteralContext)) {
+      return false;
+    }
+    LiteralContext that = (LiteralContext) o;
+    return _type.equals(that._type) && Objects.equals(_value, that._value);
+  }
+
+  @Override
+  public String toString() {
+    if (_value == null) {
+      return '\'' + "" + '\'';
+    }
+    // TODO: print out the type.
+    if(_type == FieldSpec.DataType.STRING || _type == 
FieldSpec.DataType.BYTES) {

Review Comment:
   What is the value for `BYTES` type? If it is `byte[]`, `toString()` won't 
work



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,41 +33,58 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
-  private final String _value;
+  private final String _identifier;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  private final LiteralContext _literal;
 
-  public static ExpressionContext forLiteral(String literal) {
-    return new ExpressionContext(Type.LITERAL, literal, null);
+  public static ExpressionContext forLiteralContext(Literal literal){
+    return new ExpressionContext(Type.LITERAL, null, null, new 
LiteralContext(literal));
+  }
+  
+  public static ExpressionContext forLiteralContext(FieldSpec.DataType type, 
Object val){
+    return new ExpressionContext(Type.LITERAL, null, null, new 
LiteralContext(type, val));
   }
 
   public static ExpressionContext forIdentifier(String identifier) {
-    return new ExpressionContext(Type.IDENTIFIER, identifier, null);
+    return new ExpressionContext(Type.IDENTIFIER, identifier, null, null);
   }
 
   public static ExpressionContext forFunction(FunctionContext function) {
-    return new ExpressionContext(Type.FUNCTION, null, function);
+    return new ExpressionContext(Type.FUNCTION, null, function, null);
   }
 
-  private ExpressionContext(Type type, String value, FunctionContext function) 
{
+  private ExpressionContext(Type type, String value, FunctionContext function, 
LiteralContext literal) {

Review Comment:
   ```suggestion
     private ExpressionContext(Type type, String identifier, FunctionContext 
function, LiteralContext literal) {
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,41 +33,58 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
-  private final String _value;
+  private final String _identifier;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  private final LiteralContext _literal;
 
-  public static ExpressionContext forLiteral(String literal) {
-    return new ExpressionContext(Type.LITERAL, literal, null);
+  public static ExpressionContext forLiteralContext(Literal literal){

Review Comment:
   (format) Please reformat the changes



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