Github user yhuai commented on a diff in the pull request: https://github.com/apache/spark/pull/13025#discussion_r62698532 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala --- @@ -489,9 +486,83 @@ private[sql] object DDLUtils { case _ => }) } + def isTablePartitioned(table: CatalogTable): Boolean = { - table.partitionColumns.size > 0 || + table.partitionColumns.nonEmpty || table.properties.contains("spark.sql.sources.schema.numPartCols") } -} + def getSchemaFromTableProperties(metadata: CatalogTable): Option[StructType] = { + getSchemaFromTableProperties(metadata.properties) + } + + // A persisted data source table may not store its schema in the catalog. In this case, its schema + // will be inferred at runtime when the table is referenced. + def getSchemaFromTableProperties(props: Map[String, String]): Option[StructType] = { + require(isDatasourceTable(props)) + + val schemaParts = for { + numParts <- props.get("spark.sql.sources.schema.numParts").toSeq + index <- 0 until numParts.toInt + } yield props.getOrElse( + s"spark.sql.sources.schema.part.$index", + throw new AnalysisException( + s"Corrupted schema in catalog: $numParts parts expected, but part $index is missing." + ) + ) + + if (schemaParts.isEmpty) { + None + } else { + Some(DataType.fromJson(schemaParts.mkString).asInstanceOf[StructType]) + } + } --- End diff -- There was a time when we only used `spark.sql.sources.schema`. Let's check this first and then check `spark.sql.sources.schema.numParts`. You can take a look at `HiveMetastoreCatalog`'s `cachedDataSourceTables`.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org