vvysotskyi commented on a change in pull request #1481: DRILL-6763: Codegen 
optimization of SQL functions with constant values
URL: https://github.com/apache/drill/pull/1481#discussion_r223291277
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
 ##########
 @@ -265,72 +266,103 @@ public HoldingContainer visitSchemaPath(SchemaPath 
path, ClassGenerator<?> gener
       throw new UnsupportedOperationException("All schema paths should have 
been replaced with ValueVectorExpressions.");
     }
 
+    private HoldingContainer createHoldingContainer(MajorType majorType, JVar 
var) {
+      JFieldRef outputSet = null;
+      if (majorType.getMode() == TypeProtos.DataMode.OPTIONAL) {
+        outputSet = var.ref("isSet");
+      }
+      return new HoldingContainer(majorType, var, var.ref("value"), outputSet);
+    }
+
+    private JVar declareClassField(ClassGenerator<?> generator, MajorType 
majorType, String prefix) {
+      JType holderType = generator.getHolderType(majorType);
+      return generator.declareClassField(prefix, holderType);
+    }
+
     @Override
     public HoldingContainer visitLongConstant(LongExpression e, 
ClassGenerator<?> generator) throws RuntimeException {
-      HoldingContainer out = generator.declare(e.getMajorType());
-      generator.getEvalBlock().assign(out.getValue(), JExpr.lit(e.getLong()));
-      return out;
+      JVar var = declareClassField(generator, e.getMajorType(), "long");
 
 Review comment:
   I meant to move all this logic to the separate method and pass 
`ClassGenerator`, `MajorType` and `Function`, for example, to receive something 
like this:
   ```
       @Override
       public HoldingContainer visitLongConstant(LongExpression e, 
ClassGenerator<?> generator) throws RuntimeException {
         return getHoldingContainer(generator,
             e.getMajorType(),
             buffer -> ValueHolderHelper.getBigIntHolder(e.getLong()));
       }
   
       private HoldingContainer getHoldingContainer(ClassGenerator<?> generator,
           MajorType majorType,Function<DrillBuf, ? extends ValueHolder> 
function) {
         JType holderType = generator.getHolderType(majorType);
         JVar var = generator.declareClassField("value", holderType);
         generator.declareSetterMethod(
             var,
             function);
         return createHoldingContainer(majorType, var);
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to