Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5851#discussion_r29545181
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/ClientInterface.scala 
---
    @@ -0,0 +1,149 @@
    +/*
    + * 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.spark.sql.catalyst.analysis.NoSuchTableException
    +
    +case class HiveDatabase(
    +    name: String,
    +    location: String)
    +
    +abstract class TableType { val name: String }
    +case object ExternalTable extends TableType { override val name = 
"EXTERNAL_TABLE" }
    +case object IndexTable extends TableType { override val name = 
"INDEX_TABLE" }
    +case object ManagedTable extends TableType { override val name = 
"MANAGED_TABLE" }
    +case object VirtualView extends TableType { override val name = 
"VIRTUAL_VIEW" }
    +
    +case class HiveStorageDescriptor(
    +    location: String,
    +    inputFormat: String,
    +    outputFormat: String,
    +    serde: String)
    +
    +case class HivePartition(
    +    values: Seq[String],
    +    storage: HiveStorageDescriptor)
    +
    +case class HiveColumn(name: String, hiveType: String, comment: String)
    +case class HiveTable(
    +    specifiedDatabase: Option[String],
    +    name: String,
    +    schema: Seq[HiveColumn],
    +    partitionColumns: Seq[HiveColumn],
    +    properties: Map[String, String],
    +    serdeProperties: Map[String, String],
    +    tableType: TableType,
    +    location: Option[String] = None,
    +    inputFormat: Option[String] = None,
    +    outputFormat: Option[String] = None,
    +    serde: Option[String] = None) {
    +
    +  @transient
    +  private[client] var client: ClientInterface = _
    +
    +  private[client] def withClient(ci: ClientInterface): this.type = {
    +    client = ci
    +    this
    +  }
    +
    +  def database: String = specifiedDatabase.getOrElse(sys.error("database 
not resolved"))
    +
    +  def isPartitioned: Boolean = partitionColumns.nonEmpty
    +
    +  def getAllPartitions: Seq[HivePartition] = client.getAllPartitions(this)
    +
    +  // Hive does not support backticks when passing names to the client.
    +  def qualifiedName: String = s"$database.$name"
    +}
    +
    +/**
    + * An externally visible interface to the Hive client.  This interface is 
shared across both the
    + * internal and external classloaders for a given version of Hive and thus 
must expose only
    + * shared classes.
    + */
    +trait ClientInterface {
    +  /**
    +   * Runs a HiveQL command using Hive, returning the results as a list of 
strings.  Each row will
    +   * result in one string.
    +   */
    +  def runSqlHive(sql: String): Seq[String]
    +
    +  /** Returns the names of all tables in the given database. */
    +  def listTables(dbName: String): Seq[String]
    +
    +  /** Returns the name of the active database. */
    +  def currentDatabase: String
    +
    +  /** Returns the metadata for specified database, throwing an exception 
if it doesn't exist */
    +  def getDatabase(name: String): HiveDatabase = {
    +    getDatabaseOption(name).getOrElse(sys.error(s"No such database $name"))
    --- End diff --
    
    should we create a NoSuchDatabaseException and use it here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to