You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/02/03 10:32:09 UTC

[GitHub] [spark] MaxGekk commented on pull request #31423: [SPARK-34314][SQL] Create new file index after partition schema inferring w/ the schema

MaxGekk commented on pull request #31423:
URL: https://github.com/apache/spark/pull/31423#issuecomment-772405194


   > can you provide more code-wise details about how this bug is triggered?
   
   @cloud-fan We have in the file system:
   ```
   $ tree /private/var/folders/p3/dfs6mf655d7fnjrsjvldh0tc0000gn/T/spark-f57b515d-7449-4ace-98e6-becde9490095
   /private/var/folders/p3/dfs6mf655d7fnjrsjvldh0tc0000gn/T/spark-f57b515d-7449-4ace-98e6-becde9490095
   ├── _SUCCESS
   ├── part=-0
   │   └── part-00001-6612e1e6-c81a-4763-81d8-ea9b446a525e.c000.snappy.parquet
   └── part=AA
       └── part-00000-6612e1e6-c81a-4763-81d8-ea9b446a525e.c000.snappy.parquet
   ```
   
   `getOrInferFileFormatSchema(format, () => index)` -> `tempFileIndex.partitionSchema` -> `cachedPartitionSpec = inferPartitioning()`:
   https://github.com/apache/spark/blob/467d7589737d2430d09f1ffbd33bf801d179f990/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala#L73
   -> parsePartitions():
   https://github.com/apache/spark/blob/a093d6feefb0e086d19c86ae53bf92df12ccf2fa/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PartitioningUtils.scala#L138-L142
   
   `parsePartition()` parses every partition individually and finds the "best" type for every partition value:
   - `part=AA` -> `parsePartitionColumn` -> `inferPartitionColumnValue` returns: `Literal.create("AA", StringType)`
   - `part=-0` -> `parsePartitionColumn` -> `inferPartitionColumnValue` returns: `Literal.create(0, IntegerType)`
   
   Inferring the common type:
   ```
   val resolvedPartitionValues =
           resolvePartitions(pathsWithPartitionValues, caseSensitive, zoneId)
   ```
   After inferring the string type, and casting the partition value literals, we get:
   https://github.com/apache/spark/blob/a093d6feefb0e086d19c86ae53bf92df12ccf2fa/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PartitioningUtils.scala#L196
   ```
   PartitionSpec(
       partitionColumns = StructType(StructField(StringType, ...)),
       partitions = Seq(
           UTF8String("AA") -> path.`part=AA`,
           UTF8String("0") -> path.`part=-0`
       )
   )
   ```
   Then the partitions are cached, and used in scans.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org