cloud-fan commented on code in PR #44377:
URL: https://github.com/apache/spark/pull/44377#discussion_r1435100769


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala:
##########
@@ -198,10 +198,21 @@ class V2SessionCatalog(catalog: SessionCatalog)
             s"Partitions should be empty when the schema is empty: 
${partitions.mkString(", ")}")
           // Infer the schema and partitions and store them in the catalog.
           (tableProvider.inferSchema(dsOptions), 
tableProvider.inferPartitioning(dsOptions))
-        } else if (partitions.isEmpty) {
-          (schema, tableProvider.inferPartitioning(dsOptions))
         } else {
-          (schema, partitions)
+          val partitioning = if (partitions.isEmpty) {
+            tableProvider.inferPartitioning(dsOptions)
+          } else {
+            partitions
+          }
+          val table = tableProvider.getTable(schema, partitions, dsOptions)
+          // Check if the schema of the created table matches the given schema.
+          val tableSchema = 
CharVarcharUtils.replaceCharVarcharWithStringInSchema(
+            table.columns().asSchema)
+          if (!DataType.equalsIgnoreNullability(tableSchema, schema)) {
+            throw QueryCompilationErrors.dataSourceTableSchemaMismatchError(

Review Comment:
   Since I touched it, I improved the error message a little bit to make it 
more clear.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to