-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-30184][SQL] Implement a helper method for aliasing functions #26808
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 20 commits
29fdaba
7d5f4be
7ba7802
759262d
5ec101f
f210bb9
cc234b9
7617ec3
92e381b
a2d75de
3ef62af
87c6ea3
9480532
5c540fc
d780dfc
85d9597
a71e8a7
dd2d85d
c1b3afb
e7a4e90
ca886f0
125cfac
4ca20f4
aecdd8a
bbd4397
9146913
8e9e42b
36418e2
ce8ea17
4b536dd
737f33a
1920940
700a84d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,19 +67,25 @@ import org.apache.spark.sql.types._ | |
| """, | ||
| since = "2.1.0") | ||
| case class ApproximatePercentile( | ||
| funcName: String, | ||
| child: Expression, | ||
| percentageExpression: Expression, | ||
| accuracyExpression: Expression, | ||
| override val mutableAggBufferOffset: Int, | ||
| override val inputAggBufferOffset: Int) | ||
| extends TypedImperativeAggregate[PercentileDigest] with ImplicitCastInputTypes { | ||
|
|
||
| def this(child: Expression, percentageExpression: Expression, accuracyExpression: Expression) = { | ||
| this(child, percentageExpression, accuracyExpression, 0, 0) | ||
| def this( | ||
| funcName: String, | ||
|
||
| child: Expression, | ||
| percentageExpression: Expression, | ||
| accuracyExpression: Expression) = { | ||
| this(funcName, child, percentageExpression, accuracyExpression, 0, 0) | ||
| } | ||
|
|
||
| def this(child: Expression, percentageExpression: Expression) = { | ||
| this(child, percentageExpression, Literal(ApproximatePercentile.DEFAULT_PERCENTILE_ACCURACY)) | ||
| def this(funcName: String, child: Expression, percentageExpression: Expression) = { | ||
| this(funcName, child, percentageExpression, | ||
| Literal(ApproximatePercentile.DEFAULT_PERCENTILE_ACCURACY)) | ||
| } | ||
|
|
||
| // Mark as lazy so that accuracyExpression is not evaluated during tree transformation. | ||
|
|
@@ -185,7 +191,7 @@ case class ApproximatePercentile( | |
| if (returnPercentileArray) ArrayType(child.dataType, false) else child.dataType | ||
| } | ||
|
|
||
| override def prettyName: String = "percentile_approx" | ||
| override def nodeName: String = funcName | ||
|
|
||
| override def serialize(obj: PercentileDigest): Array[Byte] = { | ||
| ApproximatePercentile.serializer.serialize(obj) | ||
|
|
@@ -194,6 +200,10 @@ case class ApproximatePercentile( | |
| override def deserialize(bytes: Array[Byte]): PercentileDigest = { | ||
| ApproximatePercentile.serializer.deserialize(bytes) | ||
| } | ||
|
|
||
| override def flatArguments: Iterator[Any] = | ||
| Iterator(child, percentageExpression, accuracyExpression, | ||
| mutableAggBufferOffset, inputAggBufferOffset) | ||
| } | ||
|
|
||
| object ApproximatePercentile { | ||
|
|
@@ -321,4 +331,22 @@ object ApproximatePercentile { | |
| } | ||
|
|
||
| val serializer: PercentileDigestSerializer = new PercentileDigestSerializer | ||
|
|
||
| def apply( | ||
| child: Expression, | ||
|
||
| percentageExpression: Expression, | ||
| accuracyExpression: Expression, | ||
| mutableAggBufferOffset: Int, inputAggBufferOffset: Int): ApproximatePercentile = | ||
| new ApproximatePercentile("percentile_approx", child, percentageExpression, | ||
|
||
| accuracyExpression, mutableAggBufferOffset, inputAggBufferOffset) | ||
|
|
||
| def apply( | ||
| child: Expression, | ||
|
||
| percentageExpression: Expression, | ||
| accuracyExpression: Expression): ApproximatePercentile = { | ||
| new ApproximatePercentile("percentile_approx", child, percentageExpression, accuracyExpression) | ||
| } | ||
|
|
||
| def apply(child: Expression, percentageExpression: Expression): ApproximatePercentile = | ||
| new ApproximatePercentile("percentile_approx", child, percentageExpression) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,9 +35,11 @@ import org.apache.spark.sql.types._ | |
| -3 days -11 hours -59 minutes -59 seconds | ||
| """, | ||
| since = "1.0.0") | ||
| case class Average(child: Expression) extends DeclarativeAggregate with ImplicitCastInputTypes { | ||
| case class Average( | ||
| funcName: String, child: Expression) | ||
|
||
| extends DeclarativeAggregate with ImplicitCastInputTypes { | ||
|
|
||
| override def prettyName: String = "avg" | ||
| override def nodeName: String = funcName | ||
|
|
||
| override def children: Seq[Expression] = child :: Nil | ||
|
|
||
|
|
@@ -93,4 +95,10 @@ case class Average(child: Expression) extends DeclarativeAggregate with Implicit | |
| coalesce(child.cast(sumDataType), Literal.default(sumDataType))), | ||
| /* count = */ If(child.isNull, count, count + 1L) | ||
| ) | ||
|
|
||
| override def flatArguments: Iterator[Any] = Iterator(child) | ||
| } | ||
|
|
||
| object Average{ | ||
| def apply(child: Expression): Average = Average("avg", child) | ||
| } | ||
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.
Seems we don't need
expressionWithAliasat all, just callexpression[Average]("mean", setAlias = true).And
expression[Average]("avg")can remain unchanged, asavgis already the default name.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.
And we don't need to reorder them now.