Skip to content
Merged
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
Next Next commit
reducing gen code size
  • Loading branch information
ahshahid committed Oct 18, 2016
commit 42e1cea0021ad6b55c1bc55cfade312700e42717
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,43 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection]
ctx.addMutableState("Object[]", values, s"this.$values = null;")

val rowClass = classOf[GenericInternalRow].getName

val fieldWriters = schema.map(_.dataType).zipWithIndex.map { case (dt, i) =>
val converter = convertToSafe(ctx, ctx.getValue(tmp, dt, i.toString), dt)
val isHomogenousStruct = {
var i = 1
val ref = ctx.javaType(schema.fields(0).dataType)
var broken = false || !ctx.isPrimitiveType(ref) || schema.length <=1
while( !broken && i < schema.length) {
if(ctx.javaType(schema.fields(i).dataType) != ref) {
broken = true
}
i +=1
}
!broken
}
val allFields = if(isHomogenousStruct) {
val counter = ctx.freshName("counter")
val converter = convertToSafe(ctx, ctx.getValue(tmp, schema.fields(0).dataType, counter), schema.fields(0).dataType)
s"""
for(int $counter = 0; $counter < ${schema.length}; ++$counter) {
if (!$tmp.isNullAt($counter)) {
${converter.code}
$values[$counter] = ${converter.value};
}
}
"""

}else {
val fieldWriters = schema.map(_.dataType).zipWithIndex.map { case (dt, i) =>
val converter = convertToSafe(ctx, ctx.getValue(tmp, dt, i.toString), dt)
s"""
if (!$tmp.isNullAt($i)) {
${converter.code}
$values[$i] = ${converter.value};
}
"""
}
ctx.splitExpressions(tmp, fieldWriters)
}
val allFields = ctx.splitExpressions(tmp, fieldWriters)

val code = s"""
final InternalRow $tmp = $input;
this.$values = new Object[${schema.length}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro
val isHomogenousStruct = {
var i = 1
val ref = ctx.javaType(t.fields(0).dataType)
var broken = false || !ctx.isPrimitiveType(ref) || t.length <=1 || input.isNull != "false"
var broken = false || !ctx.isPrimitiveType(ref) || t.length <=1
while( !broken && i < t.length) {
if(ctx.javaType(t.fields(i).dataType) != ref) {
broken = true
Expand Down