Hive Connection¶
Bases: DBConnection
Spark connection with Hive MetaStore support.
See also
Before using this connector please take into account Hive prerequisites
Added in 0.1.0
Parameters:
-
cluster(str) –Cluster name. Used for HWM and lineage.
Added in 0.7.0
-
spark(SparkSession) –Spark session with Hive metastore support enabled
Examples:
Execute kinit consome command before creating Spark Session
$ kinit -kt /path/to/keytab user
from onetl.connection import Hive
from pyspark.sql import SparkSession
# Create Spark session
spark = (
SparkSession.builder.appName("spark-app-name")
.option("spark.kerberos.access.hadoopFileSystems", "hdfs://cluster.name.node:8020")
.option("spark.kerberos.principal", "user")
.option("spark.kerberos.keytab", "/path/to/keytab")
.enableHiveSupport()
.getOrCreate()
)
# Create connection
hive = Hive(cluster="rnd-dwh", spark=spark).check()
from onetl.connection import Hive
from pyspark.sql import SparkSession
# Create Spark session
spark = SparkSession.builder.appName("spark-app-name").enableHiveSupport().getOrCreate()
# Create connection
hive = Hive(cluster="rnd-dwh", spark=spark).check()
get_current(spark)
classmethod
¶
Create connection for current cluster.
Note
Can be used only if there are some hooks bound to Slots.get_current_cluster slot.
Added in 0.7.0
Parameters:
-
spark(SparkSession) –Spark session
Examples:
from onetl.connection import Hive
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("spark-app-name").enableHiveSupport().getOrCreate()
# injecting current cluster name via hooks mechanism
hive = Hive.get_current(spark=spark)