io.eels.component.hive.HiveDatabase.scala Maven / Gradle / Ivy
The newest version!
package io.eels.component.hive
import org.apache.hadoop.fs.FileSystem
import org.apache.hadoop.hive.metastore.IMetaStoreClient
import scala.collection.JavaConverters._
class HiveContext(implicit fs: FileSystem, client: IMetaStoreClient) {
def databases: Seq[HiveDatabase] = client.getAllDatabases.asScala.map { dbName => HiveDatabase(dbName) }
}
case class HiveDatabase(dbName: String)(implicit fs: FileSystem, client: IMetaStoreClient) {
def tables(): List[HiveSource] = {
val tables = client.getAllTables(dbName).asScala
tables.map { it => HiveSource(dbName, it) }.toList
}
def table(tableName: String): HiveSource = {
val exists = client.tableExists(dbName, tableName)
if (!exists)
throw new IllegalArgumentException(s"$dbName.$tableName does not exist")
HiveSource(dbName, tableName)
}
def location: String = client.getDatabase(dbName).getLocationUri
}