kudu 查看元数据信息

package com.lala.lala.pipe.dbinfo

import org.apache.kudu.client.KuduClient

import com.lala.lala.common.query.option.KuduOptions
import collection.JavaConverters._
import scala.util.Try

class KuduShow(map: Map[String, String]) {
  private val master = map(KuduOptions.KUDU_MASTER)
  private lazy val tableName = map(KuduOptions.TBL)
  private val client = KuduShow.getClient(master)

  def getTbs: String = Try(client.getTablesList.getTablesList.asScala.mkString(",")).getOrElse("master错误或网络不可用")

  def getCols: String = {
    val table = client.openTable(tableName)
    table.getSchema
      .getColumns.asScala
      .map(col => s"${col.getName}:${col.getType.getName}")
      .mkString(",")
  }
}

object KuduShow {
  var client: KuduClient = null

  def getClient(master: String): KuduClient = {
    if (client == null || master != client.getMasterAddressesAsString) {
      client = new KuduClient.KuduClientBuilder(master).build
    }
    client
  }

}

 

你可能感兴趣的:(kudu 查看元数据信息)