ODBC Driver for Apache Hive

Build 22.0.8462

Batch Processing

The CData ODBC Driver for Apache Hive offers bulk load support in Apache Hive through the ODBC Batch API. The driver can execute related SQL data manipulation statements simultaneously by translating them into a single bulk API request. In your application's code, the driver executes statements based on an array of inputs and a parameterized query.

Batch Update Procedure

Complete the following steps to execute a batch update:

  1. Define arrays of column values for each parameter in the statement.
  2. Set the SQL_ATTR_PARAMSET_SIZE statement attribute.
  3. Bind each array to each parameter.
  4. Execute the parameterized statement.

Bulk Insert

The following code shows how to execute a bulk insert with SQLSetStmtAttr, SQLBindParameter, and SQLExecDirect:

SQLHSTMT pHstmt = NULL;
const int MAX_INSERT_COUNT = 2;
const int MAX_BUFFER_SIZE = 100;
char CompanyNameArray[MAX_INSERT_COUNT][MAX_BUFFER_SIZE] = { 0 };
SQLLEN cbCompanyNameArray[MAX_INSERT_COUNT] = { 0 };
...
retcode = SQLSetStmtAttr(pHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)MAX_INSERT_COUNT, 0);
char *CompanyName1 = "John Deere", *CompanyName2 = "RSSBus Inc.";
cbCompanyNameArray[0] = strlen(CompanyName1);
cbCompanyNameArray[1] = strlen(CompanyName2);
memcpy(CompanyNameArray[0], CompanyName1, strlen(CompanyName1));
memcpy(CompanyNameArray[1], CompanyName2, strlen(CompanyName2));
retcode = SQLBindParameter(pHstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, CompanyNameArray, MAX_BUFFER_SIZE, cbCompanyNameArray);

retcode = SQLExecDirect(pHstmt, (SQLCHAR*) "INSERT INTO [CData].[Default].Customers (CompanyName) VALUES(?)", SQL_NTS); 

Bulk Delete

An array of the primary keys of the records to delete must be specified. The following code shows how to execute a bulk delete with SQLSetStmtAttr, SQLBindParameter, and SQLExecDirect:

 
SQLHSTMT pHstmt = NULL;
const int MAX_DELETE_COUNT = 2;
const int MAX_BUFFER_SIZE = 100;
char _idArray[MAX_DELETE_COUNT][MAX_BUFFER_SIZE] = { 0 };
SQLLEN cb_idArray[MAX_DELETE_COUNT] = { 0 };
...
retcode = SQLSetStmtAttr(pHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)MAX_DELETE_COUNT, 0);
char *_id1 = "_id1", *_id2 = "_id2";
cb_idArray[0] = strlen(_id1);
cb_idArray[1] = strlen(_id2);
memcpy(_idArray[0], _id1, strlen(_id1));
memcpy(_idArray[1], _id2, strlen(_id2));
retcode = SQLBindParameter(pHstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, _idArray, MAX_BUFFER_SIZE, cb_idArray);

retcode = SQLExecDirect(pHstmt, (SQLCHAR*) "DELETE FROM [CData].[Default].Customers WHERE _id = ?", SQL_NTS); 

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462