Hive Warehouse Connector 2.1 and 2.0 APIs in Azure HDInsight
This article lists all the APIs supported by Hive warehouse connector 2.1 and 2.0. All the examples shown are how to run using spark-shell and hive warehouse connector session.
How to create Hive warehouse connector session:
import com.hortonworks.hwc.HiveWarehouseSession
val hive = HiveWarehouseSession.session(spark).build()
// Creates a bucketed table,
// Parameters are numOfBuckets (integer) followed by column names for bucketing
createTableBuilder = createTableBuilder.clusterBy(numOfBuckets, "", .... , "")
// Creates the table
createTableBuilder.create()
Note
This API creates an ORC formatted table at default location. For other features/options or to create table using hive queries, use executeUpdate API.
Read a table
// Returns a Dataset that contains data of in the current database
hive.table("")
Execute DDL commands on HiveServer2
// Executes the against HiveServer2
// Returns true or false if the query succeeded or failed respectively
hive.executeUpdate("")
// Executes the against HiveServer2
// Throws exception, if propagateException is true and query threw exception in HiveServer2
// Returns true or false if the query succeeded or failed respectively
hive.executeUpdate("", propagateException) // propagate exception is boolean value
Execute Hive query and load result in Dataset
Executing query via LLAP daemons. [Recommended]
// should be a hive query
hive.executeQuery("")
Executing query through HiveServer2 via JDBC.
Set spark.datasource.hive.warehouse.smartExecution to false in spark configs before starting spark session to use this API
hive.execute("")
Close Hive warehouse connector session
// Closes all the open connections and
// release resources/locks from HiveServer2
hive.close()
Execute Hive Merge query
This API creates a Hive merge query in the format
MERGE INTO . AS USING AS
ON
WHEN MATCHED [AND ] THEN UPDATE SET ...
WHEN MATCHED [AND ] THEN DELETE
WHEN NOT MATCHED [AND ] THEN INSERT VALUES ...
val mergeBuilder = hive.mergeBuilder() // Returns a builder for merge query