juliuszsompolski commented on a change in pull request #25073: [SPARK-28293][SQL] Implement Spark's own GetTableTypesOperation URL: https://github.com/apache/spark/pull/25073#discussion_r301017350
########## File path: sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetTableTypesOperation.scala ########## @@ -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")) Review comment: I think you meant (tableType == EXTERNAL || tableType == MANAGED), but then you want to add "TABLE" to the results only once. I think you want `tableTypes.foreach { tableType => tableTypeString(tableType) }.toSet.foreach { type => rowset.addRow(Array[AnyRef](type) }` tableTypeString can be shared with SparkGetTablesOperation. To share some such functions between the operatoins, how about a mixin utils trait ``` trait SparkOperationUtils { this: Operation => def tableTypeString(tableType: CatalogTableType) = ... } ``` e.g. at the bottom of `SparkSQLOperationManager.scala`? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
