-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-19459][SQL] Add Hive datatype (char/varchar) to StructField metadata #16804
Changes from 8 commits
c6a5bf6
277ed15
64c37e0
7d1b48e
f42348a
e378f62
673168e
e7ca0ea
2fa926d
21be4ca
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 |
---|---|---|
|
@@ -152,14 +152,39 @@ abstract class OrcSuite extends QueryTest with TestHiveSingleton with BeforeAndA | |
assert(new OrcOptions(Map("Orc.Compress" -> "NONE")).compressionCodec == "NONE") | ||
} | ||
|
||
test("SPARK-18220: read Hive orc table with varchar column") { | ||
test("SPARK-19459/SPARK-18220: read char/varchar column written by Hive") { | ||
val hiveClient = spark.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client | ||
val location = Utils.createTempDir().toURI | ||
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. shall we remove this temp dir in the finally block? |
||
try { | ||
hiveClient.runSqlHive("CREATE TABLE orc_varchar(a VARCHAR(10)) STORED AS orc") | ||
hiveClient.runSqlHive("INSERT INTO TABLE orc_varchar SELECT 'a' FROM (SELECT 1) t") | ||
checkAnswer(spark.table("orc_varchar"), Row("a")) | ||
hiveClient.runSqlHive( | ||
""" | ||
|CREATE EXTERNAL TABLE hive_orc( | ||
| a STRING, | ||
| b CHAR(10), | ||
| c VARCHAR(10)) | ||
|STORED AS orc""".stripMargin) | ||
// Hive throws an exception if I assign the location in the create table statement. | ||
hiveClient.runSqlHive( | ||
s"ALTER TABLE hive_orc SET LOCATION '$location'") | ||
hiveClient.runSqlHive( | ||
"INSERT INTO TABLE hive_orc SELECT 'a', 'b', 'c' FROM (SELECT 1) t") | ||
|
||
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. How about adding one more check? checkAnswer(spark.table("hive_orc"), Row("a", "b ", "c")) Then, we can remove the test case 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. yeah that makes sense 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. Done. |
||
// We create a different table in Spark using the same schema which points to | ||
// the same location. | ||
spark.sql( | ||
s""" | ||
|CREATE EXTERNAL TABLE spark_orc( | ||
| a STRING, | ||
| b CHAR(10), | ||
| c VARCHAR(10)) | ||
|STORED AS orc | ||
|LOCATION '$location'""".stripMargin) | ||
val result = Row("a", "b ", "c") | ||
checkAnswer(spark.table("hive_orc"), result) | ||
checkAnswer(spark.table("spark_orc"), result) | ||
} finally { | ||
hiveClient.runSqlHive("DROP TABLE IF EXISTS orc_varchar") | ||
hiveClient.runSqlHive("DROP TABLE IF EXISTS hive_orc") | ||
hiveClient.runSqlHive("DROP TABLE IF EXISTS spark_orc") | ||
} | ||
} | ||
} | ||
|
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.
shall we remove
HiveUtils. HIVE_TYPE_STRING
?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.
Yeah we should.