[ 
https://issues.apache.org/jira/browse/HIVE-25485?focusedWorklogId=651057&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-651057
 ]

ASF GitHub Bot logged work on HIVE-25485:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/Sep/21 12:26
            Start Date: 15/Sep/21 12:26
    Worklog Time Spent: 10m 
      Work Description: kasakrisz commented on a change in pull request #2608:
URL: https://github.com/apache/hive/pull/2608#discussion_r709110069



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveTransformSimpleSelectsToInlineTableInUnion.java
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelRecordType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException;
+import org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable;
+import org.apache.hadoop.hive.ql.optimizer.calcite.TraitsUtil;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableFunctionScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnion;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.translator.SqlFunctionConverter;
+import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Transforms SELECTS of literals under UNION ALL into inline table scans.
+ */
+public class HiveTransformSimpleSelectsToInlineTableInUnion extends RelOptRule 
{

Review comment:
       It is a long name but in case of other rules we add the word `Rule`.
   
   How about `HiveUnionSimpleSelectsToInlineTableRule` ?

##########
File path: ql/src/test/results/clientpositive/llap/union_literals.q.out
##########
@@ -0,0 +1,397 @@
+PREHOOK: query: explain
+SELECT * FROM (
+   VALUES(1, '1'),
+         (2, 'orange'),
+         (5, 'yellow'),
+         (10, 'green'),
+         (11, 'blue'),
+         (12, 'indigo'),
+         (20, 'violet'))
+   AS Colors
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: explain
+SELECT * FROM (
+   VALUES(1, '1'),
+         (2, 'orange'),
+         (5, 'yellow'),
+         (10, 'green'),
+         (11, 'blue'),
+         (12, 'indigo'),
+         (20, 'violet'))
+   AS Colors
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+      Processor Tree:
+        TableScan
+          alias: _dummy_table
+          Row Limit Per Split: 1
+          Select Operator
+            expressions: array(const struct(1,'1'),const 
struct(2,'orange'),const struct(5,'yellow'),const struct(10,'green'),const 
struct(11,'blue'),const struct(12,'indigo'),const struct(20,'violet')) (type: 
array<struct<col1:int,col2:string>>)
+            outputColumnNames: _col0
+            UDTF Operator
+              function name: inline
+              Select Operator
+                expressions: col1 (type: int), col2 (type: string)
+                outputColumnNames: _col0, _col1
+                ListSink
+
+PREHOOK: query: explain
+SELECT * FROM (
+   VALUES(1, '1'),
+         (2, 'orange'),
+         (5, 'yellow'),
+         (10, 'green'),
+         (11, 'blue'),
+         (12, 'indigo'),
+         (20, 'violet'))
+   AS Colors
+union all
+  select 2,'2'
+union all
+  select 2,'2'
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: explain
+SELECT * FROM (
+   VALUES(1, '1'),
+         (2, 'orange'),
+         (5, 'yellow'),
+         (10, 'green'),
+         (11, 'blue'),
+         (12, 'indigo'),
+         (20, 'violet'))
+   AS Colors
+union all
+  select 2,'2'
+union all
+  select 2,'2'
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 depends on stages: Stage-1
+
+STAGE PLANS:
+  Stage: Stage-1
+    Tez
+#### A masked pattern was here ####
+      Edges:
+        Map 1 <- Union 2 (CONTAINS)
+        Map 3 <- Union 2 (CONTAINS)
+#### A masked pattern was here ####
+      Vertices:
+        Map 1 
+            Map Operator Tree:
+                TableScan
+                  alias: _dummy_table
+                  Row Limit Per Split: 1
+                  Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE 
Column stats: COMPLETE
+                  Select Operator
+                    expressions: array(const struct(2,'2'),const 
struct(2,'2')) (type: array<struct<col1:int,col2:string>>)
+                    outputColumnNames: _col0
+                    Statistics: Num rows: 1 Data size: 56 Basic stats: 
COMPLETE Column stats: COMPLETE
+                    UDTF Operator
+                      Statistics: Num rows: 1 Data size: 56 Basic stats: 
COMPLETE Column stats: COMPLETE
+                      function name: inline
+                      Select Operator
+                        expressions: col1 (type: int), col2 (type: string)
+                        outputColumnNames: _col0, _col1
+                        Statistics: Num rows: 1 Data size: 8 Basic stats: 
COMPLETE Column stats: COMPLETE
+                        File Output Operator
+                          compressed: false
+                          Statistics: Num rows: 2 Data size: 16 Basic stats: 
COMPLETE Column stats: COMPLETE
+                          table:
+                              input format: 
org.apache.hadoop.mapred.SequenceFileInputFormat
+                              output format: 
org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                              serde: 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+            Execution mode: llap
+            LLAP IO: no inputs
+        Map 3 
+            Map Operator Tree:
+                TableScan
+                  alias: _dummy_table
+                  Row Limit Per Split: 1
+                  Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE 
Column stats: COMPLETE
+                  Select Operator
+                    expressions: array(const struct(1,'1'),const 
struct(2,'orange'),const struct(5,'yellow'),const struct(10,'green'),const 
struct(11,'blue'),const struct(12,'indigo'),const struct(20,'violet')) (type: 
array<struct<col1:int,col2:string>>)

Review comment:
       Are these Mappers mergeable?
   Map1: `expressions: array(const struct(2,'2'),const struct(2,'2')) (type: 
array<struct<col1:int,col2:string>>)`
   Map3: `expressions: array(const struct(1,'1'),const struct(2,'orange'),const 
struct(5,'yellow'),const struct(10,'green'),const struct(11,'blue'),const 
struct(12,'indigo'),const struct(20,'violet')) (type: 
array<struct<col1:int,col2:string>>)`
   
   

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveTransformSimpleSelectsToInlineTableInUnion.java
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelRecordType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException;
+import org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable;
+import org.apache.hadoop.hive.ql.optimizer.calcite.TraitsUtil;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableFunctionScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnion;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.translator.SqlFunctionConverter;
+import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Transforms SELECTS of literals under UNION ALL into inline table scans.
+ */
+public class HiveTransformSimpleSelectsToInlineTableInUnion extends RelOptRule 
{
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(HiveTransformSimpleSelectsToInlineTableInUnion.class);
+
+  private RelNode dummyTable;
+
+  public HiveTransformSimpleSelectsToInlineTableInUnion(RelNode dummyTable) {
+    super(operand(HiveUnion.class, any()));
+    this.dummyTable = dummyTable;
+  }
+
+  static class RowStorage extends HashMap<RelRecordType, List<RexNode>> {
+
+    private static final long serialVersionUID = 1L;
+
+    public void addRow(RexNode row) {
+      RelRecordType type = (RelRecordType) row.getType();
+
+      List<RexNode> e = get(type);
+      if (e == null) {
+        put(type, e = new ArrayList<RexNode>());
+      }
+      e.add(row);
+    }
+  }
+
+  @Override
+  public void onMatch(RelOptRuleCall call) {
+    RexBuilder rexBuilder = call.builder().getRexBuilder();
+    final HiveUnion union = call.rel(0);
+    if (!union.all) {
+      return;
+    }
+    List<RelNode> inputs = new ArrayList<RelNode>();
+    List<Project> projects = new ArrayList<>();
+    List<HiveTableFunctionScan> inlineTables = new ArrayList<>();
+
+    for (RelNode input : union.getInputs()) {
+      input = HiveRelDecorrelator.stripHep(input);
+
+      if (isPlainProject(input)) {
+        projects.add((Project) input);
+        continue;
+      }
+
+      if (isInlineTableOperand(input)) {
+        inlineTables.add((HiveTableFunctionScan) input);
+        continue;
+      }
+      inputs.add(input);
+    }
+
+    if (projects.size() + inlineTables.size() <= 1) {
+      // nothing to do
+      return;
+    }
+
+    RowStorage newRows = new RowStorage();
+    for (HiveTableFunctionScan rel : inlineTables) {
+      // inline(array(row1,row2,...))
+      RexCall rex = (RexCall) ((RexCall) rel.getCall()).operands.get(0);
+      for (RexNode row : rex.operands) {
+        if (!(row.getType() instanceof RelRecordType)) {
+          return;
+        }
+        newRows.addRow(row);
+      }
+    }
+
+    for (Project proj : projects) {
+      RexNode row = rexBuilder.makeCall(SqlStdOperatorTable.ROW, 
proj.getProjects());
+      if (!(row.getType() instanceof RelRecordType)) {
+        return;
+      }
+      newRows.addRow(row);
+    }
+
+    if (newRows.keySet().size() + inputs.size() == union.getInputs().size()) {
+      // nothing to do
+      return;
+    }
+
+    if (dummyTable == null) {
+      LOG.warn("Unexpected; rule would match - but dummyTable is not 
available");
+      return;
+    }
+
+    for (RelRecordType type : newRows.keySet()) {
+      List<RexNode> rows = newRows.get(type);
+
+      RelDataType arrayType = 
rexBuilder.getTypeFactory().createArrayType(type, -1);
+      try {
+        SqlOperator inlineFn =
+            SqlFunctionConverter.getCalciteFn("inline", 
ImmutableList.of(arrayType), type, true, false);

Review comment:
       nit: Collections.singletonList(arrayType)

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveTransformSimpleSelectsToInlineTableInUnion.java
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelRecordType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException;
+import org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable;
+import org.apache.hadoop.hive.ql.optimizer.calcite.TraitsUtil;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableFunctionScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnion;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.translator.SqlFunctionConverter;
+import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Transforms SELECTS of literals under UNION ALL into inline table scans.
+ */

Review comment:
       Could you please add a dimple example?
   Also a input and output plan something like
   
   from
   ```
   HiveUnion(all=true)
     HiveProject(a=[1])
     ...
     HiveProject(a=[42])
     ...
   ```
   
   to
   ```
   HiveProject(a=[$0])
     HiveTableScan(table=...)
   ```

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveTransformSimpleSelectsToInlineTableInUnion.java
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelRecordType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException;
+import org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable;
+import org.apache.hadoop.hive.ql.optimizer.calcite.TraitsUtil;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableFunctionScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnion;
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.translator.SqlFunctionConverter;
+import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Transforms SELECTS of literals under UNION ALL into inline table scans.
+ */
+public class HiveTransformSimpleSelectsToInlineTableInUnion extends RelOptRule 
{
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(HiveTransformSimpleSelectsToInlineTableInUnion.class);
+
+  private RelNode dummyTable;
+
+  public HiveTransformSimpleSelectsToInlineTableInUnion(RelNode dummyTable) {
+    super(operand(HiveUnion.class, any()));
+    this.dummyTable = dummyTable;
+  }
+
+  static class RowStorage extends HashMap<RelRecordType, List<RexNode>> {
+
+    private static final long serialVersionUID = 1L;
+
+    public void addRow(RexNode row) {
+      RelRecordType type = (RelRecordType) row.getType();
+
+      List<RexNode> e = get(type);
+      if (e == null) {
+        put(type, e = new ArrayList<RexNode>());
+      }
+      e.add(row);
+    }
+  }
+
+  @Override
+  public void onMatch(RelOptRuleCall call) {
+    RexBuilder rexBuilder = call.builder().getRexBuilder();
+    final HiveUnion union = call.rel(0);
+    if (!union.all) {
+      return;
+    }
+    List<RelNode> inputs = new ArrayList<RelNode>();
+    List<Project> projects = new ArrayList<>();
+    List<HiveTableFunctionScan> inlineTables = new ArrayList<>();
+
+    for (RelNode input : union.getInputs()) {
+      input = HiveRelDecorrelator.stripHep(input);
+
+      if (isPlainProject(input)) {
+        projects.add((Project) input);
+        continue;
+      }
+
+      if (isInlineTableOperand(input)) {
+        inlineTables.add((HiveTableFunctionScan) input);
+        continue;
+      }
+      inputs.add(input);
+    }
+
+    if (projects.size() + inlineTables.size() <= 1) {
+      // nothing to do
+      return;
+    }
+
+    RowStorage newRows = new RowStorage();
+    for (HiveTableFunctionScan rel : inlineTables) {
+      // inline(array(row1,row2,...))
+      RexCall rex = (RexCall) ((RexCall) rel.getCall()).operands.get(0);
+      for (RexNode row : rex.operands) {
+        if (!(row.getType() instanceof RelRecordType)) {
+          return;
+        }
+        newRows.addRow(row);
+      }
+    }
+
+    for (Project proj : projects) {
+      RexNode row = rexBuilder.makeCall(SqlStdOperatorTable.ROW, 
proj.getProjects());
+      if (!(row.getType() instanceof RelRecordType)) {
+        return;
+      }
+      newRows.addRow(row);
+    }
+
+    if (newRows.keySet().size() + inputs.size() == union.getInputs().size()) {
+      // nothing to do
+      return;
+    }
+
+    if (dummyTable == null) {
+      LOG.warn("Unexpected; rule would match - but dummyTable is not 
available");
+      return;
+    }
+
+    for (RelRecordType type : newRows.keySet()) {
+      List<RexNode> rows = newRows.get(type);
+
+      RelDataType arrayType = 
rexBuilder.getTypeFactory().createArrayType(type, -1);
+      try {
+        SqlOperator inlineFn =
+            SqlFunctionConverter.getCalciteFn("inline", 
ImmutableList.of(arrayType), type, true, false);
+        SqlOperator arrayFn =
+            SqlFunctionConverter.getCalciteFn("array", 
Collections.nCopies(rows.size(), type), arrayType, true, false);
+
+        RexNode expr = rexBuilder.makeCall(arrayFn, rows);
+        expr = rexBuilder.makeCall(inlineFn, expr);
+
+        RelNode newInlineTable = buildTableFunctionScan(expr, 
union.getCluster());
+
+        inputs.add(newInlineTable);
+
+      } catch (CalciteSemanticException e) {
+        LOG.debug("Conversion failed with exception", e);
+        return;
+      }
+    }
+
+    if (inputs.size() > 1) {
+      HiveUnion newUnion = (HiveUnion) union.copy(union.getTraitSet(), inputs, 
true);
+      call.transformTo(newUnion);
+    } else {
+      call.transformTo(inputs.get(0));
+    }
+  }
+
+  private boolean isPlainProject(RelNode input) {
+    input = HiveRelDecorrelator.stripHep(input);
+    if (!(input instanceof Project)) {
+      return false;
+    }
+    if (input.getInputs().size() == 0) {
+      return true;
+    }
+    return isDummyTableScan(input.getInput(0));
+  }
+
+  private boolean isInlineTableOperand(RelNode input) {
+    input = HiveRelDecorrelator.stripHep(input);
+    if (!(input instanceof HiveTableFunctionScan)) {
+      return false;
+    }
+    if (input.getInputs().size() == 0) {
+      return true;
+    }
+    return isDummyTableScan(input.getInput(0));
+  }
+
+  private boolean isDummyTableScan(RelNode input) {
+    input = HiveRelDecorrelator.stripHep(input);
+    if (!(input instanceof HiveTableScan)) {
+      return false;
+    }
+    HiveTableScan ts = (HiveTableScan) input;
+    Table table = ((RelOptHiveTable) ts.getTable()).getHiveTableMD();
+    if (!table.getDbName().equals(SemanticAnalyzer.DUMMY_DATABASE)) {

Review comment:
       !SemanticAnalyzer.DUMMY_DATABASE.equals(table.getDbName())




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 651057)
    Time Spent: 0.5h  (was: 20m)

> Transform selects of literals under a UNION ALL to inline table scan
> --------------------------------------------------------------------
>
>                 Key: HIVE-25485
>                 URL: https://issues.apache.org/jira/browse/HIVE-25485
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> {code}
> select 1
> union all
> select 1
> union all
> [...]
> union all
> select 1
> {code}
> results in a very big plan; which will have vertexes proportional to the 
> number of union all branch - hence it could be slow to execute it



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to