[ 
https://issues.apache.org/jira/browse/CALCITE-6667?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Caican Cai updated CALCITE-6667:
--------------------------------
    Description: 
Arrow adapter should push down arithmetic operations

Here is a simple case:
{code:java}
select  intField, stringField from arrowdata where floatField - 1 = 12
{code}

Its plan can be optimized to
{code:java}
    String plan = "PLAN=ArrowToEnumerableConverter\n"
        + "  ArrowProject(intField=[$0], stringField=[$1])\n"
        + "    ArrowFilter(condition=[=(+($2, 1.0:DECIMAL(2, 1)), 12.0E0)])\n"
        + "      ArrowTableScan(table=[[ARROW, ARROWDATA]], fields=[[0, 1, 2, 
3]])\n\n";
{code}



  was:
Arrow's filter does not support simple constant addition and subtraction 
calculations.

{code:java}
  private @Nullable String translateBinary2(String op, RexNode left, RexNode 
right) {
    if (right.getKind() != SqlKind.LITERAL) {
      return null;
    }
    final RexLiteral rightLiteral = (RexLiteral) right;
    switch (left.getKind()) {
    case INPUT_REF:
      final RexInputRef left1 = (RexInputRef) left;
      String name = fieldNames.get(left1.getIndex());
      return translateOp2(op, name, rightLiteral);
    case CAST:
      // FIXME This will not work in all cases (for example, we ignore string 
encoding)
      return translateBinary2(op, ((RexCall) left).operands.get(0), right);
    default:
      return null;
    }
  }
{code}

example

{code:java}
    String sql = "select \"intField\", \"stringField\"\n"
        + "from arrowdata\n"
        + "where \"floatField\" - 1 = 12";
    String plan = "PLAN=EnumerableCalc(expr#0..3=[{inputs}], expr#4=[1], 
expr#5=[-($t2, $t4)], expr#6=[12.0E0:REAL], expr#7=[=($t5, $t6)], 
proj#0..1=[{exprs}], $condition=[$t7])\n"
        + "  ArrowToEnumerableConverter\n"
        + "    ArrowTableScan(table=[[ARROW, ARROWDATA]], fields=[[0, 1, 2, 
3]])\n\n";
{code}



        Summary: Arrow adapter should push down arithmetic operations  (was: 
The Filter operator supports simple addition and subtraction operations)

> Arrow adapter should push down arithmetic operations
> ----------------------------------------------------
>
>                 Key: CALCITE-6667
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6667
>             Project: Calcite
>          Issue Type: Bug
>          Components: arrow-adapter
>    Affects Versions: 1.38.0
>            Reporter: Caican Cai
>            Assignee: Caican Cai
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.39.0
>
>
> Arrow adapter should push down arithmetic operations
> Here is a simple case:
> {code:java}
> select  intField, stringField from arrowdata where floatField - 1 = 12
> {code}
> Its plan can be optimized to
> {code:java}
>     String plan = "PLAN=ArrowToEnumerableConverter\n"
>         + "  ArrowProject(intField=[$0], stringField=[$1])\n"
>         + "    ArrowFilter(condition=[=(+($2, 1.0:DECIMAL(2, 1)), 12.0E0)])\n"
>         + "      ArrowTableScan(table=[[ARROW, ARROWDATA]], fields=[[0, 1, 2, 
> 3]])\n\n";
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to