Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,12 @@ trait ComplexTypeMergingExpression extends Expression {
s" The input types found are\n\t${inputTypesForMerging.mkString("\n\t")}")
}

override def dataType: DataType = {
private lazy val internalDataType: DataType = {
dataTypeCheck
inputTypesForMerging.reduceLeft(TypeCoercion.findCommonTypeDifferentOnlyInNullFlags(_, _).get)
}

override def dataType: DataType = internalDataType
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ case class ApproximatePercentile(
override def nullable: Boolean = true

// The result type is the same as the input type.
override def dataType: DataType = {
private lazy val internalDataType: DataType = {
if (returnPercentileArray) ArrayType(child.dataType, false) else child.dataType
}

override def dataType: DataType = internalDataType

override def prettyName: String =
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("percentile_approx")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ case class MapEntries(child: Expression)

@transient private lazy val childDataType: MapType = child.dataType.asInstanceOf[MapType]

override def dataType: DataType = {
private lazy val internalDataType: DataType = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it expensive? it just creates a few objects.

Copy link
Copy Markdown
Member Author

@wangyum wangyum Sep 22, 2020

Choose a reason for hiding this comment

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

This is to improve this case:
image

Benchmark code Before this PR(Milliseconds) After this PR(Milliseconds)
spark.range(100000000L).selectExpr("approx_count_distinct(map_entries(map(1, id)))").collect() 21787 15551

ArrayType(
StructType(
StructField("key", childDataType.keyType, false) ::
Expand All @@ -377,6 +377,8 @@ case class MapEntries(child: Expression)
false)
}

override def dataType: DataType = internalDataType

override protected def nullSafeEval(input: Any): Any = {
val childMap = input.asInstanceOf[MapData]
val keys = childMap.keyArray()
Expand Down Expand Up @@ -3498,13 +3500,16 @@ object ArrayUnion {
since = "2.4.0")
case class ArrayIntersect(left: Expression, right: Expression) extends ArrayBinaryLike
with ComplexTypeMergingExpression {
override def dataType: DataType = {

private lazy val internalDataType: DataType = {
dataTypeCheck
Comment thread
wangyum marked this conversation as resolved.
Comment thread
wangyum marked this conversation as resolved.
ArrayType(elementType,
left.dataType.asInstanceOf[ArrayType].containsNull &&
right.dataType.asInstanceOf[ArrayType].containsNull)
}

override def dataType: DataType = internalDataType

@transient lazy val evalIntersect: (ArrayData, ArrayData) => ArrayData = {
if (TypeUtils.typeWithProperEquals(elementType)) {
(array1, array2) =>
Expand Down Expand Up @@ -3741,11 +3746,13 @@ case class ArrayIntersect(left: Expression, right: Expression) extends ArrayBina
case class ArrayExcept(left: Expression, right: Expression) extends ArrayBinaryLike
with ComplexTypeMergingExpression {

override def dataType: DataType = {
private lazy val internalDataType: DataType = {
dataTypeCheck
Comment thread
wangyum marked this conversation as resolved.
left.dataType
}

override def dataType: DataType = internalDataType

@transient lazy val evalExcept: (ArrayData, ArrayData) => ArrayData = {
if (TypeUtils.typeWithProperEquals(elementType)) {
(array1, array2) =>
Expand Down