Uh oh!
There was an error while loading. Please reload this page.
[SPARK-16628][SQL] Translate file-based relation schema when file schema is inconsistent with catalog schema - #14365
Conversation
… for file-based data source relation.
SparkQA
commented
Jul 26, 2016
Test build #62875 has finished for PR 14365 at commit
|
SparkQA
commented
Jul 26, 2016
Test build #62880 has finished for PR 14365 at commit
|
viirya
commented
Jul 28, 2016
cc @cloud-fan@yhuai@liancheng@rxin Please review this change. Thanks. |
| /** | ||
| * An interface for mapping two different schemas. For the relations that have are backed by files, | ||
| * the inferred schema from the files might be different with the schema stored in the catalog. In | ||
| * such case, the interface helps mapping inconsistent schemas. |
There was a problem hiding this comment.
Can you put the detailed description of this mapping in the doc here? thanks.
There was a problem hiding this comment.
I've added more detailed document. Please take a look. Thanks.
SparkQA
commented
Jul 29, 2016
Test build #62993 has finished for PR 14365 at commit
|
viirya
commented
Aug 2, 2016
cloud-fan
commented
Aug 2, 2016
viirya
commented
Aug 2, 2016
@cloud-fan I've submitted a PR #14282 previously that disables the conversion if the schema is inconsistent. |
…sistent-schema Conflicts: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileSourceStrategy.scala
SparkQA
commented
Aug 4, 2016
Test build #63214 has finished for PR 14365 at commit
|
viirya
commented
Aug 12, 2016
@cloud-fan So do we have decision on this? A simpler approach to disable the conversion if the schema is inconsistent, or a complex one to work around this Hive bug? |
viirya
commented
Oct 6, 2016
ping @cloud-fan Can you have a decision about this? Are we going to have complex logic for this issue? Or just disable it? |
cloud-fan
commented
Oct 9, 2016
I noticed that And we may stop inferring file schema when reading ORC tables, for performance reasons(#16980), then we don't have the chance to detect the mismatch and disable this feature. We may remove this feature entirely, or thinking harder to come up with a better fix. cc @yhuai |
yhuai
commented
Oct 10, 2016
@cloud-fan actually, this conversion was disabled because of this bug. btw, pr that @cloud-fan mentioned is #14690. I think it is better to hold this change before we finish #14690. |
Hi, @viirya , @cloud-fan , @yhuai . |
viirya
commented
Dec 7, 2016
As we replace schema inferring with metastore schema completely by #14690 for converted Hive tables, we may not have the chance to detect the mismatch between Orc file's physical schema and metastore schema. |
dongjoon-hyun
commented
Dec 7, 2016
It seems to exist some cases like the following (on the current master). On hive, CREATETABLEt1 (a string) PARTITIONED BY (b string) STORED AS ORC;
INSERT INTO TABLE t1 PARTITION (b='01') VALUES ('1');On scala> sql("select * from t1").show
+---+---+| a| b|+---+---+|1|01|+---+---+
scala> sql("set spark.sql.hive.convertMetastoreOrc=true").show
+--------------------+-----+| key|value|+--------------------+-----+|spark.sql.hive.co...|true|+--------------------+-----+
scala> sql("select * from t1").show
16/12/0705:17:19ERRORExecutor:Exception in task 0.0 in stage 2.0 (TID2)
java.lang.IllegalArgumentException:Field"a" does not exist. |
viirya
commented
Dec 8, 2016
@dongjoon-hyun yeah, I see. Because we directly use metastore schema of converted Orc table, when the physical schema in Orc file and metastore schema mismatch, this issue happens. |
viirya
commented
Dec 8, 2016
We have two options. First one is to map metastore schema to physical Orc schema like this. But we don't infer physical schema of Orc file now. I will update this to have this mapping in OrcFileFormat. Another one is like #14282. But as we don't infer schema from Orc file now, we can't disable the conversion when the mismatch is detected. One possible is to throw exception in OrcFileFormat when detecting the mismatch before reading and show message to ask user to disable @cloud-fan@yhuai@dongjoon-hyun What do you think? |
SparkQA
commented
Dec 8, 2016
Test build #69852 has started for PR 14365 at commit |
viirya
commented
Dec 8, 2016
@cloud-fan@yhuai@dongjoon-hyun I've updated this as:
Please let me know what you think about this approach. Thanks. |
viirya
commented
Dec 8, 2016
retest this please. |
SparkQA
commented
Dec 8, 2016
Test build #69856 has finished for PR 14365 at commit
|
| } | ||
| def isMismatchSchema(physicalSchema: StructType, requestedSchema: StructType): Boolean = { | ||
| requestedSchema.forall(a => physicalSchema.getFieldIndex(a.name).isEmpty) |
There was a problem hiding this comment.
Maybe, the following?
!requestedSchema.forall(a => physicalSchema.getFieldIndex(a.name).isDefined)There was a problem hiding this comment.
Oh, never mind. It's really about checking whether all requested columns are not matched.
dongjoon-hyun
commented
Dec 8, 2016
It looks good to me. Thank you for updating, @viirya ! |
viirya
commented
Dec 19, 2016
ping @cloud-fan@yhuai May you take a look? Thanks. |
SparkQA
commented
Dec 19, 2016
Test build #70336 has finished for PR 14365 at commit
|
What changes were proposed in this pull request?
We will convert Metastore Orc tables (represented by
MetastoreRelation) to datasource tables (represented byHadoopFsRelation) ifspark.sql.hive.convertMetastoreOrcis enabled for better performance.However, due to a Hive issue, an Orc table created by Hive does not store column name correctly in the Orc files. For these Orc tables, the converted relation has wrong schema.
To fix this, we assume the metastore schema
dataSchemacan match tophysicalSchemaby each column disregarding the column names. If not, we throw an exception that suggests users to disable the conversion of Hive Orc tables.How was this patch tested?
Jenkins tests.