Batch Processing
The CData ODBC Driver for Amazon Athena offers bulk load support in Amazon Athena 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:
- Define arrays of column values for each parameter in the statement.
- Set the SQL_ATTR_PARAMSET_SIZE statement attribute.
- Bind each array to each parameter.
- 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 TotalDueArray[MAX_INSERT_COUNT][MAX_BUFFER_SIZE] = { 0 };
SQLLEN cbTotalDueArray[MAX_INSERT_COUNT] = { 0 };
...
retcode = SQLSetStmtAttr(pHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)MAX_INSERT_COUNT, 0);
char *TotalDue1 = "Jon Doe", *TotalDue2 = "'John', 4";
cbTotalDueArray[0] = strlen(TotalDue1);
cbTotalDueArray[1] = strlen(TotalDue2);
memcpy(TotalDueArray[0], TotalDue1, strlen(TotalDue1));
memcpy(TotalDueArray[1], TotalDue2, strlen(TotalDue2));
retcode = SQLBindParameter(pHstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, TotalDueArray, MAX_BUFFER_SIZE, cbTotalDueArray);
retcode = SQLExecDirect(pHstmt, (SQLCHAR*) "INSERT INTO [AwsDataCatalog].[sampledb].Customers (TotalDue) VALUES (?)", SQL_NTS);