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

Sanitize column names in ParquetCachedBatchSerializer before writing to Parquet [databricks] #4258

Merged
merged 3 commits into from
Dec 7, 2021
Merged
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 @@ -565,11 +565,14 @@ class ParquetCachedBatchSerializer extends GpuCachedBatchSerializer with Arm {
})
cbRdd.mapPartitions(iter => CloseableColumnBatchIterator(iter))
} else {
val origSelectedAttributesWithUnambiguousNames =
sanitizeColumnNames(newSelectedAttributes, selectedSchemaWithNames)
val broadcastedConf = SparkSession.active.sparkContext.broadcast(conf.getAllConfs)
input.mapPartitions {
cbIter => {
new CachedBatchIteratorConsumer(cbIter, cachedSchemaWithNames, selectedSchemaWithNames,
cacheAttributes, newSelectedAttributes, broadcastedConf).getColumnBatchIterator
cacheAttributes, origSelectedAttributesWithUnambiguousNames, broadcastedConf)
.getColumnBatchIterator
}
}
}
Expand All @@ -592,11 +595,12 @@ class ParquetCachedBatchSerializer extends GpuCachedBatchSerializer with Arm {
conf: SQLConf): RDD[InternalRow] = {
val (cachedSchemaWithNames, selectedSchemaWithNames) =
getSupportedSchemaFromUnsupported(cacheAttributes, selectedAttributes)
val newSelectedAttributes = sanitizeColumnNames(selectedAttributes, selectedSchemaWithNames)
val broadcastedConf = SparkSession.active.sparkContext.broadcast(conf.getAllConfs)
input.mapPartitions {
cbIter => {
new CachedBatchIteratorConsumer(cbIter, cachedSchemaWithNames, selectedSchemaWithNames,
cacheAttributes, selectedAttributes, broadcastedConf).getInternalRowIterator
cacheAttributes, newSelectedAttributes, broadcastedConf).getInternalRowIterator
}
}
}
Expand Down Expand Up @@ -1357,6 +1361,14 @@ class ParquetCachedBatchSerializer extends GpuCachedBatchSerializer with Arm {
}
}

// We want to change the original schema to have the new names as well
private def sanitizeColumnNames(originalSchema: Seq[Attribute],
schemaToCopyNamesFrom: Seq[Attribute]): Seq[Attribute] = {
originalSchema.zip(schemaToCopyNamesFrom).map {
case (origAttribute, newAttribute) => origAttribute.withName(newAttribute.name)
}
}

private def getSupportedSchemaFromUnsupported(
cachedAttributes: Seq[Attribute],
requestedAttributes: Seq[Attribute] = Seq.empty): (Seq[Attribute], Seq[Attribute]) = {
Expand Down