-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23939][SQL] Add transform_keys function #22013
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
0a19cc4
12e0259
5806ac4
150a6a5
9f6a8ab
6526630
f7fd231
1cbaf0c
bb52630
621213d
5db526b
e5d9b05
fb885f4
58b60b2
2f4943f
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 |
|---|---|---|
|
|
@@ -512,21 +512,18 @@ case class ArrayAggregate( | |
| """, | ||
| since = "2.4.0") | ||
| case class TransformKeys( | ||
| input: Expression, | ||
| argument: Expression, | ||
| function: Expression) | ||
| extends MapBasedSimpleHigherOrderFunction with CodegenFallback { | ||
|
|
||
| override def nullable: Boolean = input.nullable | ||
| override def nullable: Boolean = argument.nullable | ||
|
|
||
| override def dataType: DataType = { | ||
| val map = input.dataType.asInstanceOf[MapType] | ||
| val map = argument.dataType.asInstanceOf[MapType] | ||
| MapType(function.dataType, map.valueType, map.valueContainsNull) | ||
|
||
| } | ||
|
|
||
| override def inputTypes: Seq[AbstractDataType] = Seq(MapType, expectingFunctionType) | ||
|
|
||
| @transient val (keyType, valueType, valueContainsNull) = | ||
| HigherOrderFunction.mapKeyValueArgumentType(input.dataType) | ||
| @transient val MapType(keyType, valueType, valueContainsNull) = argument.dataType | ||
|
||
|
|
||
| override def bind(f: (Expression, Seq[(DataType, Boolean)]) => LambdaFunction): TransformKeys = { | ||
| copy(function = f(function, (keyType, false) :: (valueType, valueContainsNull) :: Nil)) | ||
|
|
@@ -538,8 +535,8 @@ case class TransformKeys( | |
| (keyVar, valueVar) | ||
| } | ||
|
||
|
|
||
| override def nullSafeEval(inputRow: InternalRow, value: Any): Any = { | ||
| val map = value.asInstanceOf[MapData] | ||
| override def nullSafeEval(inputRow: InternalRow, argumentValue: Any): Any = { | ||
| val map = argumentValue.asInstanceOf[MapData] | ||
| val f = functionForEval | ||
|
||
| val resultKeys = new GenericArrayData(new Array[Any](map.numElements)) | ||
| var i = 0 | ||
|
|
||
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 think this can be moved to
SimpleHigherOrderFunctionThere 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.
makes sense.
Let's have wrap-up prs for higher-order functions after the remaining 2 prs are merged.