You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/05/26 07:50:15 UTC
[GitHub] [spark] opensky142857 opened a new pull request #32675: [SPARK-35531]Can not insert into hive bucket table if create table wi…
opensky142857 opened a new pull request #32675:
URL: https://github.com/apache/spark/pull/32675
…th upper case schema
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error message, please read the guideline first:
https://spark.apache.org/error-message-guidelines.html
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
when convert to HiveTable, respect table schema cases.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
When user create a hive bucket table with upper case schema, the table schema will be stored as lower cases while bucket column info will stay the same with user input.
if we try to insert into this table, an HiveException reports bucket column is not in table schema.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
UT
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
wangyum commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-850086524
cc @cloud-fan @yaooqinn @AngersZhuuuu
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-851177143
Can you post the full stacktrace? I'm a bit curious about how/where the error happens.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r641220605
##########
File path: sql/hive/src/test/scala/org/apache/spark/sql/hive/InsertSuite.scala
##########
@@ -870,4 +871,68 @@ class InsertSuite extends QueryTest with TestHiveSingleton with BeforeAndAfter
assert(e.contains("Partition spec is invalid"))
}
}
+
+ test("Insert data with different cases") {
Review comment:
Add `SPARK-35531` prefix to test name?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] opensky142857 commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
opensky142857 commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r649826784
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
org/apache/spark/sql/hive/client/HiveClient.scala
final def getPartitions(
db: String,
table: String,
partialSpec: Option[TablePartitionSpec]): Seq[CatalogTablePartition] = {
getPartitions(getTable(db, table), partialSpec)
}
in this method, we get table from metasotre and pass it into getPartitions
and then call toHiveTable to convert a catalog table into HiveTable.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r648071228
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
Sorry I still can't understand how the bug happens.
In this `toHiveTable` method, the input `CatalogTable` should guarantee sanity: the partition/bucket column names should match the schema.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] opensky142857 commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
opensky142857 commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r647917500
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
Review comment:
yes
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r721854539
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
@AngersZhuuuu can you take this over?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] opensky142857 commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
opensky142857 commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r651415220
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
this convertion is not unnecessary since the hive client interface require a CatalogTable.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] github-actions[bot] closed pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #32675:
URL: https://github.com/apache/spark/pull/32675
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r657699288
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
catalogTable->HiveTable is fine, as long as the catalogTable is correctly initialized. The problem I see here is, we get catalogTable by `HiveClient.getTable` which doesn't go through the intialization logic in `HiveExternalCatalog`
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] opensky142857 commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
opensky142857 commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-857337063
> > the table schema will be stored as lower cases while bucket column info will stay the same with user input.
>
> I'm not sure this is true. Table schema and bucketed columns are both stored in the Spark-specific table properties which are case-preserving.
the schema here comes from metastore when we call methods like 'getRawTableOption' and the Spark schema info in properties don't overwrite the schema field in those cases.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] github-actions[bot] commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-932837590
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
wangyum commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-851195220
@cloud-fan I hive add stacktrace to PR description.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r651991064
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
Can we change the hive client interface? For example
```
trait HiveClient {
def getRawTableOption(dbName: String, tableName: String): Option[HiveTable]
final def getTableOption(dbName: String, tableName: String): Option[CatalogTable] = {
getRawTableOption(dbName, tableName).map(convertHiveTableToCatalogTable)
}
...
def getPartitionOption(
table: HiveTable,
spec: TablePartitionSpec): Option[CatalogTablePartition] = {
getPartitions(getRawTable(db, table), partialSpec)
}
...
}
```
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
wangyum commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r641220214
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,28 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def convertColumnNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map(name => {
+ val s = schema.find(col => col.name.equalsIgnoreCase(name))
+ if (s.isDefined) {
+ s.get.name
+ } else {
+ name
+ }
+ })
+ }
Review comment:
Rewrite `convertColumnNames`?
```scala
def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
names.map { name =>
schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
}
}
```
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r649841292
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
So there is a necessary hive table -> `CatalogTable` -> hive table convertion?
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
So there is a unnecessary hive table -> `CatalogTable` -> hive table convertion?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-851243531
> the table schema will be stored as lower cases while bucket column info will stay the same with user input.
I'm not sure this is true. Table schema and bucketed columns are both stored in the Spark-specific table properties which are case-preserving.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-848577388
Can one of the admins verify this patch?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AngersZhuuuu commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
AngersZhuuuu commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r721855848
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
> @AngersZhuuuu can you take this over?
Sure.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] opensky142857 commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
opensky142857 commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r657610011
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+ hiveTable.setBucketCols(
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.bucketColumnNames).toList.asJava)
if (bucketSpec.sortColumnNames.nonEmpty) {
hiveTable.setSortCols(
- bucketSpec.sortColumnNames
+ restoreHiveBucketSpecColNames(table.schema, bucketSpec.sortColumnNames)
Review comment:
this is not the only place that have this issue. if we set spark.sql.statistics.size.autoUpdate.enabled=true, you can see this issue as well. for alter table, we have to do a catalogTable->HiveTable conversion
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r642254313
##########
File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
hiveTable.setViewExpandedText(t)
}
+ // hive may convert schema into lower cases while bucketSpec will not
+ // only convert if case not match
+ def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): Seq[String] = {
+ names.map { name =>
+ schema.find(col => SQLConf.get.resolver(col.name, name)).map(_.name).getOrElse(name)
+ }
+ }
+
table.bucketSpec match {
case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
hiveTable.setNumBuckets(bucketSpec.numBuckets)
- hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
Review comment:
To clarify: `hiveTable.setFields` lower-cases the column names, but `hiveTable.setBucketCols` does not. And this causes the exception?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum edited a comment on pull request #32675: [SPARK-35531][SQL] Can not insert into hive bucket table if create table with upper case schema
Posted by GitBox <gi...@apache.org>.
wangyum edited a comment on pull request #32675:
URL: https://github.com/apache/spark/pull/32675#issuecomment-851195220
@cloud-fan I have added the stacktrace to PR description.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org