-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28293][SQL] Implement Spark's own GetTableTypesOperation #25073
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 1 commit
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.thriftserver | ||
|
|
||
| import java.util.UUID | ||
|
|
||
| import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType | ||
| import org.apache.hive.service.cli._ | ||
| import org.apache.hive.service.cli.operation.GetTableTypesOperation | ||
| import org.apache.hive.service.cli.session.HiveSession | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.SQLContext | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogTableType | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogTableType._ | ||
| import org.apache.spark.sql.hive.thriftserver.HiveThriftServer2.listener | ||
| import org.apache.spark.util.{Utils => SparkUtils} | ||
|
|
||
| /** | ||
| * Spark's own GetTableTypesOperation | ||
| * | ||
| * @param sqlContext SQLContext to use | ||
| * @param parentSession a HiveSession from SessionManager | ||
| */ | ||
| private[hive] class SparkGetTableTypesOperation( | ||
| sqlContext: SQLContext, | ||
| parentSession: HiveSession) | ||
| extends GetTableTypesOperation(parentSession) with Logging { | ||
|
|
||
| override def runInternal(): Unit = { | ||
| val statementId = UUID.randomUUID().toString | ||
| val logMsg = s"Listing table types" | ||
| logInfo(s"$logMsg with $statementId") | ||
| setState(OperationState.RUNNING) | ||
| // Always use the latest class loader provided by executionHive's state. | ||
| val executionHiveClassLoader = sqlContext.sharedState.jarClassLoader | ||
| Thread.currentThread().setContextClassLoader(executionHiveClassLoader) | ||
|
|
||
| if (isAuthV2Enabled) { | ||
| authorizeMetaGets(HiveOperationType.GET_TABLETYPES, null) | ||
| } | ||
|
|
||
| listener.onStatementStart( | ||
| statementId, | ||
| parentSession.getSessionHandle.getSessionId.toString, | ||
| logMsg, | ||
| statementId, | ||
| parentSession.getUsername) | ||
|
|
||
| try { | ||
| CatalogTableType.tableTypes.foreach { tableType => | ||
| if (tableType == EXTERNAL || tableType == EXTERNAL) { | ||
| rowSet.addRow(Array[AnyRef]("TABLE")) | ||
|
||
| } else if (tableType == VIEW) { | ||
| rowSet.addRow(Array[AnyRef](tableType.name)) | ||
| } else { | ||
| logError(s"Unknown table type: ${tableType.name}") | ||
| } | ||
| } | ||
| setState(OperationState.FINISHED) | ||
| } catch { | ||
| case e: HiveSQLException => | ||
| setState(OperationState.ERROR) | ||
| listener.onStatementError(statementId, e.getMessage, SparkUtils.exceptionString(e)) | ||
| throw e | ||
| } | ||
| listener.onStatementFinish(statementId) | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,13 @@ import java.util.{List => JList, Map => JMap} | |
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| import org.apache.hive.service.cli._ | ||
| import org.apache.hive.service.cli.operation.{ExecuteStatementOperation, GetColumnsOperation, GetSchemasOperation, MetadataOperation, Operation, OperationManager} | ||
| import org.apache.hive.service.cli.operation._ | ||
| import org.apache.hive.service.cli.session.HiveSession | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.SQLContext | ||
| import org.apache.spark.sql.hive.HiveUtils | ||
| import org.apache.spark.sql.hive.thriftserver.{ReflectionUtils, SparkExecuteStatementOperation, SparkGetColumnsOperation, SparkGetSchemasOperation, SparkGetTablesOperation} | ||
| import org.apache.spark.sql.hive.thriftserver._ | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| /** | ||
|
|
@@ -108,6 +108,17 @@ private[thriftserver] class SparkSQLOperationManager() | |
| operation | ||
| } | ||
|
|
||
| override def newGetTableTypesOperation( | ||
| parentSession: HiveSession): GetTableTypesOperation = synchronized { | ||
| val sqlContext = sessionToContexts.get(parentSession.getSessionHandle) | ||
| require(sqlContext != null, s"Session handle: ${parentSession.getSessionHandle} has not been" + | ||
| s" initialized or had already closed.") | ||
|
||
| val operation = new SparkGetTableTypesOperation(sqlContext, parentSession) | ||
| handleToOperation.put(operation.getHandle, operation) | ||
| logDebug(s"Created GetTableTypesOperation with session=$parentSession.") | ||
| operation | ||
| } | ||
|
|
||
| def setConfMap(conf: SQLConf, confMap: java.util.Map[String, String]): Unit = { | ||
| val iterator = confMap.entrySet().iterator() | ||
| while (iterator.hasNext) { | ||
|
|
||
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.
nit ..
s.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.
OK. Thank you.