Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-13537][SQL] Fix readBytes in VectorizedPlainValuesReader #11418

Closed
wants to merge 2 commits into from
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 @@ -85,7 +85,7 @@ public final void readBytes(int total, ColumnVector c, int rowId) {
for (int i = 0; i < total; i++) {
// Bytes are stored as a 4-byte little endian int. Just read the first byte.
// TODO: consider pushing this in ColumnVector by adding a readBytes with a stride.
c.putByte(rowId + i, buffer[offset]);
c.putByte(rowId + i, Platform.getByte(buffer, offset));
offset += 4;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,37 @@ class ParquetHadoopFsRelationSuite extends HadoopFsRelationTest {
}
}
}

test(s"SPARK-13537: Fix readBytes in VectorizedPlainValuesReader") {
withTempPath { file =>
val path = file.getCanonicalPath

val schema = new StructType()
.add("index", IntegerType, nullable = false)
.add("col", ByteType, nullable = true)

val data = Seq(Row(1, -33.toByte), Row(2, 0.toByte), Row(3, -55.toByte), Row(4, 56.toByte),
Row(5, 127.toByte), Row(6, -44.toByte), Row(7, 23.toByte), Row(8, -95.toByte),
Row(9, 127.toByte), Row(10, 13.toByte))

val rdd = sqlContext.sparkContext.parallelize(data)
val df = sqlContext.createDataFrame(rdd, schema).orderBy("index").coalesce(1)

df.write
.mode("overwrite")
.format(dataSourceName)
.option("dataSchema", df.schema.json)
.save(path)

val loadedDF = sqlContext
.read
.format(dataSourceName)
.option("dataSchema", df.schema.json)
.schema(df.schema)
.load(path)
.orderBy("index")

checkAnswer(loadedDF, df)
}
}
}