Github user amansinha100 commented on a diff in the pull request:

    https://github.com/apache/drill/pull/598#discussion_r80994695
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java
 ---
    @@ -143,116 +156,176 @@ public void reduce(RexBuilder rexBuilder, 
List<RexNode> constExps, List<RexNode>
             continue;
           }
     
    -        switch(materializedExpr.getMajorType().getMinorType()) {
    -          case INT:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                new BigDecimal(((IntHolder)output).value),
    -                
TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, 
SqlTypeName.INTEGER, newCall.getType().isNullable()),
    -                false));
    -            break;
    -          case BIGINT:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                new BigDecimal(((BigIntHolder)output).value),
    -                
TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, 
SqlTypeName.BIGINT, newCall.getType().isNullable()),
    -                false));
    -            break;
    -          case FLOAT4:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                new BigDecimal(((Float4Holder)output).value),
    -                
TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, 
SqlTypeName.FLOAT, newCall.getType().isNullable()),
    -                false));
    -            break;
    -          case FLOAT8:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                new BigDecimal(((Float8Holder)output).value),
    -                
TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, 
SqlTypeName.DOUBLE, newCall.getType().isNullable()),
    -                false));
    -            break;
    -          case VARCHAR:
    -            reducedValues.add(rexBuilder.makeCharLiteral(
    -                new 
NlsString(StringFunctionHelpers.getStringFromVarCharHolder((VarCharHolder)output),
 null, null)));
    -            break;
    -          case BIT:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                ((BitHolder)output).value == 1 ? true : false,
    -                
TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, 
SqlTypeName.BOOLEAN, newCall.getType().isNullable()),
    -                false));
    -            break;
    -          case DATE:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                new DateTime(((DateHolder) output).value, 
DateTimeZone.UTC).toCalendar(null),
    -                
TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, 
SqlTypeName.DATE, newCall.getType().isNullable()),
    -                false));
    -            break;
    -          case DECIMAL9:
    -            reducedValues.add(rexBuilder.makeLiteral(
    -                new BigDecimal(BigInteger.valueOf(((Decimal9Holder) 
output).value), ((Decimal9Holder)output).scale),
    +      Function<ValueHolder, RexNode> literator = new Function<ValueHolder, 
RexNode>() {
    --- End diff --
    
    Interesting that you are using a Function interface here within the 
original function.  Is this helping much ? It is not eliminating the need for 
the large switch statement.  I would think a valid use case for Function 
interface would be when you are passing a function pointer (borrowing a term 
from c++) to another function and that function calls apply().   We can keep 
this as-is but I am curious about the rationale.   


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to