Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
improve
  • Loading branch information
cloud-fan committed Mar 28, 2017
commit a13ab67ba43f19498c88c96a7a05bfc58de50adc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ object ScalaReflection extends ScalaReflection {

case t if t <:< localTypeOf[Seq[_]] =>
val TypeRef(_, _, Seq(elementType)) = t
val Schema(dataType, elementNullable) = schemaFor(elementType)
val Schema(_, elementNullable) = schemaFor(elementType)
val className = getClassNameFromType(elementType)
val newTypePath = s"""- array element class: "$className"""" +: walkedTypePath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@ case class UnresolvedMapObjects(
function: Expression => Expression,
child: Expression,
customCollectionCls: Option[Class[_]] = None) extends UnaryExpression with Unevaluable {
override def dataType: DataType = throw new UnsupportedOperationException("not resolved")
override lazy val resolved = false

override def dataType: DataType = customCollectionCls.map(ObjectType.apply).getOrElse {
throw new UnsupportedOperationException("not resolved")
}
}

/**
Expand Down Expand Up @@ -588,17 +592,24 @@ case class MapObjects private(
// collection
val collObjectName = s"${cls.getName}$$.MODULE$$"
val getBuilderVar = s"$collObjectName.newBuilder()"

(s"""${classOf[Builder[_, _]].getName} $builderValue = $getBuilderVar;
$builderValue.sizeHint($dataLength);""",
(
s"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

below are style-only changes

${classOf[Builder[_, _]].getName} $builderValue = $getBuilderVar;
$builderValue.sizeHint($dataLength);
""",
genValue => s"$builderValue.$$plus$$eq($genValue);",
s"(${cls.getName}) $builderValue.result();")
s"(${cls.getName}) $builderValue.result();"
)
case None =>
// array
(s"""$convertedType[] $convertedArray = null;
$convertedArray = $arrayConstructor;""",
(
s"""
$convertedType[] $convertedArray = null;
$convertedArray = $arrayConstructor;
""",
genValue => s"$convertedArray[$loopIndex] = $genValue;",
s"new ${classOf[GenericArrayData].getName}($convertedArray);")
s"new ${classOf[GenericArrayData].getName}($convertedArray);"
)
}

val code = s"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
*
* This class currently assumes there is at least one input row.
*/
private[sql] class ReduceAggregator[T](func: (T, T) => T)(@transient implicit val enc: Encoder[T])
private[sql] class ReduceAggregator[T: Encoder](func: (T, T) => T)
extends Aggregator[T, (Boolean, T), T] {

@transient private val encoder = implicitly[Encoder[T]]

override def zero: (Boolean, T) = (false, null.asInstanceOf[T])

override def bufferEncoder: Encoder[(Boolean, T)] =
ExpressionEncoder.tuple(
ExpressionEncoder[Boolean](),
enc.asInstanceOf[ExpressionEncoder[T]])
encoder.asInstanceOf[ExpressionEncoder[T]])

override def outputEncoder: Encoder[T] = enc
override def outputEncoder: Encoder[T] = encoder

override def reduce(b: (Boolean, T), a: T): (Boolean, T) = {
if (b._1) {
Expand Down