viirya commented on a change in pull request #25717: [WIP][SPARK-29013][SQL] 
Structurally equivalent subexpression elimination
URL: https://github.com/apache/spark/pull/25717#discussion_r322017093
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/BoundAttribute.scala
 ##########
 @@ -65,6 +65,40 @@ case class BoundReference(ordinal: Int, dataType: DataType, 
nullable: Boolean)
   }
 }
 
+/**
+ * This bound reference points to a parameterized slot in an input tuple. It 
is used in
+ * common sub-expression elimination. When some common sub-expressions have 
same structural
+ * but different slots of input tuple, we replace `BoundReference` with this 
parameterized
+ * version. The slot position is parameterized and is given at runtime.
+ */
+case class ParameterizedBoundReference(parameter: String, dataType: DataType, 
nullable: Boolean)
+  extends LeafExpression {
+
+  override def toString: String = s"input[$parameter, 
${dataType.simpleString}, $nullable]"
+
+  override def eval(input: InternalRow): Any = {
+    throw new UnsupportedOperationException(
+      "ParameterizedBoundReference does not implement eval")
+  }
+
+  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+    assert(ctx.currentVars == null && ctx.INPUT_ROW != null,
+      "ParameterizedBoundReference can not be used in whole-stage codegen 
yet.")
 
 Review comment:
   I think it can be used in whole-stage codegen. As this is applied to 
sub-expression elimination which is non whole-stage only, I'd also like to 
reduce the change of code in a single PR.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to