-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17992][SQL] Return all partitions from HiveShim when Hive throws a metastore exception when attempting to fetch partitions by filter #15673
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
Closed
mallman
wants to merge
4
commits into
apache:master
from
VideoAmp:spark-17992-catch_hive_partition_filter_exception
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
212b416
[SPARK-17992][SQL] Return all partitions from HiveShim when Hive throws
f5d0186
Update the warning message to clarify that we will fall back to fetching
4de1596
Throw an exception with a specific message if getPartitionsByFilter
8d468ac
Revise the warning/error messages
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientBuilder.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * 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.client | ||
|
|
||
| import java.io.File | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.util.VersionInfo | ||
|
|
||
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| private[client] class HiveClientBuilder { | ||
| private val sparkConf = new SparkConf() | ||
|
|
||
| // In order to speed up test execution during development or in Jenkins, you can specify the path | ||
| // of an existing Ivy cache: | ||
| private val ivyPath: Option[String] = { | ||
| sys.env.get("SPARK_VERSIONS_SUITE_IVY_PATH").orElse( | ||
| Some(new File(sys.props("java.io.tmpdir"), "hive-ivy-cache").getAbsolutePath)) | ||
| } | ||
|
|
||
| private def buildConf() = { | ||
| lazy val warehousePath = Utils.createTempDir() | ||
| lazy val metastorePath = Utils.createTempDir() | ||
| metastorePath.delete() | ||
| Map( | ||
| "javax.jdo.option.ConnectionURL" -> s"jdbc:derby:;databaseName=$metastorePath;create=true", | ||
| "hive.metastore.warehouse.dir" -> warehousePath.toString) | ||
| } | ||
|
|
||
| def buildClient(version: String, hadoopConf: Configuration): HiveClient = { | ||
| IsolatedClientLoader.forVersion( | ||
| hiveMetastoreVersion = version, | ||
| hadoopVersion = VersionInfo.getVersion, | ||
| sparkConf = sparkConf, | ||
| hadoopConf = hadoopConf, | ||
| config = buildConf(), | ||
| ivyPath = ivyPath).createClient() | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * 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.client | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.hive.conf.HiveConf | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.catalyst.catalog._ | ||
| import org.apache.spark.sql.catalyst.expressions.{AttributeReference, EqualTo, Literal} | ||
| import org.apache.spark.sql.hive.HiveUtils | ||
| import org.apache.spark.sql.types.IntegerType | ||
|
|
||
| class HiveClientSuite extends SparkFunSuite { | ||
| private val clientBuilder = new HiveClientBuilder | ||
|
|
||
| private val tryDirectSqlKey = HiveConf.ConfVars.METASTORE_TRY_DIRECT_SQL.varname | ||
|
|
||
| test(s"getPartitionsByFilter returns all partitions when $tryDirectSqlKey=false") { | ||
| val testPartitionCount = 5 | ||
|
|
||
| val storageFormat = CatalogStorageFormat( | ||
| locationUri = None, | ||
| inputFormat = None, | ||
| outputFormat = None, | ||
| serde = None, | ||
| compressed = false, | ||
| properties = Map.empty) | ||
|
|
||
| val hadoopConf = new Configuration() | ||
| hadoopConf.setBoolean(tryDirectSqlKey, false) | ||
| val client = clientBuilder.buildClient(HiveUtils.hiveExecutionVersion, hadoopConf) | ||
| client.runSqlHive("CREATE TABLE test (value INT) PARTITIONED BY (part INT)") | ||
|
|
||
| val partitions = (1 to testPartitionCount).map { part => | ||
| CatalogTablePartition(Map("part" -> part.toString), storageFormat) | ||
| } | ||
| client.createPartitions( | ||
| "default", "test", partitions, ignoreIfExists = false) | ||
|
|
||
| val filteredPartitions = client.getPartitionsByFilter(client.getTable("default", "test"), | ||
| Seq(EqualTo(AttributeReference("part", IntegerType)(), Literal(3)))) | ||
|
|
||
| assert(filteredPartitions.size == testPartitionCount) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@mallman sorry to disturb you here, but what is the reason that when direct sql isn't set only a warning is logged?and why when direct sql is set a runtime exception is being raised instead of just a warning like no direct sql case?
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.
Hi @rezasafi
I believe the reasoning is if the user has disabled direct sql, we will try to fetch the partitions for the requested partition predicate anyway. However, since we don't expect that call to succeed, we just log a warning and fallback to the legacy behavior.
On the other hand, if the user has enabled direct sql, then we expect the call to Hive to succeed. If it fails, we consider that an error and throw an exception.
I hope that helps clarify things.
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.
Thank you very much for the explanation @mallman. I appreciate it.
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.
@mallman Your assumption is incorrect. If Hive on direct sql fails, it will retry with ORM. So in this case, I am able to reproduce a issue with postgres where direct sql fails and if it retries with ORM, spark fails! Hive has fallback behavior for direct sql.
Filed SPARK-25561