Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/5298#discussion_r28240423
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableSupport.scala
---
@@ -98,12 +98,32 @@ private[parquet] class RowReadSupport extends
ReadSupport[Row] with Logging {
val metadata = new JHashMap[String, String]()
val requestedAttributes =
RowReadSupport.getRequestedSchema(configuration)
+ // convert fileSchema to attributes
+ val fileAttributes =
ParquetTypesConverter.convertToAttributes(fileSchema, true, true)
+ val fileAttMap = fileAttributes.map(f => f.name.toLowerCase ->
f.name).toMap
+
if (requestedAttributes != null) {
+ // reconcile names of requested Attributes
+ val modRequestedAttributes = requestedAttributes.map(attr => {
+ val lName = attr.name.toLowerCase
+ if (fileAttMap.contains(lName)) {
+ attr.withName(fileAttMap(lName))
+ } else {
+ if (attr.nullable) {
+ attr
+ } else {
+ // field is not nullable but not present in the parquet file
schema!!
+ // this is just a safety check since in hive all columns are
nullable
+ // throw exception here
+ throw new RuntimeException(s"""Field ${attr.name} is
non-nullable,
+ but not found in parquet file schema:
${fileSchema}""".stripMargin)
+ }}})
+
--- End diff --
`ParquetRelation2.mergeMetastoreParquetSchema` is just a static method, can
we just reuse that here? Especially comments for this method and
`ParquetRelation2.mergeMissingNullableFields` are pretty useful. I would like
to keep them.
And please don't put multiple `}`/`)` on a single line.
---
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]