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 2019/06/20 09:02:48 UTC

[GitHub] [spark] juliuszsompolski commented on a change in pull request #24906: [SPARK-28104][SQL][test-hadoop3.2] Implement Spark's own GetColumnsOperation

juliuszsompolski commented on a change in pull request #24906: [SPARK-28104][SQL][test-hadoop3.2] Implement Spark's own GetColumnsOperation
URL: https://github.com/apache/spark/pull/24906#discussion_r295710265
 
 

 ##########
 File path: sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetColumnsOperation.scala
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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 java.util.regex.Pattern
+
+import scala.collection.JavaConverters.seqAsJavaListConverter
+
+import org.apache.hadoop.hive.ql.security.authorization.plugin.{HiveOperationType, HivePrivilegeObject}
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject.HivePrivilegeObjectType
+import org.apache.hive.service.cli._
+import org.apache.hive.service.cli.operation.GetColumnsOperation
+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.TableIdentifier
+import org.apache.spark.sql.catalyst.catalog.SessionCatalog
+import org.apache.spark.sql.hive.thriftserver.ThriftserverShimUtils.toJavaSQLType
+
+/**
+ * Spark's own SparkGetColumnsOperation
+ *
+ * @param sqlContext SQLContext to use
+ * @param parentSession a HiveSession from SessionManager
+ * @param catalogName catalog name. NULL if not applicable.
+ * @param schemaName database name, NULL or a concrete database name
+ * @param tableName table name
+ * @param columnName column name
+ */
+private[hive] class SparkGetColumnsOperation(
+    sqlContext: SQLContext,
+    parentSession: HiveSession,
+    catalogName: String,
+    schemaName: String,
+    tableName: String,
+    columnName: String)
+  extends GetColumnsOperation(parentSession, catalogName, schemaName, tableName, columnName)
+    with Logging {
+
+  val catalog: SessionCatalog = sqlContext.sessionState.catalog
+
+  private var statementId: String = _
+
+  override def runInternal(): Unit = {
+    statementId = UUID.randomUUID().toString
+    logInfo(s"Getting columns 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)
+
+    val schemaPattern = convertSchemaPattern(schemaName)
+    val tablePattern = convertIdentifierPattern(tableName, true)
+
+    var columnPattern: Pattern = null
+    if (columnName != null) {
+      columnPattern = Pattern.compile(convertIdentifierPattern(columnName, false))
+    }
+
+    val db2Tabs = catalog.listDatabases(schemaPattern).map { dbName =>
+      (dbName, catalog.listTables(dbName, tablePattern))
+    }.toMap
 
 Review comment:
   BTW: I believe that this doesn't take the global temp views into account.
   I think it could be solved by
   ```
       val matchingDbs = {
         val databases = catalog.listDatabases(schemaPattern)
         // Add global temp view schema if matches
         val databasePattern = Pattern.compile(CLIServiceUtils.patternToRegex(sparkSchemaName))
         if (databasePattern.matcher(catalog.globalTempViewManager.database).matches()) {
           databases :+ catalog.globalTempViewManager.database
         } else {
           databases
         }
       }
   ```
   (same problem seems to exist in SparkGetTablesOperation)

----------------------------------------------------------------
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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org