-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-14387][SPARK-16628][SPARK-18355][SQL] Use Spark schema to read ORC table instead of ORC file schema #19470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ import org.apache.spark.sql.catalyst.parser.ParseException | |
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, SubqueryAlias} | ||
import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, LogicalRelation} | ||
import org.apache.spark.sql.functions._ | ||
import org.apache.spark.sql.hive.HiveUtils | ||
import org.apache.spark.sql.hive.{HiveExternalCatalog, HiveUtils} | ||
import org.apache.spark.sql.hive.test.TestHiveSingleton | ||
import org.apache.spark.sql.internal.SQLConf | ||
import org.apache.spark.sql.test.SQLTestUtils | ||
|
@@ -2050,4 +2050,64 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
} | ||
} | ||
} | ||
|
||
Seq("orc", "parquet").foreach { format => | ||
test(s"SPARK-18355 Read data from a hive table with a new column - $format") { | ||
val client = spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client | ||
|
||
Seq("true", "false").foreach { value => | ||
withSQLConf( | ||
HiveUtils.CONVERT_METASTORE_ORC.key -> value, | ||
HiveUtils.CONVERT_METASTORE_PARQUET.key -> value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you separate orc and parquet to two tests in fact, maybe you just need to test against one config at one time, i.e., orc -> HiveUtils.CONVERT_METASTORE_ORC, parquet -> HiveUtils.CONVERT_METASTORE_PARQUET.key. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for review, @viirya . For that, yes, we can, but that will be a little-bit overkill. |
||
withTempDatabase { db => | ||
client.runSqlHive( | ||
s""" | ||
|CREATE TABLE $db.t( | ||
| click_id string, | ||
| search_id string, | ||
| uid bigint) | ||
|PARTITIONED BY ( | ||
| ts string, | ||
| hour string) | ||
|STORED AS $format | ||
""".stripMargin) | ||
|
||
client.runSqlHive( | ||
s""" | ||
|INSERT INTO TABLE $db.t | ||
|PARTITION (ts = '98765', hour = '01') | ||
|VALUES (12, 2, 12345) | ||
""".stripMargin | ||
) | ||
|
||
checkAnswer( | ||
sql(s"SELECT click_id, search_id, uid, ts, hour FROM $db.t"), | ||
Row("12", "2", 12345, "98765", "01")) | ||
|
||
client.runSqlHive(s"ALTER TABLE $db.t ADD COLUMNS (dummy string)") | ||
|
||
checkAnswer( | ||
sql(s"SELECT click_id, search_id FROM $db.t"), | ||
Row("12", "2")) | ||
|
||
checkAnswer( | ||
sql(s"SELECT search_id, click_id FROM $db.t"), | ||
Row("2", "12")) | ||
|
||
checkAnswer( | ||
sql(s"SELECT search_id FROM $db.t"), | ||
Row("2")) | ||
|
||
checkAnswer( | ||
sql(s"SELECT dummy, click_id FROM $db.t"), | ||
Row(null, "12")) | ||
|
||
checkAnswer( | ||
sql(s"SELECT click_id, search_id, uid, dummy, ts, hour FROM $db.t"), | ||
Row("12", "2", 12345, null, "98765", "01")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it work? seems here we lie to the orc reader about the physical schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see, we only need to pass the required column indices to orc reader.