Github user ericl commented on a diff in the pull request:
https://github.com/apache/spark/pull/16944#discussion_r101462262
--- Diff:
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala ---
@@ -161,23 +161,49 @@ private[hive] class
HiveMetastoreCatalog(sparkSession: SparkSession) extends Log
bucketSpec,
Some(partitionSchema))
+ val catalogTable = metastoreRelation.catalogTable
val logicalRelation = cached.getOrElse {
val sizeInBytes =
metastoreRelation.stats(sparkSession.sessionState.conf).sizeInBytes.toLong
val fileIndex = {
- val index = new CatalogFileIndex(
- sparkSession, metastoreRelation.catalogTable, sizeInBytes)
+ val index = new CatalogFileIndex(sparkSession, catalogTable,
sizeInBytes)
if (lazyPruningEnabled) {
index
} else {
index.filterPartitions(Nil) // materialize all the
partitions in memory
}
}
val partitionSchemaColumnNames =
partitionSchema.map(_.name.toLowerCase).toSet
- val dataSchema =
- StructType(metastoreSchema
+ val filteredMetastoreSchema = StructType(metastoreSchema
.filterNot(field =>
partitionSchemaColumnNames.contains(field.name.toLowerCase)))
+ val inferenceMode =
sparkSession.sessionState.conf.schemaInferenceMode
+ val dataSchema = if (inferenceMode != "NEVER_INFER" &&
+ !catalogTable.schemaFromTableProps) {
+ val fileStatuses = fileIndex.listFiles(Nil).flatMap(_.files)
+ val inferred = defaultSource.inferSchema(sparkSession,
options, fileStatuses)
+ val merged = if (fileType.equals("parquet")) {
+
inferred.map(ParquetFileFormat.mergeMetastoreParquetSchema(metastoreSchema, _))
+ } else {
+ inferred
--- End diff --
Why don't we merge in the other cases?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]