Skip to content

Commit efd0b25

Browse files
author
Davies Liu
committed
fix copy of MutableRow
1 parent 87b13cf commit efd0b25

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateProjection.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ object GenerateProjection extends CodeGenerator[Seq[Expression], Projection] {
148148
"""
149149
}.mkString("\n")
150150

151+
val copyColumns = expressions.zipWithIndex.map { case (e, i) =>
152+
s"""arr[$i] = c$i;"""
153+
}.mkString("\n ")
154+
151155
val code = s"""
152156
public SpecificProjection generate($exprType[] expr) {
153157
return new SpecificProjection(expr);
@@ -215,6 +219,13 @@ object GenerateProjection extends CodeGenerator[Seq[Expression], Projection] {
215219
}
216220
return super.equals(other);
217221
}
222+
223+
@Override
224+
public InternalRow copy() {
225+
Object[] arr = new Object[${expressions.length}];
226+
${copyColumns}
227+
return new ${typeOf[GenericInternalRow]}(arr);
228+
}
218229
}
219230
"""
220231

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/rows.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ abstract class MutableRow extends InternalRow {
4141
def setString(i: Int, value: String): Unit = {
4242
update(i, UTF8String.fromString(value))
4343
}
44+
45+
override def copy(): InternalRow = {
46+
val arr = new Array[Any](length)
47+
var i = 0
48+
while (i < length) {
49+
arr(i) = get(i)
50+
i += 1
51+
}
52+
new GenericInternalRow(arr)
53+
}
4454
}
4555

4656
/**

sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveInspectorSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ class HiveInspectorSuite extends SparkFunSuite with HiveInspectors {
202202
val dt = StructType(dataTypes.zipWithIndex.map {
203203
case (t, idx) => StructField(s"c_$idx", t)
204204
})
205-
205+
val inspector = toInspector(dt)
206206
checkValues(row,
207-
unwrap(wrap(Row.fromSeq(row), toInspector(dt)), toInspector(dt)).asInstanceOf[InternalRow])
207+
unwrap(wrap(InternalRow.fromSeq(row), inspector), inspector).asInstanceOf[InternalRow])
208208
checkValue(null, unwrap(wrap(null, toInspector(dt)), toInspector(dt)))
209209
}
210210

0 commit comments

Comments
 (0)