You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/09/14 04:14:00 UTC

[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #9389: [Feature] [Refactoring] Create LiteralContext to hold type and value of literal and Boolean literal eval support

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


##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,37 +34,53 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
   private final String _value;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  @Nullable
+  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));
+  }

Review Comment:
   (nit) add an empty line



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,37 +34,53 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
   private final String _value;

Review Comment:
   Change it to `_identifier`



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,37 +34,53 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
   private final String _value;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  @Nullable
+  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) {
     _type = type;
     _value = value;
     _function = function;
+    _literal = literal;
+  }
+
+  @Deprecated
+  public String getLiteralString() {
+    if (_literal == null || _literal.getValue() == null) {
+      return "";

Review Comment:
   Should return `null` to keep the same behavior
   ```suggestion
         return null;
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,37 +34,53 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
   private final String _value;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  @Nullable
+  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) {
     _type = type;
     _value = value;
     _function = function;
+    _literal = literal;
+  }
+
+  @Deprecated
+  public String getLiteralString() {
+    if (_literal == null || _literal.getValue() == null) {
+      return "";
+    }
+    return _literal.getValue().toString();
   }
 
   public Type getType() {
     return _type;
   }
 
-  public String getLiteral() {
-    return _value;
+  @Nullable

Review Comment:
   (minor) Not sure if we want to put `@Nullable` here. We usually call it after checking the type, and this annotation can potentially cause warning in IDE. If we decide to use `@Nullable` here, we should probably also annotate `getIdentifier()` and `getFunction()`



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,37 +34,53 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
   private final String _value;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  @Nullable

Review Comment:
   (minor) We don't usually put `@Nullable` in variable declaration.



##########
pinot-common/src/main/java/org/apache/pinot/common/request/context/ExpressionContext.java:
##########
@@ -31,37 +34,53 @@
  */
 public class ExpressionContext {
   public enum Type {
-    LITERAL, IDENTIFIER, FUNCTION
+    LITERAL, IDENTIFIER, FUNCTION,
   }
 
   private final Type _type;
   private final String _value;
   private final FunctionContext _function;
+  // Only set when the _type is LITERAL
+  @Nullable
+  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) {
     _type = type;
     _value = value;
     _function = function;
+    _literal = literal;
+  }
+
+  @Deprecated
+  public String getLiteralString() {
+    if (_literal == null || _literal.getValue() == null) {
+      return "";
+    }
+    return _literal.getValue().toString();
   }
 
   public Type getType() {
     return _type;
   }
 
-  public String getLiteral() {
-    return _value;
+  @Nullable
+  public LiteralContext getLiteralContext(){

Review Comment:
   ```suggestion
     public LiteralContext getLiteral() {
   ```



-- 
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-unsubscribe@pinot.apache.org

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


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