JDBC Storage Handler for Hive is a storage handling feature of WSO2 BAM. This page describes the usage of Hive JDBC Storage Handler with its basic functionality. Currently It supports writing into any database and reading from major databases (MySQL, Microsoft SQL, Oracle, H2, PostgreSQL).
Setting up BAM to use Hive JDBC handler
- Obtain the jdbc-driver JAR file that is shipped with the respective database type you use.
- Add the jdbc-driver to
<BAM_HOME>/repository/component/lib/directory, before starting the server.
Below is a sample Hive query, which uses the JDBC Storage Handler to call and connect to the specified database, and store the query results in it.
Storage handler table properties
Following are the properties that can be defined under
TBLPROPERTIES in a Hive query, which uses the Hive JDBC Storage Handler:
|Yes||The classname for the JDBC Driver to use. This should be available on Hive's classpath.|
|Yes||The connection URL for the database.|
|Yes||Whetehr you have any primary keys in the database table.|
|No||The username to access the database, if it's required.|
|mapred.jdbc.password||No||The password to access the database, if it's required.|
|No||If the table already exists in the database, then you don't need this. Else, provide the SQL query for creating the table in the database.|
|No||The name of the table in the database. It need not be the same as the name of the table in Hive. If you specified the SQL query for creating the table, handler will pick the table name from the query. Otherwise, if your meta table name is different from the table in database, specify this.|
|No||Enter either true or false as the value. If true is entered, then the storage handler will update the records with duplicate keys. Otherwise it will insert all the data.|
This is used to optimize the update operation. The default implementation is to use either insert or update statements after the select statement. Therefore, there will be two database round trips. But we can reduce it to one, by using database specific upsert statements.
For Example a query for a MySQL database is:
If you are using an upsert query, then this is mandatory. Sample values for the above query will be:
This is mandatory if your field names in the meta table and database tables are different. P rovide the field names in the database table in the same order as the field names in meta table with ',' separated values.
These will map to your meta table with
|No||Used when reading from a database table. This is needed if the meta table name and database table name are different.|