-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29869][SQL] improve error message in HiveMetastoreCatalog#convertToLogicalRelation #26499
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 8 commits
dd1efc8
1071b50
1c98c38
363afb6
46c16c0
1df7b8d
9f29abc
ad71656
2efaafc
3288ffd
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 |
|---|---|---|
|
|
@@ -257,8 +257,20 @@ private[hive] class HiveMetastoreCatalog(sparkSession: SparkSession) extends Log | |
| } | ||
| // The inferred schema may have different field names as the table schema, we should respect | ||
| // it, but also respect the exprId in table relation output. | ||
| assert(result.output.length == relation.output.length && | ||
| result.output.zip(relation.output).forall { case (a1, a2) => a1.dataType == a2.dataType }) | ||
| if (result.output.length != relation.output.length) { | ||
| throw new HiveTableConvertException( | ||
| s"Converted table has ${result.output.length} columns, " + | ||
| s"but source Hive table has ${relation.output.length} columns. " + | ||
| s"Set ${HiveUtils.CONVERT_METASTORE_PARQUET.key} to false, " + | ||
| s"or recreate table ${relation.tableMeta.identifier} to workaround.") | ||
| } | ||
| if (!result.output.zip(relation.output).forall { | ||
| case (a1, a2) => a1.dataType.sameType(a2.dataType) }) { | ||
|
||
| throw new HiveTableConvertException( | ||
| s"Column in converted table has different data type with source Hive table's. " + | ||
| s"Set ${HiveUtils.CONVERT_METASTORE_PARQUET.key} to false, " + | ||
| s"or recreate table ${relation.tableMeta.identifier} to workaround.") | ||
| } | ||
LantaoJin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val newOutput = result.output.zip(relation.output).map { | ||
| case (a1, a2) => a1.withExprId(a2.exprId) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.hive | ||
|
|
||
| import org.apache.spark.SparkException | ||
|
|
||
| private[hive] case class HiveTableConvertException(message: String) | ||
| extends SparkException(message) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -358,4 +358,24 @@ class DataSourceWithHiveMetastoreCatalogSuite | |
| Seq(table("src").count().toString)) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-29869: Fix convertToLogicalRelation throws unclear AssertionError") { | ||
| withTempPath(dir => { | ||
| val baseDir = s"${dir.getCanonicalFile.toURI.toString}/non_partition_table" | ||
| val partitionLikeDir = s"$baseDir/dt=20191113" | ||
| spark.range(3).selectExpr("id").write.parquet(partitionLikeDir) | ||
| withTable("non_partition_table") { | ||
| withSQLConf(HiveUtils.CONVERT_METASTORE_PARQUET.key -> "true") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TABLE non_partition_table (id bigint) | ||
|
Contributor
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. Isn't it a malformed table? Does hive ignore the directories for non-partitioned tables?
Contributor
Author
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. Seems Hive return none when query this table(1.2.1):
But no assertion error
Contributor
Author
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. Maybe you are right. Actually the table LOCATION is So should I revert the code changes and only keep the assert detail information? Or throws exception instead of assertion, and catch it then rollback to do not use built-in Parquet reader to read? |
||
| |STORED AS PARQUET LOCATION '$baseDir' | ||
| |""".stripMargin) | ||
| val e = intercept[HiveTableConvertException]( | ||
| spark.table("non_partition_table"), Seq()).getMessage | ||
|
||
| assert(e.contains("Converted table has 2 columns, but source Hive table has 1 columns.")) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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 just throw AnalysisException? It's not in the runtime stage yet.