Uh oh!
There was an error while loading. Please reload this page.
[SPARK-37627][SQL][FOLLOWUP] Separate SortedBucketTransform from BucketTransform - #34914
[SPARK-37627][SQL][FOLLOWUP] Separate SortedBucketTransform from BucketTransform#34914huaxingao wants to merge 9 commits into
Conversation
SparkQA
commented
Dec 16, 2021
Kubernetes integration test starting |
SparkQA
commented
Dec 16, 2021
Kubernetes integration test status failure |
SparkQA
commented
Dec 16, 2021
Test build #146247 has finished for PR 34914 at commit
|
There was a problem hiding this comment.
does this really work? I don't see a way for people to extract bucket and sort columns from arguments with the Transform API.
There was a problem hiding this comment.
Shall we keep consistent order of columns and numBuckets for two cases in arguments?
There was a problem hiding this comment.
If there are sortedColumn, we need numBuckets in between of columns and sortedColumns, because we need a way to figure out which elements in the array are for columns, and which elements are for sortedColumns.
There was a problem hiding this comment.
There is an extra space between case and Lit.
4719a02 to
00a90daCompare| this.copy(columns = newReferences) | ||
| } else { | ||
| val splits = newReferences.grouped(columns.length).toList | ||
| this.copy(columns = splits(0), sortedColumns = splits(1)) |
There was a problem hiding this comment.
is it: columns = newReferences.take(columns.length), sortedColumns = newReferences.drop(columns.length)
| sortedColumns: Seq[NamedReference] = Seq.empty[NamedReference]) extends RewritableTransform { | ||
| override val name: String = "bucket" | ||
| override val name: String = if (sortedColumns.nonEmpty) "sortedBucket" else "bucket" |
There was a problem hiding this comment.
Can we create a new class SortedBucketTransform to be clearer?
There was a problem hiding this comment.
Added a new class SortedBucketTransform. Thanks!
| val identifier = "testcat.table_name" | ||
| withTable(identifier) { | ||
| sql(s"CREATE TABLE $identifier (a int, b string, c int) USING $v2Source PARTITIONED BY (c)" + | ||
| s" CLUSTERED BY (b) SORTED by (a) INTO 4 BUCKETS") |
There was a problem hiding this comment.
Just want to make sure multiple columns/sortedColumns work ok.
| BucketTransform(literal(numBuckets, IntegerType), references) | ||
| def bucket( | ||
| def sortedBucket( |
There was a problem hiding this comment.
It's OK to keep the name bucket, to match the name of this SQL feature
| columns: Seq[NamedReference], | ||
| sortedColumns: Seq[NamedReference] = Seq.empty[NamedReference]) extends RewritableTransform { | ||
| override val name: String = "sortedBucket" |
There was a problem hiding this comment.
sorted_bucket is more SQL-ish.
| throw new IllegalArgumentException(s"Match: unsupported argument(s) type - ($v, $t)") | ||
| } | ||
| case BucketTransform(numBuckets, ref, _) => | ||
| case BucketTransform(numBuckets, ref) => |
There was a problem hiding this comment.
I think we can have a single BucketTransform.unapply, to match both BucketTransform and SortedBucketTransform, so that we can have a single case here and avoid duplicated code.
| private[sql] object BucketTransform { | ||
| def unapply(expr: Expression): Option[(Int, FieldReference, FieldReference)] = | ||
| expr match { | ||
| def unapply(expr: Expression): Option[(Int, FieldReference, FieldReference)] = expr match { |
There was a problem hiding this comment.
where do we use this unapply?
There was a problem hiding this comment.
This was introduced in #30706 but doesn't seem to be used. I will remove for now.
| var index: Int = -1 | ||
| var posOfLit: Int = -1 | ||
| var numOfBucket: Int = -1 | ||
| arguments.foreach { |
There was a problem hiding this comment.
nit: we can do arguments.zipWithIndex.foreach, so that it's much easier to get posOfLit.
| posOfLit = index | ||
| case _ => index = index + 1 | ||
| } | ||
| Some(numOfBucket, FieldReference(arguments.take(posOfLit).map(_.describe)), |
There was a problem hiding this comment.
we know that the arguments of bucket/sorted_bucketare all NamedReference, how about arguments.take(posOfLit).map(_.asInstanceOf[NamedReference])?
| } | ||
| Some(numOfBucket, FieldReference(arguments.take(posOfLit).map(_.describe)), | ||
| FieldReference(arguments.drop(posOfLit + 1).map(_.describe))) | ||
| case NamedTransform("bucket", Seq(Lit(value: Int, IntegerType), Ref(seq: Seq[String]))) => |
There was a problem hiding this comment.
this doesn't seem to be right. It only matches bucket with a single bucket column.
There was a problem hiding this comment.
Seems somehow only a single column is supported in BucketTransform. Will fix this.
| private[sql] object BucketTransform { | ||
| def unapply(expr: Expression): Option[(Int, FieldReference, FieldReference)] = | ||
| expr match { | ||
| def unapply(expr: Expression): Option[(Int, FieldReference, FieldReference)] = expr match { |
There was a problem hiding this comment.
Could you add some comments on unapply (if it is really used) about what it returns?
| private[sql] object BucketTransform { | ||
| def unapply(expr: Expression): Option[(Int, FieldReference, FieldReference)] = | ||
| expr match { | ||
| def unapply(expr: Expression): Option[(Int, FieldReference, FieldReference)] = expr match { |
There was a problem hiding this comment.
BTW, why def unapply(expr: Expression) addresses only BucketTransform but def unapply(transform: Transform) addresses both sorted_bucket and bucket?
viirya
left a comment
There was a problem hiding this comment.
This change seems to be not only "Add tests ...". It's better to update the title and description accordingly before merging.
huaxingao
commented
Jan 10, 2022
Updated. Thanks! |
cloud-fan
commented
Jan 14, 2022
thanks, merging to master! |
huaxingao
commented
Jan 14, 2022
Thanks! |
…etTransform ### What changes were proposed in this pull request? 1. Currently only a single bucket column is supported in `BucketTransform`, fix the code to make multiple bucket columns work. 2. Separate `SortedBucketTransform` from `BucketTransform`, and make the `arguments` in `SortedBucketTransform` in the format of `columns numBuckets sortedColumns` so we have a way to find out the `columns` and `sortedColumns`. 3. add more test coverage. ### Why are the changes needed? Fix bugs in `BucketTransform` and `SortedBucketTransform`. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New tests Closesapache#34914 from huaxingao/sorted_followup. Lead-authored-by: Huaxin Gao <huaxin_gao@apple.com> Co-authored-by: huaxingao <huaxin.gao11@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
BucketTransform, fix the code to make multiple bucket columns work.SortedBucketTransformfromBucketTransform, and make theargumentsinSortedBucketTransformin the format ofcolumns numBuckets sortedColumnsso we have a way to find out thecolumnsandsortedColumns.Why are the changes needed?
Fix bugs in
BucketTransformandSortedBucketTransform.Does this PR introduce any user-facing change?
No
How was this patch tested?
New tests