Skip to content
Prev Previous commit
Next Next commit
Merge master Refactoring changes
  • Loading branch information
codeatri committed Aug 14, 2018
commit 5db526be7bad0fa38dc9743c919014b475cf8aeb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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 SimpleHigherOrderFunction

Copy link
Member

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.


override def dataType: DataType = {
val map = input.dataType.asInstanceOf[MapType]
val map = argument.dataType.asInstanceOf[MapType]
MapType(function.dataType, map.valueType, map.valueContainsNull)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use valueType and valueContainsNull from the following val?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

}

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lazy val?
Could you add a test when argument is not a map in invalid cases of DataFrameFunctionsSuite?


override def bind(f: (Expression, Seq[(DataType, Boolean)]) => LambdaFunction): TransformKeys = {
copy(function = f(function, (keyType, false) :: (valueType, valueContainsNull) :: Nil))
Expand All @@ -538,8 +535,8 @@ case class TransformKeys(
(keyVar, valueVar)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: how about:

@transient lazy val LambdaFunction(_,
  (keyVar: NamedLambdaVariable) :: (valueVar: NamedLambdaVariable) :: Nil, _) = function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant we don't need to surround by:

@transient lazy val (keyVar, valueVar) = {
  ...
  (keyVar, valueVar)
}

just

@transient lazy val LambdaFunction(_,
  (keyVar: NamedLambdaVariable) :: (valueVar: NamedLambdaVariable) :: Nil, _) = function

should work.


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use functionForEval directly?

val resultKeys = new GenericArrayData(new Array[Any](map.numElements))
var i = 0
Expand Down