-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-15764][SQL] Replace N^2 loop in BindReferences #13505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6216e94
b1a7646
38e8a99
0b412b0
bc17587
e7c4150
210dbd3
dd94e29
b933fe0
4efd3ee
5504b6c
bdb68ad
99197b7
5e9c258
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst | ||
|
|
||
| import com.google.common.collect.Maps | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.types.{StructField, StructType} | ||
|
|
||
|
|
@@ -94,12 +96,14 @@ package object expressions { | |
|
|
||
| private lazy val inputArr = attrs.toArray | ||
|
|
||
| private lazy val inputToOrdinal = { | ||
| val map = new java.util.HashMap[ExprId, Int](inputArr.length * 2) | ||
| private lazy val exprIdToOrdinal = { | ||
| val arr = inputArr | ||
| val map = Maps.newHashMapWithExpectedSize[ExprId, Int](arr.length) | ||
| var index = 0 | ||
| attrs.foreach { attr => | ||
| if (!map.containsKey(attr.exprId)) { | ||
| map.put(attr.exprId, index) | ||
| while (index < arr.length) { | ||
| val exprId = arr(index).exprId | ||
| if (!map.containsKey(exprId)) { | ||
| map.put(exprId, index) | ||
| } | ||
| index += 1 | ||
|
||
| } | ||
|
|
@@ -109,7 +113,7 @@ package object expressions { | |
| def apply(ordinal: Int): Attribute = inputArr(ordinal) | ||
|
|
||
| def getOrdinalWithExprId(exprId: ExprId): Int = { | ||
|
||
| Option(inputToOrdinal.get(exprId)).getOrElse(-1) | ||
| Option(exprIdToOrdinal.get(exprId)).getOrElse(-1) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to check containsKey before the put?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was being conservative here in order to match the behavior of the old linear scan, which stopped upon finding the first entry with a matching expression id. However, we can remove the need for this check if we iterate over
arrin reverse-order.