You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by go...@apache.org on 2016/03/18 20:02:18 UTC
[1/3] hive git commit: HIVE-13234: Remove dead ODBC driver from Hive
(Gopal V, reviewed by Thejas Nair)
Repository: hive
Updated Branches:
refs/heads/master 586c30441 -> 3468a6661
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/test/hiveclienttest.c
----------------------------------------------------------------------
diff --git a/odbc/src/test/hiveclienttest.c b/odbc/src/test/hiveclienttest.c
deleted file mode 100644
index fbb4e24..0000000
--- a/odbc/src/test/hiveclienttest.c
+++ /dev/null
@@ -1,1395 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <stdint.h>
-#include <string.h>
-#include "hiveclient.h"
-
-/* INSTRUCTIONS:
- * This test suite should have been compiled when 'make' was executed from the
- * base odbc directory as HiveClientTestC before running this test suite, make
- * sure to copy the odbc/testdata/ directory to /tmp/ on the same machine as
- * the Hive Server. To run this test suite, just run the executable: HiveClientTestC.
- */
-
-#define MAX_QUERY_LEN 1024
-#define MAX_FIELD_LEN 255
-
-// Currently all Hive numeric types are signed (64-bit platform specific)
-// but tests should also run in 32-bit mode
-#define MIN_TINYINT -128
-#define MIN_SMALLINT -32768
-#define MIN_INT 0x80000000
-#define MIN_BIGINT 0x8000000000000000
-#define SMALLEST_POS_FLOAT 1.1754944E-38
-#define SMALLEST_POS_DOUBLE 2.225073858507201E-308
-#define MAX_TINYINT 127
-#define MAX_SMALLINT 32767
-#define MAX_INT 0x7FFFFFFF
-#define MAX_BIGINT 0x7FFFFFFFFFFFFFFF
-#define BIGGEST_POS_FLOAT 3.4028235E+38
-#define BIGGEST_POS_DOUBLE 1.797693134862315E+308
-
-// Convert a macro value to a string
-#define STRINGIFY(x) XSTRINGIFY(x)
-#define XSTRINGIFY(x) #x
-
-// Path to test data (should be supplied at compile time)
-#ifdef TEST_DATA_DIR
-#define TEST_DATA_DIR_STR STRINGIFY(TEST_DATA_DIR)
-#else
-#define TEST_DATA_DIR_STR "/tmp/testdata" // Provide a default if not defined
-#endif
-
-/**
- * Checks an error condition, and if true:
- * 1. prints the error to stderr
- * 2. returns the specified ret_val
- */
-#define RETURN_ON_ASSERT_ONE_ARG(condition, err_format, arg, ret_val) { \
- if (condition) { \
- fprintf(stderr, "----LINE %i: ", __LINE__); \
- fprintf(stderr, err_format, arg); \
- return ret_val; \
- } \
-}
-
-/**
- * Checks an error condition, and if true:
- * 1. prints the error to stderr
- * 2. closes the DB connection on db_conn
- * 3. returns the specified ret_val
- */
-#define RETURN_ON_ASSERT_NO_ARG_CLOSE(condition, err_format, db_conn, ret_val) { \
- if (condition) { \
- char error_buffer_[MAX_HIVE_ERR_MSG_LEN]; \
- fprintf(stderr, "----LINE %i: ", __LINE__); \
- fprintf(stderr, err_format); \
- DBCloseConnection(db_conn, error_buffer_, sizeof(error_buffer_)); \
- return ret_val; \
- } \
-}
-#define RETURN_ON_ASSERT_ONE_ARG_CLOSE(condition, err_format, arg, db_conn, ret_val) { \
- if (condition) { \
- char error_buffer_[MAX_HIVE_ERR_MSG_LEN]; \
- fprintf(stderr, "----LINE %i: ", __LINE__); \
- fprintf(stderr, err_format, arg); \
- DBCloseConnection(db_conn, error_buffer_, sizeof(error_buffer_)); \
- return ret_val; \
- } \
-}
-#define RETURN_ON_ASSERT_TWO_ARG_CLOSE(condition, err_format, arg1, arg2, db_conn, ret_val) { \
- if (condition) { \
- char error_buffer_[MAX_HIVE_ERR_MSG_LEN]; \
- fprintf(stderr, "----LINE %i: ", __LINE__); \
- fprintf(stderr, err_format, arg1, arg2); \
- DBCloseConnection(db_conn, error_buffer_, sizeof(error_buffer_)); \
- return ret_val; \
- } \
-}
-
-/**************************************************************************************************
- * HELPER FUNCTIONS
- **************************************************************************************************/
-
-int dummyHiveTypeConverter(HiveType type) {
- return 1; // For testing purposes, just return an arbitrary value
-}
-
-HiveReturn dropTable(HiveConnection* connection, const char* table_name) {
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- HiveReturn retval;
- char query[MAX_QUERY_LEN];
- int has_results;
- HiveResultSet* resultset;
-
- sprintf(query, "DROP TABLE %s", table_name);
- retval = DBExecute(connection, query, &resultset, 10, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, HIVE_ERROR);
-
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, HIVE_ERROR);
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(has_results,
- "Query '%s' generated results\n",
- query, connection, HIVE_ERROR);
-
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, HIVE_ERROR)
-
- return HIVE_SUCCESS;
-}
-
-/**************************************************************************************************
- * TEST FUNCTIONS
- **************************************************************************************************/
-
-int basic_connect_disconnect_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- HiveReturn retval;
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- if (connection == NULL) {
- /* If this fails, make sure that Hive server is running with the connect parameter arguments */
- fprintf(stderr, "Connect failed: %s\n", err_buf);
- fprintf(stderr, "\n\n\nMAKE SURE YOU HAVE THE STANDALONE HIVESERVER RUNNING!\n");
- fprintf(stderr, "Expected Connection Parameters:\n");
- fprintf(stderr, "HOST: %s\n", DEFAULT_HOST);
- fprintf(stderr, "PORT: %s\n", DEFAULT_PORT);
- fprintf(stderr, "DATABASE: %s\n\n\n", DEFAULT_DATABASE);
- assert(connection != NULL);
- }
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "Disconnect failed: %s\n",
- err_buf, 0)
- return 1;
-}
-
-int basic_query_exec_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- HiveResultSet* resultset;
- HiveReturn retval;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- /* If this fails, make sure that Hive server is running with the connect parameter arguments */
- assert(connection != NULL);
-
- retval = DBExecute(connection, "SHOW TABLES", &resultset, 10, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBDisconnect failed: %s\n",
- err_buf, connection, 0);
- return 1;
-}
-
-int basic_fetch_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- int has_results;
- HiveResultSet* resultset;
- HiveReturn retval;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- /* If this fails, make sure that Hive server is running with the connect parameter arguments */
- assert(connection != NULL);
-
- retval = DBExecute(connection, "SHOW TABLES", &resultset, 10, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_SUCCESS && !has_results,
- "DBFetch failed: Row fetched but no results detected\n",
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA && has_results,
- "DBFetch failed: Results detected but no rows fetched\n",
- connection, 0)
-
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBDisconnect failed: %s\n",
- err_buf, connection, 0);
- return 1;
-}
-
-int show_tables_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- const char* table_name = "ehwang_tmp_test";
- HiveReturn retval;
- char query[MAX_QUERY_LEN];
- char field[MAX_FIELD_LEN];
- int has_results;
- size_t col_count;
- size_t col_len;
- size_t data_byte_size;
- int is_null_value;
- HiveResultSet* resultset;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- assert(connection != NULL); /* If this fails, make sure that Hive server is running with the connect parameter arguments */
-
- // Drop pre-existing tables of the same name
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Create the table
- sprintf(query, "CREATE TABLE %s (key int, value string)", table_name);
- retval = DBExecute(connection, query, &resultset, 10, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(has_results,
- "Query '%s' generated results\n",
- query, connection, 0);
-
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
-
- // Test 'show tables' query
- sprintf(query, "SHOW TABLES '%s'", table_name);
- retval = DBExecute(connection, query, &resultset, 10, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(!has_results,
- "Query '%s'could not find table '%s'\n",
- query, table_name, connection, 0);
-
- retval = DBGetColumnCount(resultset, &col_count, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetColumnCount failed: '%s'\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(col_count != 1,
- "Column count not equal to one: %zu\n",
- col_count, connection, 0);
-
- // Fetch row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the only row\n",
- connection, 0);
-
- // Check row data
- retval = DBGetFieldAsCString(resultset, 0, field, sizeof(field), &data_byte_size, &is_null_value,
- err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(field, table_name) != 0,
- "Tables do not have the same name: table_name:%s, field:%s\n",
- table_name, field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 0, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as table_name (%zu)\n",
- col_len, strlen(field), connection, 0);
-
- // Fetch row (check that there is nothing else to fetch)
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "DBFetch failed: Only one row, but fetched two\n",
- connection, 0);
-
- // Clean up table
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Close the handles
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "Disconnect failed: %s\n",
- err_buf, 0)
-
- return 1;
-}
-
-int query_fetch_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- const char* table_name = "ehwang_tmp_test";
- const char* test_data_path = TEST_DATA_DIR_STR "/dataset1.input";
- HiveReturn retval;
- char query[MAX_QUERY_LEN];
- char string_field[MAX_FIELD_LEN];
- int int_field;
- int has_results;
- size_t col_count;
- size_t col_len;
- size_t data_byte_size;
- int is_null_value;
- HiveResultSet* resultset;
- HiveColumnDesc* column_desc;
- HiveType hive_type;
- HiveType expected_hive_type;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- /* If this fails, make sure that Hive server is running with the connect parameter arguments */
- assert(connection != NULL);
-
- // Drop pre-existing tables of the same name
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Create the table
- sprintf(query, "CREATE TABLE %s (key int, value string) STORED AS TEXTFILE", table_name);
- retval = DBExecute(connection, query, NULL, 0, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Load data into the table
- // NOTE: test_data_path has to be local to the hive server
- // NOTE: test_data_path is a ctrl-A separated file with two fields per line
- sprintf(query, "LOAD DATA LOCAL INPATH '%s' INTO TABLE %s", test_data_path, table_name);
- retval = DBExecute(connection, query, NULL, 0, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Run Select * query
- sprintf(query, "SELECT * FROM %s", table_name);
- // max_buf_len value of 1 to test client side result buffer fetching
- retval = DBExecute(connection, query, &resultset, 1, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(!has_results,
- "Query '%s'should have found results in table: '%s'\n",
- query, table_name, connection, 0);
-
- retval = DBGetColumnCount(resultset, &col_count, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetColumnCount failed: '%s'\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(col_count != 2,
- "Column count not equal to two: %zu\n",
- col_count, connection, 0);
-
- // Check HiveType of first column
- retval = DBCreateColumnDesc(resultset, 0, &column_desc, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCreateColumnDesc failed: %s\n",
- err_buf, connection, 0);
- hive_type = DBGetHiveType(column_desc);
- expected_hive_type = HIVE_INT_TYPE;
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(hive_type != expected_hive_type,
- "DBCreateColumnDesc failed: incorrect hive type: %i, expected: %i\n",
- hive_type, expected_hive_type, connection, 0);
-
- retval = DBCloseColumnDesc(column_desc, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseColumnDesc failed: %s\n",
- err_buf, connection, 0);
-
- // Check HiveType of second column
- retval = DBCreateColumnDesc(resultset, 1, &column_desc, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCreateColumnDesc failed: %s\n",
- err_buf, connection, 0);
- hive_type = DBGetHiveType(column_desc);
- expected_hive_type = HIVE_STRING_TYPE;
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(hive_type != expected_hive_type,
- "DBCreateColumnDesc failed: incorrect hive type: %i, expected: %i\n",
- hive_type, expected_hive_type, connection, 0);
-
- retval = DBCloseColumnDesc(column_desc, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseColumnDesc failed: %s\n",
- err_buf, connection, 0);
-
- // Fetch row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the first row\n",
- connection, 0);
-
- // Check first row of data
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "Int field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != 1,
- "Int field for row 1 does not match: expected=%i, recieved=%i\n",
- 1, int_field, connection, 0);
-
- retval = DBGetFieldAsCString(resultset, 1, string_field, sizeof(string_field), &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "String field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(string_field, "foo") != 0,
- "String fields does not match: expected='%s', received='%s'\n",
- "foo", string_field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 1, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(string_field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as expected length (%zu)\n",
- col_len, strlen(string_field), connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(data_byte_size != col_len,
- "DBGetFieldDataLen failed: Returned data_byte_length (%zu) was not the same as the amount written to buffer (%zu)\n",
- data_byte_size, strlen(string_field) + 1, connection, 0);
-
- // Fetch second row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the second row\n",
- connection, 0);
-
- // Check second row of data
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "Int field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != 2,
- "Int field for row 1 does not match: expected=%i, recieved=%i\n",
- 1, int_field, connection, 0);
-
- retval = DBGetFieldAsCString(resultset, 1, string_field, sizeof(string_field), &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "String field for row 2 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(string_field, "bar") != 0,
- "String fields does not match: expected='%s', received='%s'\n",
- "bar", string_field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 1, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(string_field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as expected length (%zu)\n",
- col_len, strlen(string_field), connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(data_byte_size != col_len,
- "DBGetFieldDataLen failed: Returned data_byte_length (%zu) was not the same as the amount written to buffer (%zu)\n",
- data_byte_size, strlen(string_field) + 1, connection, 0);
-
- // Fetch non-existant row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "DBFetch failed: Only 2 rows, but was able to fetch a third...\n",
- connection, 0);
-
- // Clean up table
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Close the handles
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "DBDisconnect failed: %s\n",
- err_buf, 0);
-
- return 1;
-}
-
-int numeric_range_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- const char* table_name = "ehwang_tmp_test";
- const char* test_data_path = TEST_DATA_DIR_STR "/dataset_types.input";
- HiveReturn retval;
- char query[MAX_QUERY_LEN];
- int int_field;
- int64_t I64_field;
- double double_field;
- int is_null_value;
- HiveResultSet* resultset;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- /* If this fails, make sure that Hive server is running with the connect parameter arguments */
- assert(connection != NULL);
-
- // Drop pre-existing tables of the same name
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Create the table
- sprintf(
- query,
- "CREATE TABLE %s (tinyint_type tinyint, smallint_type smallint, int_type int, bigint_type bigint, float_type float, double_type double, null_test int) STORED AS TEXTFILE",
- table_name);
- retval = DBExecute(connection, query, NULL, 0, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Load data into the table
- // NOTE: test_data_path has to be local to the hive server
- // NOTE: test_data_path is a ctrl-A separated file with seven fields per line
- sprintf(query, "LOAD DATA LOCAL INPATH '%s' INTO TABLE %s", test_data_path, table_name);
- retval = DBExecute(connection, query, NULL, 0, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Run Select * query
- sprintf(query, "SELECT * FROM %s", table_name);
- retval = DBExecute(connection, query, &resultset, 1, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Fetch row of minimum numeric values
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the first row\n",
- connection, 0);
-
- // Check first row of minimum numeric values
-
- // Min tinyint field
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "TINYINT field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != MIN_TINYINT,
- "TINYINT field for row 1 does not match: expected=%i, received=%i\n",
- MIN_TINYINT, int_field, connection, 0);
-
- // Min smallint field
- retval = DBGetFieldAsInt(resultset, 1, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "SMALLINT field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != MIN_SMALLINT,
- "SMALLINT field for row 1 does not match: expected=%i, received=%i\n",
- MIN_SMALLINT, int_field, connection, 0);
-
- // Min int field
- retval = DBGetFieldAsInt(resultset, 2, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "INTEGER field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != MIN_INT,
- "INTEGER field for row 1 does not match: expected=%i, received=%i\n",
- MIN_INT, int_field, connection, 0);
-
- // Min bigint field
- retval = DBGetFieldAsI64(resultset, 3, &I64_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsI64 failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "BIGINT field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(I64_field != MIN_BIGINT,
- "BIGINT field for row 1 does not match: expected=%lld, received=%lld\n",
- (long long) MIN_BIGINT, (long long) I64_field, connection, 0);
-
- // Smallest positive float field
- retval
- = DBGetFieldAsDouble(resultset, 4, &double_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsDouble failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "FLOAT field for row 1 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE((float) double_field != (float) SMALLEST_POS_FLOAT,
- "FLOAT field for row 1 does not match: expected=%.17g, received=%.17g\n",
- (float) SMALLEST_POS_FLOAT, (float) double_field, connection, 0);
-
- // Smallest positive double field
- retval
- = DBGetFieldAsDouble(resultset, 5, &double_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,"DBGetFieldAsDouble failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "DOUBLE field for row 1 should not be NULL\n", connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE((double) double_field != (double) SMALLEST_POS_DOUBLE,
- "DOUBLE field for row 1 does not match: expected=%.17g, received=%.17g\n",
- (double) SMALLEST_POS_DOUBLE, (double) double_field, connection, 0);
-
- // NULL field
- retval = DBGetFieldAsInt(resultset, 6, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR, "DBGetFieldAsInt failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(!is_null_value,
- "Field should be NULL\n", connection, 0);
-
- // Fetch row of maximum numeric values
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR, "DBFetch failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA, "DBFetch failed: Could not fetch the second row\n",
- connection, 0);
-
- // Check second row of maximum numeric values
-
- // Max tinyint field
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR, "DBGetFieldAsInt failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "TINYINT field for row 2 should not be NULL\n", connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != MAX_TINYINT,
- "TINYINT field for row 2 does not match: expected=%i, received=%i\n", MAX_TINYINT,
- int_field, connection, 0);
-
- // Max smallint field
- retval = DBGetFieldAsInt(resultset, 1, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR, "DBGetFieldAsInt failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "SMALLINT field for row 2 should not be NULL\n", connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != MAX_SMALLINT,
- "SMALLINT field for row 2 does not match: expected=%i, received=%i\n",
- MAX_SMALLINT, int_field, connection, 0);
-
- // Max int field
- retval = DBGetFieldAsInt(resultset, 2, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR, "DBGetFieldAsInt failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "INTEGER field for row 2 should not be NULL\n", connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_field != MAX_INT,
- "INTEGER field for row 2 does not match: expected=%i, received=%i\n",
- MAX_INT, int_field, connection, 0);
-
- // Max bigint field
- retval = DBGetFieldAsI64(resultset, 3, &I64_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR, "DBGetFieldAsI64 failed: %s\n", err_buf,
- connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "BIGINT field for row 2 should not be NULL\n", connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(I64_field != MAX_BIGINT,
- "BIGINT field for row 2 does not match: expected=%lld, received=%lld\n",
- (long long) MAX_BIGINT, (long long) I64_field, connection, 0);
-
- // Biggest positive float field
- retval
- = DBGetFieldAsDouble(resultset, 4, &double_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsDouble failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "FLOAT field for row 2 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE((float) double_field != (float) BIGGEST_POS_FLOAT,
- "FLOAT field for row 2 does not match: expected=%.17g, received=%.17g\n",
- (float) BIGGEST_POS_FLOAT, (float) double_field, connection, 0);
-
- // Biggest positive double field
- retval
- = DBGetFieldAsDouble(resultset, 5, &double_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsDouble failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(is_null_value,
- "DOUBLE field for row 2 should not be NULL\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE((double) double_field != (double) BIGGEST_POS_DOUBLE,
- "DOUBLE field for row 2 does not match: expected=%.17g, received=%.17g\n",
- (double) BIGGEST_POS_DOUBLE, (double) double_field, connection, 0);
-
- // NULL field
- retval = DBGetFieldAsInt(resultset, 6, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(!is_null_value,
- "Field should be NULL\n",
- connection, 0);
-
- // Clean up table
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Close the handles
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "DBDisconnect failed: %s\n",
- err_buf, 0);
-
- return 1;
-}
-
-int field_multifetch_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- const char* table_name = "ehwang_tmp_test";
- const char* test_data_path = TEST_DATA_DIR_STR "/dataset2.input";
- HiveReturn retval;
- char query[MAX_QUERY_LEN];
- char string_field[MAX_FIELD_LEN];
- size_t data_byte_size;
- int int_field;
- int is_null_value;
- HiveResultSet* resultset;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- /* If this fails, make sure that Hive server is running with the connect parameter arguments */
- assert(connection != NULL);
-
- // Drop pre-existing tables of the same name
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Create the table
- sprintf(query, "CREATE TABLE %s (fixed_len_field int, var_len_field string) STORED AS TEXTFILE",
- table_name);
- retval = DBExecute(connection, query, NULL, 0, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Load data into the table
- // NOTE: test_data_path has to be local to the hive server
- // NOTE: test_data_path is a ctrl-A separated file with two fields per line
- sprintf(query, "LOAD DATA LOCAL INPATH '%s' INTO TABLE %s", test_data_path, table_name);
- retval = DBExecute(connection, query, NULL, 0, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Run Select * query
- sprintf(query, "SELECT * FROM %s", table_name);
- retval = DBExecute(connection, query, &resultset, 1, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Fetch row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the first row\n",
- connection, 0);
-
- // Test multi-fetches on fixed length fields:
- // First fetch
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_SUCCESS,
- "First fetch of a fixed length field should be successful\n",
- connection, 0);
-
- // Second fetch
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "Second consecutive fetch of a fixed length field should return HIVE_NO_MORE_DATA\n",
- connection, 0);
-
- // Third fetch
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "Third consecutive fetch of a fixed length field should return HIVE_NO_MORE_DATA\n",
- connection, 0);
-
- // Test multi-fetches on var length fields:
- // First fetch with sufficient buffer space
- retval = DBGetFieldAsCString(resultset, 1, string_field, sizeof(string_field), &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- /* Length of alphabet string in data */
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(data_byte_size != 26,
- "DBGetFieldAsCString failed: incorrect data_byte_size: expected=%zu, received=%zu\n",
- (size_t) 26, data_byte_size, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_SUCCESS,
- "First fetch of a variable length field with sufficient buffer space should be successful\n",
- connection, 0);
-
- // Second fetch with sufficient buffer space
- retval = DBGetFieldAsCString(resultset, 1, string_field, sizeof(string_field), &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "Second consecutive fetch of a completely fetched variable length field should return HIVE_NO_MORE_DATA\n",
- connection, 0);
-
- // Third fetch with sufficient buffer space
- retval = DBGetFieldAsCString(resultset, 1, string_field, sizeof(string_field), &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "Third consecutive fetch of a completely fetched variable length field should return HIVE_NO_MORE_DATA\n",
- connection, 0);
-
- // Test multi-fetches on fixed length fields after reset column reset:
- // First fetch
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_SUCCESS,
- "First fetch of a fixed length field after a column reset should be successful\n",
- connection, 0);
- // Second fetch
- retval = DBGetFieldAsInt(resultset, 0, &int_field, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "Second consecutive fetch of a fixed length field should always return HIVE_NO_MORE_DATA\n",
- connection, 0);
-
- // Test multi-fetches on var length fields after column reset with insufficient buffer space:
- // First fetch with insufficient buffer space after a column reset
- size_t reduced_buffer_size = 13; // For a source data size of 26 bytes
- retval = DBGetFieldAsCString(resultset, 1, string_field, reduced_buffer_size, &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- /* Length of available alphabet string to return before truncation */
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(data_byte_size != 26,
- "DBGetFieldAsCString failed: incorrect data_byte_size: expected=%zu, received=%zu\n",
- (size_t) 26, data_byte_size, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_SUCCESS_WITH_MORE_DATA,
- "First fetch of a variable length field with insufficient buffer space should return HIVE_SUCCESS_WITH_MORE_DATA\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(string_field, "abcdefghijkl") != 0,
- "Fetched string does not match: expected:%s, received:%s\n",
- "abcdefghijkl", string_field, connection, 0);
-
- // Second fetch with insufficient buffer space
- retval = DBGetFieldAsCString(resultset, 1, string_field, reduced_buffer_size, &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- /* Length of remaining alphabet string to return before truncation */
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(data_byte_size != 14,
- "DBGetFieldAsCString failed: incorrect data_byte_size: expected=%zu, received=%zu\n",
- (size_t) 14, data_byte_size, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_SUCCESS_WITH_MORE_DATA,
- "Second consecutive fetch with still insufficient buffer space should return HIVE_SUCCESS_WITH_MORE_DATA\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(string_field, "mnopqrstuvwx"),
- "Fetched string does not match: expected:%s, received:%s\n",
- "mnopqrstuvwx", string_field, connection, 0);
-
- // Third fetch to obtain the remainder of the buffer data
- retval = DBGetFieldAsCString(resultset, 1, string_field, reduced_buffer_size, &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- /* Length of remaining alphabet string to return before truncation */
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(data_byte_size != 2,
- "DBGetFieldAsCString failed: incorrect data_byte_size: expected=%zu, received=%zu\n",
- (size_t) 2, data_byte_size, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_SUCCESS,
- "Fetch that returns all or the complete remainder of the data buffer should return HIVE_SUCCESS\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(string_field, "yz") != 0,
- "Fetched string does not match: expected:%s, received:%s\n",
- "yz", string_field, connection, 0);
-
- // Fourth fetch after all data has already been obtained
- retval = DBGetFieldAsCString(resultset, 1, string_field, reduced_buffer_size, &data_byte_size,
- &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "Fourth consecutive fetch of a completely fetched variable length field should return HIVE_NO_MORE_DATA\n",
- connection, 0);
-
- // Clean up table
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Close the handles
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "DBDisconnect failed: %s\n",
- err_buf, 0);
-
- return 1;
-}
-
-int meta_data_function_test() {
- fprintf(stderr, "Running %s...\n", __FUNCTION__);
- char err_buf[MAX_HIVE_ERR_MSG_LEN];
- const char* table_name = "ehwang_tmp_test";
- HiveReturn retval;
- char query[MAX_QUERY_LEN];
- char field[MAX_FIELD_LEN];
- int has_results;
- int int_buffer;
- size_t col_count;
- size_t col_len;
- size_t data_byte_size;
- int is_null_value;
- HiveResultSet* resultset;
-
- HiveConnection* connection = DBOpenConnection(DEFAULT_DATABASE, DEFAULT_HOST, atoi(DEFAULT_PORT),
- atoi(DEFAULT_FRAMED), err_buf, sizeof(err_buf));
- assert(connection != NULL); /* If this fails, make sure that Hive server is running with the connect parameter arguments */
-
- // Drop pre-existing tables of the same name
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Create the table
- sprintf(query, "CREATE TABLE %s (key int, value string)", table_name);
- retval = DBExecute(connection, query, NULL, 10, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBExecute failed: %s\n",
- err_buf, connection, 0);
-
- // Test DBTables
- retval = DBTables(connection, table_name, &resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBTables failed: %s\n",
- err_buf, connection, 0);
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(!has_results,
- "DBTables could not find table '%s'\n",
- table_name, connection, 0);
-
- retval = DBGetColumnCount(resultset, &col_count, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetColumnCount failed: '%s'\n",
- err_buf, connection, 0);
- /* The DBTables function should always return a result set with exactly 5 columns */
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(col_count != 5,
- "Column count not equal to five: %zu\n",
- col_count, connection, 0);
-
- // Fetch row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the only row\n",
- connection, 0);
-
- // Check row data
- // Index 2 (a.k.a column 3) in a row will always contain the name of the table
- retval = DBGetFieldAsCString(resultset, 2, field, sizeof(field), &data_byte_size, &is_null_value,
- err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(field, table_name) != 0,
- "Tables do not have the same name: table_name:%s, field:%s\n",
- table_name, field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 2, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as table_name (%zu)\n",
- col_len, strlen(field), connection, 0);
-
- // Fetch row (check that there is nothing else to fetch)
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "DBFetch failed: Only one row, but fetched two\n",
- connection, 0);
-
- // Close the resultset
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
-
- // Test DBColumns
-
- // Match all columns in created table
- retval = DBColumns(connection, &dummyHiveTypeConverter, table_name, "*", &resultset, err_buf,
- sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBColumns failed: %s\n",
- err_buf, connection, 0);
-
- retval = DBHasResults(resultset, &has_results, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBHasResults failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(!has_results,
- "DBColumns could not find columns for table '%s'\n",
- table_name, connection, 0);
-
- retval = DBGetColumnCount(resultset, &col_count, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetColumnCount failed: '%s'\n",
- err_buf, connection, 0);
- /* The DBColumns function should always return a result set with exactly 18 columns */
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(col_count != 18,
- "Column count not equal to 18: %zu\n",
- col_count, connection, 0);
-
- // Fetch first row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the only row\n",
- connection, 0);
-
- // Check first row data
- // Index 2 (a.k.a column 3) in a row will always contain the name of the table
- retval = DBGetFieldAsCString(resultset, 2, field, sizeof(field), &data_byte_size, &is_null_value,
- err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(field, table_name) != 0,
- "Tables do not have the same name: table_name:%s, field:%s\n",
- table_name, field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 2, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as table_name (%zu)\n",
- col_len, strlen(field), connection, 0);
-
- // Index 3 (a.k.a column 4) in a row will always contain the name of the column
- retval = DBGetFieldAsCString(resultset, 3, field, sizeof(field), &data_byte_size, &is_null_value,
- err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(field, "key") != 0,
- "Columns do not have the same name: column_name:%s, field:%s\n",
- "key", field, connection, 0);
- retval = DBGetFieldDataLen(resultset, 3, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as table_name (%zu)\n",
- col_len, strlen(field), connection, 0);
-
- // Index 4 (a.k.a column 5) in a row will always contain the SQL data type value
- retval = DBGetFieldAsInt(resultset, 4, &int_buffer, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_buffer != 1,
- "Wrong converted SQL type: expected=%i, received=%i\n",
- 1, int_buffer, connection, 0);
-
- // Index 13 (a.k.a column 14) in a row will also always contain the SQL data type value
- retval = DBGetFieldAsInt(resultset, 13, &int_buffer, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_buffer != 1,
- "Wrong converted SQL data type: expected=%i, received=%i\n",
- 1, int_buffer, connection, 0);
-
- // Index 16 (a.k.a column 17) in a row will always contain the column ordinal position
- retval = DBGetFieldAsInt(resultset, 16, &int_buffer, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_buffer != 1,
- "Wrong ordinal position: expected=%i, received=%i\n",
- 1, int_buffer, connection, 0);
-
- // Fetch second row
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_NO_MORE_DATA,
- "DBFetch failed: Could not fetch the only row\n",
- connection, 0);
-
- // Check second row data
- // Index 2 (a.k.a column 3) in a row will always contain the name of the table
- retval = DBGetFieldAsCString(resultset, 2, field, sizeof(field), &data_byte_size, &is_null_value,
- err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(field, table_name) != 0,
- "Tables do not have the same name: table_name:%s, field:%s\n",
- table_name, field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 2, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as table_name (%zu)\n",
- col_len, strlen(field), connection, 0);
-
- // Index 3 (a.k.a column 4) in a row will always contain the name of the column
- retval = DBGetFieldAsCString(resultset, 3, field, sizeof(field), &data_byte_size, &is_null_value,
- err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsCString failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(strcmp(field, "value") != 0,
- "Columns do not have the same name: column_name:%s, field:%s\n",
- "key", field, connection, 0);
-
- retval = DBGetFieldDataLen(resultset, 3, &col_len, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldDataLen failed: Could not get the strlen\n",
- connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(col_len != strlen(field),
- "DBGetFieldDataLen failed: Returned length (%zu) was not the same as table_name (%zu)\n",
- col_len, strlen(field), connection, 0);
-
- // Index 4 (a.k.a column 5) in a row will always contain the SQL data type value
- retval = DBGetFieldAsInt(resultset, 4, &int_buffer, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_buffer != 1,
- "Wrong converted SQL type: expected=%i, received=%i\n",
- 1, int_buffer, connection, 0);
-
- // Index 13 (a.k.a column 14) in a row will also always contain the SQL data type value
- retval = DBGetFieldAsInt(resultset, 13, &int_buffer, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_buffer != 1,
- "Wrong converted SQL data type: expected=%i, received=%i\n",
- 1, int_buffer, connection, 0);
-
- // Index 16 (a.k.a column 17) in a row will always contain the column ordinal position
- retval = DBGetFieldAsInt(resultset, 16, &int_buffer, &is_null_value, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBGetFieldAsInt failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_TWO_ARG_CLOSE(int_buffer != 2,
- "Wrong ordinal position: expected=%i, received=%i\n",
- 2, int_buffer, connection, 0);
-
- // Fetch row (check that there is nothing else to fetch)
- retval = DBFetch(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBFetch failed: %s\n",
- err_buf, connection, 0);
- RETURN_ON_ASSERT_NO_ARG_CLOSE(retval != HIVE_NO_MORE_DATA,
- "DBFetch failed: Only one row, but fetched two\n",
- connection, 0);
-
- // Close the resultset
- retval = DBCloseResultSet(resultset, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG_CLOSE(retval == HIVE_ERROR,
- "DBCloseResultSet failed: %s\n",
- err_buf, connection, 0);
-
- // Clean up table
- if (dropTable(connection, table_name) == HIVE_ERROR) {
- DBCloseConnection(connection, err_buf, sizeof(err_buf));
- return 0;
- }
-
- // Close the connection
- retval = DBCloseConnection(connection, err_buf, sizeof(err_buf));
- RETURN_ON_ASSERT_ONE_ARG(retval == HIVE_ERROR,
- "DBDisconnect failed: %s\n",
- err_buf, 0);
- return 1;
-}
-
-/**************************************************************************************************
- * MAIN FUNCTION
- **************************************************************************************************/
-
-int main() {
- int failed = 0;
- fprintf(stderr, "\nStarting Hive Client C tests...\n\n");
-
- if (basic_connect_disconnect_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED basic_connect_disconnect_test!\n");
- }
- if (basic_query_exec_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED basic_query_exec_test!\n");
- }
- if (basic_fetch_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED basic_fetch_test!\n");
- }
- if (show_tables_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED show_tables_test!\n");
- }
- if (query_fetch_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED query_fetch_test!\n");
- }
- if (numeric_range_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED numeric_range_test!\n");
- }
- if (field_multifetch_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED field_multifetch_test!\n");
- }
- if (meta_data_function_test() == 0) {
- failed++;
- fprintf(stderr, "----FAILED meta_data_function_test!\n");
- }
-
- if (failed == 0) {
- fprintf(stderr, "\nALL HIVE CLIENT TESTS PASSED!\n\n");
- return 0;
- } else {
- fprintf(stderr, "\nHIVE CLIENT TEST FAILURE: %i test(s) failed.\n\n", failed);
- return 1;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/testdata/dataset1.input
----------------------------------------------------------------------
diff --git a/odbc/testdata/dataset1.input b/odbc/testdata/dataset1.input
deleted file mode 100644
index b930c1b..0000000
--- a/odbc/testdata/dataset1.input
+++ /dev/null
@@ -1,2 +0,0 @@
-1foo
-2bar
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/testdata/dataset2.input
----------------------------------------------------------------------
diff --git a/odbc/testdata/dataset2.input b/odbc/testdata/dataset2.input
deleted file mode 100644
index a8e72da..0000000
--- a/odbc/testdata/dataset2.input
+++ /dev/null
@@ -1 +0,0 @@
-100abcdefghijklmnopqrstuvwxyz
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/testdata/dataset_types.input
----------------------------------------------------------------------
diff --git a/odbc/testdata/dataset_types.input b/odbc/testdata/dataset_types.input
deleted file mode 100644
index c4507e5..0000000
--- a/odbc/testdata/dataset_types.input
+++ /dev/null
@@ -1,2 +0,0 @@
--128-32768-2147483648-92233720368547758081.1754944E-382.225073858507201E-308\N
-12732767214748364792233720368547758073.4028235E+381.797693134862315E+308\N
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/packaging/src/main/assembly/src.xml
----------------------------------------------------------------------
diff --git a/packaging/src/main/assembly/src.xml b/packaging/src/main/assembly/src.xml
index e8fc980..ba73bd5 100644
--- a/packaging/src/main/assembly/src.xml
+++ b/packaging/src/main/assembly/src.xml
@@ -83,7 +83,6 @@
<include>llap-server/**/*</include>
<include>lib/**/*</include>
<include>findbugs/**/*</include>
- <include>odbc/**/*</include>
<include>orc/**/*</include>
<include>packaging/pom.xml</include>
<include>packaging/src/**/*</include>
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 836e397..2337e89 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,6 @@
<module>hwi</module>
<module>jdbc</module>
<module>metastore</module>
- <module>odbc</module>
<module>orc</module>
<module>ql</module>
<module>serde</module>
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/testutils/ptest2/conf/example-apache-trunk.properties
----------------------------------------------------------------------
diff --git a/testutils/ptest2/conf/example-apache-trunk.properties b/testutils/ptest2/conf/example-apache-trunk.properties
index a13e053..bb6952c 100644
--- a/testutils/ptest2/conf/example-apache-trunk.properties
+++ b/testutils/ptest2/conf/example-apache-trunk.properties
@@ -37,7 +37,7 @@ antArgs = -Dtest.continue.on.failure=true
unitTests.directories = build/anttasks/test/classes build/beeline/test/classes build/cli/test/classes \
build/common/test/classes build/contrib/test/classes build/hbase-handler/test/classes \
- build/hwi/test/classes build/jdbc/test/classes build/metastore/test/classes build/odbc/test/classes \
+ build/hwi/test/classes build/jdbc/test/classes build/metastore/test/classes \
build/ql/test/classes build/serde/test/classes build/service/test/classes build/shims/test/classes \
build/testutils/test/classes \
hcatalog/core/build/test/classes hcatalog/hcatalog-pig-adapter/build/test/classes \
[3/3] hive git commit: HIVE-13234: Remove dead ODBC driver from Hive
(Gopal V, reviewed by Thejas Nair)
Posted by go...@apache.org.
HIVE-13234: Remove dead ODBC driver from Hive (Gopal V, reviewed by Thejas Nair)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/3468a666
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/3468a666
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/3468a666
Branch: refs/heads/master
Commit: 3468a66611a71d8cd5c940b40b888afae6b463c0
Parents: 586c304
Author: Gopal V <go...@apache.org>
Authored: Fri Mar 18 11:57:23 2016 -0700
Committer: Gopal V <go...@apache.org>
Committed: Fri Mar 18 11:57:23 2016 -0700
----------------------------------------------------------------------
odbc/Makefile | 193 ---
odbc/pom.xml | 142 --
odbc/src/cpp/HiveColumnDesc.cpp | 190 ---
odbc/src/cpp/HiveColumnDesc.h | 73 -
odbc/src/cpp/HiveConnection.h | 58 -
odbc/src/cpp/HiveResultSet.cpp | 616 --------
odbc/src/cpp/HiveResultSet.h | 190 ---
odbc/src/cpp/HiveRowSet.cpp | 465 ------
odbc/src/cpp/HiveRowSet.h | 168 ---
odbc/src/cpp/hiveclient.cpp | 294 ----
odbc/src/cpp/hiveclient.h | 598 --------
odbc/src/cpp/hiveclienthelper.cpp | 86 --
odbc/src/cpp/hiveclienthelper.h | 132 --
odbc/src/cpp/hiveconstants.h | 83 --
odbc/src/cpp/thriftserverconstants.h | 64 -
odbc/src/test/hiveclienttest.c | 1395 ------------------
odbc/testdata/dataset1.input | 2 -
odbc/testdata/dataset2.input | 1 -
odbc/testdata/dataset_types.input | 2 -
packaging/src/main/assembly/src.xml | 1 -
pom.xml | 1 -
.../ptest2/conf/example-apache-trunk.properties | 2 +-
22 files changed, 1 insertion(+), 4755 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/Makefile
----------------------------------------------------------------------
diff --git a/odbc/Makefile b/odbc/Makefile
deleted file mode 100644
index 1cd5f7b..0000000
--- a/odbc/Makefile
+++ /dev/null
@@ -1,193 +0,0 @@
-#
-# Copyright 2005 The Apache Software Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-#
-# Note: This makefile depends on 5 environment variables to funtion correctly:
-# a) WORD_SIZE
-# b) THRIFT_HOME
-# c) HIVE_ROOT
-# d) BASE_DIR
-# e) BOOST_HOME
-# All these are passed by build.xml.
-#
-
-WORD_SIZE ?= 64
-ifeq ($(WORD_SIZE),32)
- ARCH_FLAGS = -m32 -DARCH32
-else
- ARCH_FLAGS = -m64 -DARCH64
-endif
-
-OS=$(shell uname -s)
-
-ifeq ($(OS),Darwin)
- LDFLAGS = -dynamiclib
-else
- LDFLAGS = -shared
-endif
-
-
-AR = ar
-ARFLAGS = rcs
-ARXFLAGS = -x
-CC = gcc
-CFLAGS = -Wall -g -fPIC
-CXX = g++
-CXXFLAGS = -Wall -g -fPIC
-LD = g++
-INSTALL = /usr/bin/install -c
-SHELL = /bin/sh
-LIBTOOL = $(SHELL) /usr/bin/libtool
-LINK = ln -sf
-
-BUILD_DIR = $(BASE_DIR)/target
-ODBC_BUILD_DIR = $(BUILD_DIR)/odbc
-OBJ_SERVICE_BUILD_DIR = $(BUILD_DIR)/service/objs
-OBJ_QL_BUILD_DIR = $(BUILD_DIR)/ql/objs
-OBJ_METASTORE_BUILD_DIR = $(BUILD_DIR)/metastore/objs
-OBJ_ODBC_BUILD_DIR = $(ODBC_BUILD_DIR)/objs
-LIB_ODBC_BUILD_DIR = $(ODBC_BUILD_DIR)/lib
-TEST_ODBC_BUILD_DIR = $(ODBC_BUILD_DIR)/test
-THRIFT_INCLUDE_PATH=$(THRIFT_HOME)/include/thrift
-FB303_INCLUDE_PATH=$(THRIFT_INCLUDE_PATH)/fb303
-INSTALL_PATH = /usr/local
-INSTALL_LIB_PATH = $(INSTALL_PATH)/lib
-INSTALL_INCLUDE_PATH = $(INSTALL_PATH)/include
-BOOST_INCLUDE_PATH = $(BOOST_HOME)/include
-
-LIB_NAME = hiveclient
-SHLIB_VERSION = 1.0.0
-SO_LINK_NAME = lib$(LIB_NAME).so
-SO_NAME = $(SO_LINK_NAME).$(SHLIB_VERSION)
-SO_LINK_TARGET = $(LIB_ODBC_BUILD_DIR)/$(SO_LINK_NAME)
-SO_TARGET = $(LIB_ODBC_BUILD_DIR)/$(SO_NAME)
-SO_INSTALL_LINK_TARGET = $(INSTALL_LIB_PATH)/$(SO_LINK_NAME)
-SO_INSTALL_TARGET = $(INSTALL_LIB_PATH)/$(SO_NAME)
-AR_NAME = lib$(LIB_NAME).a
-AR_TARGET = $(LIB_ODBC_BUILD_DIR)/$(AR_NAME)
-AR_INSTALL_TARGET = $(INSTALL_LIB_PATH)/$(AR_NAME)
-
-SERVICE_SRC_DIR = $(HIVE_ROOT)/service/src/gen/thrift/gen-cpp
-SERVICE_SOURCES = ThriftHive.cpp \
- hive_service_constants.cpp \
- hive_service_types.cpp
-SERVICE_OBJS = $(addprefix $(OBJ_SERVICE_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(SERVICE_SOURCES))))
-
-QL_SRC_DIR = $(HIVE_ROOT)/ql/src/gen/thrift/gen-cpp
-QL_SOURCES = queryplan_types.cpp queryplan_constants.cpp
-QL_OBJS = $(addprefix $(OBJ_QL_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(QL_SOURCES))))
-
-
-METASTORE_SRC_DIR = $(HIVE_ROOT)/metastore/src/gen/thrift/gen-cpp
-METASTORE_SOURCES = ThriftHiveMetastore.cpp \
- hive_metastore_constants.cpp \
- hive_metastore_types.cpp
-METASTORE_OBJS = $(addprefix $(OBJ_METASTORE_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(METASTORE_SOURCES))))
-
-ODBC_SRC_DIR = $(BASE_DIR)/src/cpp
-
-ODBC_SOURCES = hiveclient.cpp \
- HiveResultSet.cpp \
- HiveColumnDesc.cpp \
- HiveRowSet.cpp \
- hiveclienthelper.cpp
-
-ODBC_OBJS = $(addprefix $(OBJ_ODBC_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(ODBC_SOURCES))))
-
-ODBC_TEST_SRC_DIR = $(BASE_DIR)/src/test
-ODBC_TEST_DATA_DIR = $(BASE_DIR)/testdata
-TEST_FLAGS = -DTEST_DATA_DIR=$(ODBC_TEST_DATA_DIR)
-HIVE_CLIENT_TEST = $(TEST_ODBC_BUILD_DIR)/HiveClientTestC
-
-INCLUDE_PATHS = -I$(THRIFT_INCLUDE_PATH) \
- -I$(FB303_INCLUDE_PATH) \
- -I$(BOOST_INCLUDE_PATH) \
- -I$(SERVICE_SRC_DIR) \
- -I$(QL_SRC_DIR) \
- -I$(METASTORE_SRC_DIR) \
- -I$(ODBC_SRC_DIR)
-
-INSTALL_HEADERS = hiveclient.h \
- hiveconstants.h
-HEADER_SOURCES = $(addprefix $(ODBC_SRC_DIR)/, $(INSTALL_HEADERS))
-HEADER_TARGETS = $(INSTALL_INCLUDE_PATH)/hiveclient.h \
- $(INSTALL_INCLUDE_PATH)/hiveconstants.h
-
-LIB_THRIFT_DIR = $(THRIFT_HOME)/lib
-LIB_THRIFT_ADD = -L$(LIB_THRIFT_DIR) -lthrift
-LIB_THRIFT_AR = $(LIB_THRIFT_DIR)/libthrift.a
-
-LIB_FB303_DIR = $(THRIFT_HOME)/lib
-LIB_FB303_ADD = -L$(LIB_FB303_DIR) -lfb303
-LIB_FB303_AR = $(LIB_FB303_DIR)/libfb303.a
-
-
-all:: $(AR_TARGET) $(SO_TARGET) $(HIVE_CLIENT_TEST)
-
-$(AR_TARGET): $(METASTORE_OBJS) $(SERVICE_OBJS) $(QL_OBJS) $(ODBC_OBJS)
- if test -z '$(THRIFT_HOME)'; then echo 'THRIFT_HOME directory?'; exit 1; else exit 0; fi
- mkdir -p $(LIB_ODBC_BUILD_DIR)
- $(AR) $(ARXFLAGS) $(LIB_THRIFT_AR) #Extract thrift archive
- $(AR) $(ARXFLAGS) $(LIB_FB303_AR) #Extract fb303 archive
- $(AR) $(ARFLAGS) $@ $+ *.o #Include all object files into new archive
- rm *.o #Remove extracted archive object files
-
-$(SO_TARGET): $(METASTORE_OBJS) $(SERVICE_OBJS) $(QL_OBJS) $(ODBC_OBJS)
- if test -z '$(THRIFT_HOME)'; then echo 'THRIFT_HOME directory?'; exit 1; else exit 0; fi
- mkdir -p $(LIB_ODBC_BUILD_DIR)
- $(LD) $(ARCH_FLAGS) $(LDFLAGS) $+ $(LIB_THRIFT_ADD) $(LIB_FB303_ADD) -o $@ \
- && $(LINK) $(SO_NAME) $(SO_LINK_TARGET)
-
-
-$(OBJ_SERVICE_BUILD_DIR)/%.o: $(SERVICE_SRC_DIR)/%.cpp
- mkdir -p $(OBJ_SERVICE_BUILD_DIR)
- $(CXX) $(CXXFLAGS) $(ARCH_FLAGS) $(INCLUDE_PATHS) -c $< -o $@
-
-$(OBJ_QL_BUILD_DIR)/%.o: $(QL_SRC_DIR)/%.cpp
- mkdir -p $(OBJ_QL_BUILD_DIR)
- $(CXX) $(CXXFLAGS) $(ARCH_FLAGS) $(INCLUDE_PATHS) -c $< -o $@
-
-$(OBJ_METASTORE_BUILD_DIR)/%.o: $(METASTORE_SRC_DIR)/%.cpp
- mkdir -p $(OBJ_METASTORE_BUILD_DIR)
- $(CXX) $(CXXFLAGS) $(ARCH_FLAGS) $(INCLUDE_PATHS) -c $< -o $@
-
-$(OBJ_ODBC_BUILD_DIR)/%.o: $(ODBC_SRC_DIR)/%.cpp
- mkdir -p $(OBJ_ODBC_BUILD_DIR)
- $(CXX) $(CXXFLAGS) $(ARCH_FLAGS) $(INCLUDE_PATHS) -c $< -o $@
-
-$(HIVE_CLIENT_TEST): $(SO_TARGET) $(ODBC_TEST_SRC_DIR)/hiveclienttest.c
- mkdir -p $(TEST_ODBC_BUILD_DIR)
- $(CC) $(CFLAGS) $(ARCH_FLAGS) $(TEST_FLAGS) $(INCLUDE_PATHS) $(ODBC_TEST_SRC_DIR)/hiveclienttest.c -L$(LIB_ODBC_BUILD_DIR) -L$(LIB_THRIFT_DIR) -l$(LIB_NAME) -lthrift $(LIB_FB303_ADD) -o $@
-
-
-install: $(AR_TARGET) $(SO_TARGET)
- test -z "$(INSTALL_LIB_PATH)" || mkdir -p -- "$(INSTALL_LIB_PATH)"
- $(LIBTOOL) --mode=install $(INSTALL) '$(AR_TARGET)' '$(AR_INSTALL_TARGET)'
- $(LIBTOOL) --mode=install $(INSTALL) '$(SO_TARGET)' '$(SO_INSTALL_TARGET)' \
- && $(LINK) $(SO_NAME) $(SO_INSTALL_LINK_TARGET)
- PATH="$PATH:/sbin" ldconfig -n $(INSTALL_LIB_PATH)
- test -z "$(INSTALL_INCLUDE_PATH)" || mkdir -p -- "$(INSTALL_INCLUDE_PATH)"
- $(INSTALL) -m 644 $(HEADER_SOURCES) $(INSTALL_INCLUDE_PATH)
-
-uninstall:
- $(LIBTOOL) --mode=uninstall rm -f '$(AR_INSTALL_TARGET)' '$(SO_INSTALL_LINK_TARGET)' '$(SO_INSTALL_TARGET)'
- rm -f $(HEADER_TARGETS)
-
-clean:
- rm -rf $(ODBC_BUILD_DIR) $(OBJ_SERVICE_BUILD_DIR) $(OBJ_QL_BUILD_DIR) $(OBJ_METASTORE_BUILD_DIR)
-
-test: $(AR_TARGET) $(SO_TARGET) $(HIVE_CLIENT_TEST)
- LD_LIBRARY_PATH=$(LIB_ODBC_BUILD_DIR):$(LIB_THRIFT_DIR):$(LIB_FB303_DIR):$(LD_LIBRARY_PATH) $(HIVE_CLIENT_TEST)
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/pom.xml
----------------------------------------------------------------------
diff --git a/odbc/pom.xml b/odbc/pom.xml
deleted file mode 100644
index 0c836d6..0000000
--- a/odbc/pom.xml
+++ /dev/null
@@ -1,142 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.hive</groupId>
- <artifactId>hive</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>hive-odbc</artifactId>
- <packaging>pom</packaging>
- <name>Hive ODBC</name>
-
- <properties>
- <hive.path.to.root>..</hive.path.to.root>
- <make.cmd>make</make.cmd>
- </properties>
-
- <!-- odbc code depends on code generated in these modules -->
- <dependencies>
- <!-- dependencies are always listed in sorted order by groupId, artifectId -->
- <!-- intra-project -->
- <dependency>
- <groupId>org.apache.hive</groupId>
- <artifactId>hive-exec</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.hive</groupId>
- <artifactId>hive-metastore</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.hive</groupId>
- <artifactId>hive-service</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
-
- <profiles>
- <profile>
- <id>odbc</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>compile-odbc</id>
- <phase>compile</phase>
- <configuration>
- <target>
- <condition property="word.size" value="64" else="32">
- <contains string="${os.arch}" substring="64"/>
- </condition>
- <exec executable="${make.cmd}" failonerror="true">
- <arg value="clean"/>
- <env key="HIVE_ROOT" value="${basedir}/${hive.path.to.root}/"/>
- <env key="BASE_DIR" value="${basedir}"/>
- </exec>
- <exec executable="${make.cmd}" failonerror="true">
- <env key="HIVE_ROOT" value="${basedir}/${hive.path.to.root}/"/>
- <env key="BASE_DIR" value="${basedir}"/>
- <env key="WORD_SIZE" value="${word.size}"/>
- <env key="THRIFT_HOME" value="${thrift.home}"/>
- <env key="BOOST_HOME" value="${boost.home}"/>
- </exec>
- </target>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- <execution>
- <id>test-odbc</id>
- <phase>test</phase>
- <configuration>
- <target>
- <condition property="word.size" value="64" else="32">
- <contains string="${os.arch}" substring="64"/>
- </condition>
- <exec executable="${make.cmd}" failonerror="true">
- <arg value="test"/>
- <env key="HIVE_ROOT" value="${basedir}/${hive.path.to.root}/"/>
- <env key="BASE_DIR" value="${basedir}"/>
- <env key="WORD_SIZE" value="${word.size}"/>
- <env key="THRIFT_HOME" value="${thrift.home}"/>
- </exec>
- </target>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <executions>
- <execution>
- <id>enforce-property</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <requireProperty>
- <property>boost.home</property>
- </requireProperty>
- <requireProperty>
- <property>thrift.home</property>
- </requireProperty>
- </rules>
- <fail>true</fail>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveColumnDesc.cpp
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveColumnDesc.cpp b/odbc/src/cpp/HiveColumnDesc.cpp
deleted file mode 100644
index a2a3dbe..0000000
--- a/odbc/src/cpp/HiveColumnDesc.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <assert.h>
-
-#include "HiveColumnDesc.h"
-#include "hiveclienthelper.h"
-#include "thriftserverconstants.h"
-
-
-/*************************************************************************************************
- * HiveColumnDesc Class Definition
- ************************************************************************************************/
-
-HiveColumnDesc::HiveColumnDesc() {
- m_hive_type = HIVE_UNKNOWN_TYPE;
- m_is_nullable = false;
- m_is_case_sensitive = false;
- m_max_display_size = 0;
- m_byte_size = 0;
-}
-
-HiveColumnDesc::~HiveColumnDesc() {
-}
-
-void HiveColumnDesc::initialize(Apache::Hadoop::Hive::FieldSchema& field_schema) {
- m_field_schema = field_schema;
- m_hive_type = hiveTypeLookup(field_schema.type.c_str());
- m_is_nullable = true;
- m_is_case_sensitive = false;
- m_max_display_size = getMaxDisplaySize(m_hive_type);
- m_byte_size = getByteSize(m_hive_type);
-}
-
-void HiveColumnDesc::getColumnName(char* buffer, size_t buffer_len) {
- safe_strncpy(buffer, m_field_schema.name.c_str(), buffer_len);
-}
-
-void HiveColumnDesc::getColumnType(char* buffer, size_t buffer_len) {
- safe_strncpy(buffer, m_field_schema.type.c_str(), buffer_len);
-}
-
-HiveType HiveColumnDesc::getHiveType() {
- return m_hive_type;
-}
-
-int HiveColumnDesc::getIsNullable() {
- return m_is_nullable ? 1 : 0;
-}
-
-int HiveColumnDesc::getIsCaseSensitive() {
- return m_is_case_sensitive ? 1 : 0;
-}
-
-size_t HiveColumnDesc::getMaxDisplaySize() {
- return m_max_display_size;
-}
-
-size_t HiveColumnDesc::getFieldByteSize() {
- return m_byte_size;
-}
-
-size_t HiveColumnDesc::getMaxDisplaySize(HiveType type) {
- /* These are more or less arbitrarily determined values and may be changed if it causes any problems */
- switch (type)
- {
- case HIVE_VOID_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_BOOLEAN_TYPE:
- return 1;
-
- case HIVE_TINYINT_TYPE:
- return 4;
-
- case HIVE_SMALLINT_TYPE:
- return 6;
-
- case HIVE_INT_TYPE:
- return 11;
-
- case HIVE_BIGINT_TYPE:
- return 20;
-
- case HIVE_FLOAT_TYPE:
- return 16;
-
- case HIVE_DOUBLE_TYPE:
- return 24;
-
- case HIVE_STRING_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_DATE_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_DATETIME_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_TIMESTAMP_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_LIST_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_MAP_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_STRUCT_TYPE:
- return MAX_DISPLAY_SIZE;
-
- case HIVE_UNKNOWN_TYPE:
- return MAX_DISPLAY_SIZE;
-
- default:
- return MAX_DISPLAY_SIZE;
- }
-}
-
-size_t HiveColumnDesc::getByteSize(HiveType type) {
- /* These are more or less arbitrarily determined values and may be changed if it causes any problems */
- switch (type)
- {
- case HIVE_VOID_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_BOOLEAN_TYPE:
- return 1;
-
- case HIVE_TINYINT_TYPE:
- return 1;
-
- case HIVE_SMALLINT_TYPE:
- return 2;
-
- case HIVE_INT_TYPE:
- return 4;
-
- case HIVE_BIGINT_TYPE:
- return 8;
-
- case HIVE_FLOAT_TYPE:
- return 4;
-
- case HIVE_DOUBLE_TYPE:
- return 8;
-
- case HIVE_STRING_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_DATE_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_DATETIME_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_TIMESTAMP_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_LIST_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_MAP_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_STRUCT_TYPE:
- return MAX_BYTE_LENGTH;
-
- case HIVE_UNKNOWN_TYPE:
- return MAX_BYTE_LENGTH;
-
- default:
- return MAX_BYTE_LENGTH;
- }
-}
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveColumnDesc.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveColumnDesc.h b/odbc/src/cpp/HiveColumnDesc.h
deleted file mode 100644
index b415f0e..0000000
--- a/odbc/src/cpp/HiveColumnDesc.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file HiveColumnDesc.h
- * @brief Provides the HiveColumnDesc class
- *
- *****************************************************************************/
-
-
-#ifndef __hive_column_desc_h__
-#define __hive_column_desc_h__
-
-#include "hive_metastore_types.h"
-#include "hiveconstants.h"
-
-
-/*************************************************************************************************
- * HiveColumnDesc Class Declaration
- ************************************************************************************************/
-
-/**
- * @brief Descriptor for a column in a HiveResultSet.
- *
- * This class stores the information describing a column in a HiveResultSet.
- * It was only meant to be created by DBCreateColumnDesc and destroyed by DBCloseColumnDesc.
- *
- * @see DBCreateColumnDesc()
- * @see DBCloseColumnDesc()
- */
-class HiveColumnDesc {
- public:
- HiveColumnDesc();
- virtual ~HiveColumnDesc();
- void initialize(Apache::Hadoop::Hive::FieldSchema& field_schema);
- void getColumnName(char* buffer, size_t buffer_len);
- void getColumnType(char* buffer, size_t buffer_len);
- HiveType getHiveType();
- int getIsNullable();
- int getIsCaseSensitive();
- size_t getMaxDisplaySize();
- size_t getFieldByteSize();
-
- private:
- Apache::Hadoop::Hive::FieldSchema m_field_schema;
- HiveType m_hive_type;
- bool m_is_nullable;
- bool m_is_case_sensitive;
- size_t m_max_display_size;
- size_t m_byte_size;
-
- size_t getMaxDisplaySize(HiveType type);
- size_t getByteSize(HiveType type);
-};
-
-
-#endif // __hive_column_desc_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveConnection.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveConnection.h b/odbc/src/cpp/HiveConnection.h
deleted file mode 100644
index 3b2e2b1..0000000
--- a/odbc/src/cpp/HiveConnection.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file HiveConnection.h
- * @brief Provides the HiveConnection struct
- *
- *****************************************************************************/
-
-
-#ifndef __hive_connection_h__
-#define __hive_connection_h__
-
-#include "ThriftHive.h"
-#include <boost/shared_ptr.hpp>
-
-using namespace boost;
-using namespace apache::thrift::transport;
-
-
-/*************************************************************************************************
- * HiveConnection Class Definition
- ************************************************************************************************/
-
-/**
- * @brief Container class for Hive database connections.
- *
- * This class stores the Hive database connection information. It was only meant to be created by
- * DBOpenConnection and destroyed by DBCloseConnection.
- *
- * @see DBOpenConnection()
- * @see DBCloseConnection()
- */
-struct HiveConnection {
- HiveConnection(shared_ptr<Apache::Hadoop::Hive::ThriftHiveClient> c, shared_ptr<TTransport> t) :
- client(c), transport(t) {}
- shared_ptr<Apache::Hadoop::Hive::ThriftHiveClient> client;
- shared_ptr<TTransport> transport;
-};
-
-
-#endif // __hive_connection_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveResultSet.cpp
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveResultSet.cpp b/odbc/src/cpp/HiveResultSet.cpp
deleted file mode 100644
index d3d375e..0000000
--- a/odbc/src/cpp/HiveResultSet.cpp
+++ /dev/null
@@ -1,616 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <assert.h>
-
-#include "ThriftHive.h"
-
-#include "HiveResultSet.h"
-#include "hiveclienthelper.h"
-#include "thriftserverconstants.h"
-
-
-/*************************************************************************************************
- * HiveQueryResultSet Subclass Definition
- ************************************************************************************************/
-
-HiveQueryResultSet::HiveQueryResultSet(int max_buf_rows) {
- m_connection = NULL;
- m_serial_rowset.reset();
- assert(max_buf_rows > 0);
- m_max_buffered_rows = max_buf_rows;
- m_fetch_idx = -1;
- m_has_results = false;
- m_fetch_attempted = false;
- /* Allocate the necessary amount of memory to prevent resizing */
- m_result_set_data.reserve(max_buf_rows);
-}
-
-HiveQueryResultSet::~HiveQueryResultSet() {
- /* Nothing to deallocate */
-}
-
-HiveReturn HiveQueryResultSet::initialize(HiveConnection* connection, char* err_buf,
- size_t err_buf_len) {
- assert(connection != NULL);
- m_connection = connection;
- m_serial_rowset.reset();
- m_fetch_idx = -1;
- m_has_results = false;
- m_fetch_attempted = false;
- return initializeSchema(err_buf, err_buf_len);
-}
-
-HiveReturn HiveQueryResultSet::fetchNext(char* err_buf, size_t err_buf_len) {
- m_fetch_idx++;
- if (m_fetch_idx >= (int) m_result_set_data.size()) /* If there are no more buffered rows... */
- {
- /* Repopulate the result buffer */
- if (fetchNewResults(err_buf, err_buf_len) == HIVE_ERROR) {
- return HIVE_ERROR;
- }
- /* Set the cursor to point at the first element (fetchNewResults would have reset its position)*/
- m_fetch_idx = 0;
- if (m_result_set_data.empty()) {
- return HIVE_NO_MORE_DATA; /* No more data to fetch */
- }
- }
- m_serial_rowset.reset(); /* Remove old row data before saving next */
- m_serial_rowset.initialize(m_schema, m_result_set_data[m_fetch_idx]);
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveQueryResultSet::hasResults(int* results, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(results == NULL, __FUNCTION__,
- "Pointer to has_results (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
-
- if (!m_fetch_attempted) {
- if (fetchNewResults(err_buf, err_buf_len) == HIVE_ERROR) {
- return HIVE_ERROR; /* An error must have occurred */
- }
- }
-
- *results = m_has_results ? 1 : 0; /* This flag will have been set by the fetch call */
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveQueryResultSet::getColumnCount(size_t* col_count, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(col_count == NULL, __FUNCTION__,
- "Pointer to col_count (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- /* If m_schema has been initialized, then m_schema.fieldSchemas must be populated */
- *col_count = m_schema.fieldSchemas.size();
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveQueryResultSet::createColumnDesc(size_t column_idx,
- HiveColumnDesc** column_desc_ptr, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(column_desc_ptr == NULL, __FUNCTION__,
- "Pointer to column_desc (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(m_schema.fieldSchemas.empty(), __FUNCTION__,
- "Resultset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= m_schema.fieldSchemas.size(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- *column_desc_ptr = new HiveColumnDesc();
- (*column_desc_ptr)->initialize(m_schema.fieldSchemas[column_idx]);
- return HIVE_SUCCESS;
-}
-
-HiveRowSet& HiveQueryResultSet::getRowSet() {
- return m_serial_rowset;
-}
-
-HiveReturn HiveQueryResultSet::initializeSchema(char* err_buf, size_t err_buf_len) {
- try {
- m_connection->client->getSchema(m_schema);
- } catch (Apache::Hadoop::Hive::HiveServerException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unknown Hive get result schema error.", err_buf, err_buf_len, HIVE_ERROR);
- }
-
- /* TODO: hard code this in for now because m_schema.properties not properly implemented;
- * but remove this when it is implemented */
- m_schema.properties[FIELD_DELIM] = "\t";
- m_schema.properties[SERIALIZATION_NULL_FORMAT] = DEFAULT_NULL_FORMAT;
-
- /* TODO: replace the real null representation with 'NULL' because of a bug in the Hive Server
- * fetch function; remove this when Hive Server has been fixed to not replace the actual null
- * rep with NULL. */
- m_schema.properties[SERIALIZATION_NULL_FORMAT] = "NULL";
-
- /* Verify the presence of known m_schema properties */
- assert(m_schema.properties.find(FIELD_DELIM) != m_schema.properties.end());
- assert(m_schema.properties.find(SERIALIZATION_NULL_FORMAT) != m_schema.properties.end());
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveQueryResultSet::fetchNewResults(char* err_buf, size_t err_buf_len) {
- m_result_set_data.clear(); /* Empty the original buffer just to be safe */
- assert(m_connection != NULL);
- assert(m_connection->client != NULL);
- assert(m_max_buffered_rows > 0);
- try {
- m_connection->client->fetchN(m_result_set_data, m_max_buffered_rows);
- } catch (Apache::Hadoop::Hive::HiveServerException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unknown Hive FetchN error.", err_buf, err_buf_len, HIVE_ERROR);
- }
-
- /* This indicates that a Hive server fetch call has successfully executed */
- m_fetch_attempted = true;
- if (!m_result_set_data.empty()) {
- /* This is initialized to be false and will remain true forever once this is set */
- m_has_results = true;
- }
- m_fetch_idx = -1; /* Reset the cursor b/c the old index no longer has any meaning */
- return HIVE_SUCCESS;
-}
-
-
-
-/*************************************************************************************************
- * HiveTablesResultSet Subclass Definition
- ************************************************************************************************/
-
-/*
- * g_tables_schema: An array of arrays of C strings used to define the expected
- * resultset schema for HiveTablesResultSet. All values will be stored as
- * C strings (even numbers) as they will eventually be converted to their
- * proper types. Each entry of g_tables_schema is an array with the following
- * format:
- * 1. Column name
- * 2. Column type name
- * 3. Default value (as a C string)
- */
-static const char* g_tables_schema[][3] = {
- {"TABLE_CAT" , STRING_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"TABLE_SCHEM", STRING_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"TABLE_NAME", STRING_TYPE_NAME, ""},
- {"TABLE_TYPE", STRING_TYPE_NAME, "TABLE"},
- {"REMARKS", STRING_TYPE_NAME, ""}
-};
-
-HiveTablesResultSet::HiveTablesResultSet() {
- m_fetch_idx = -1;
- m_curr_row_data.reserve(5); /* The resultset will always have 5 columns */
-}
-
-HiveTablesResultSet::~HiveTablesResultSet() {
- /* Nothing to deallocate */
-}
-
-HiveReturn HiveTablesResultSet::initialize(HiveConnection* connection,
- const char* tbl_search_pattern, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(connection == NULL, __FUNCTION__,
- "Hive connection cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(connection->client == NULL, __FUNCTION__,
- "Hive connection client cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(tbl_search_pattern == NULL, __FUNCTION__,
- "Table search pattern cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
-
- m_fetch_idx = -1;
- try {
- /* Just use the default database name for now b/c Hive does not yet support multiple
- * databases */
- connection->client->get_tables(m_tables, DEFAULT_DATABASE, tbl_search_pattern);
- } catch (Apache::Hadoop::Hive::MetaException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unknown Hive get tables error.", err_buf, err_buf_len, HIVE_ERROR);
- }
- /* Sort the table names */
- sort(m_tables.begin(), m_tables.end());
- return initializeSchema(err_buf, err_buf_len);
-}
-
-HiveReturn HiveTablesResultSet::fetchNext(char* err_buf, size_t err_buf_len) {
- m_fetch_idx++;
- if (m_fetch_idx >= (int) m_tables.size()) /* If there are no more tables */
- {
- m_fetch_idx--; /* Prevent the m_fetch_idx from wrapping around after too many calls */
- return HIVE_NO_MORE_DATA; /* No more data to fetch */
- }
-
- /* Populate m_curr_row_data with the latest row information */
- if (constructCurrentRow(err_buf, err_buf_len) == HIVE_ERROR) {
- return HIVE_ERROR; /* An error must have occurred */
- }
- m_vecstring_rowset.reset(); /* Remove old rowset data before saving next */
- m_vecstring_rowset.initialize(m_schema, &m_curr_row_data);
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveTablesResultSet::hasResults(int* results, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(results == NULL, __FUNCTION__,
- "Pointer to has_results (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- *results = (m_tables.size() > 0) ? 1 : 0; /* Just check the vector length because no caching */
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveTablesResultSet::getColumnCount(size_t* col_count, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(col_count == NULL, __FUNCTION__,
- "Pointer to col_count (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- /* If m_schema has been initialized, then m_schema.fieldSchemas must be populated */
- *col_count = m_schema.fieldSchemas.size();
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveTablesResultSet::createColumnDesc(size_t column_idx,
- HiveColumnDesc** column_desc_ptr, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(column_desc_ptr == NULL, __FUNCTION__,
- "Pointer to column_desc (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(m_schema.fieldSchemas.empty(), __FUNCTION__,
- "Resultset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= m_schema.fieldSchemas.size(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- *column_desc_ptr = new HiveColumnDesc();
- (*column_desc_ptr)->initialize(m_schema.fieldSchemas[column_idx]);
- return HIVE_SUCCESS;
-}
-
-HiveRowSet& HiveTablesResultSet::getRowSet() {
- return m_vecstring_rowset;
-}
-
-HiveReturn HiveTablesResultSet::initializeSchema(char* err_buf, size_t err_buf_len) {
- /* Initialize the schema values needed for this resultset.
- * OK to hardcode because these fields should never change */
- m_schema.properties[SERIALIZATION_NULL_FORMAT] = DEFAULT_NULL_FORMAT;
-
- Apache::Hadoop::Hive::FieldSchema tmp_field_schema;
- for (unsigned int idx = 0; idx < LENGTH(g_tables_schema); idx++) {
- tmp_field_schema.name = g_tables_schema[idx][0];
- tmp_field_schema.type = g_tables_schema[idx][1];
- /* Makes a copy of this tmp FieldSchema */
- m_schema.fieldSchemas.push_back(tmp_field_schema);
- }
-
- /* There should be exactly 5 columns for this resultset */
- assert(m_schema.fieldSchemas.size() == 5);
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveTablesResultSet::constructCurrentRow(char* err_buf, size_t err_buf_len) {
- /* Clear out the previous row data just to be safe */
- m_curr_row_data.clear();
- int column_num;
- for (unsigned int idx = 0; idx < LENGTH(g_tables_schema); idx++) {
- /* column_num represents ordinal position instead of index to avoid confusion */
- column_num = idx + 1;
- switch (column_num)
- {
- case 3: // If Col3: TABLE_NAME
- m_curr_row_data.push_back(m_tables[m_fetch_idx]);
- break;
-
- default: // Add in default value
- m_curr_row_data.push_back(g_tables_schema[idx][2]);
- break;
- }
- }
-
- /* There should be exactly 5 columns for this resultset */
- assert(m_curr_row_data.size() == 5);
-
- return HIVE_SUCCESS;
-}
-
-
-/*************************************************************************************************
- * HiveColumnsResultSet Subclass Definition
- ************************************************************************************************/
-
-/*
- * g_columns_schema: An array of arrays of C strings used to define the expected
- * resultset schema for HiveColumnsResultSet. All values will be stored as
- * C strings (even numbers) as they will eventually be converted to their
- * proper types. Each entry of g_columns_schema is an array with the following
- * format:
- * 1. Column name
- * 2. Column type name
- * 3. Default value (as a C string)
- */
-static const char* g_columns_schema[][3] = {
- {"TABLE_CAT" , STRING_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"TABLE_SCHEM", STRING_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"TABLE_NAME", STRING_TYPE_NAME, ""},
- {"COLUMN_NAME", STRING_TYPE_NAME, ""},
- {"DATA_TYPE", SMALLINT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"TYPE_NAME", STRING_TYPE_NAME, STRING_TYPE_NAME},
- {"COLUMN_SIZE", INT_TYPE_NAME, STRINGIFY(MAX_BYTE_LENGTH)},
- {"BUFFER_LENGTH", INT_TYPE_NAME, STRINGIFY(MAX_BYTE_LENGTH)},
- {"DECIMAL_DIGITS", SMALLINT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"NUM_PREC_RADIX", SMALLINT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"NULLABLE", SMALLINT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"REMARKS", STRING_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"COLUMN_DEF", STRING_TYPE_NAME, "NULL"},
- {"SQL_DATA_TYPE", SMALLINT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"SQL_DATETIME_SUB", SMALLINT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"CHAR_OCTET_LENGTH", INT_TYPE_NAME, "1"},
- {"ORDINAL_POSITION", INT_TYPE_NAME, DEFAULT_NULL_FORMAT},
- {"IS_NULLABLE", STRING_TYPE_NAME, "YES"}
-};
-
-HiveColumnsResultSet::HiveColumnsResultSet(int(*fpHiveToSQLType)(HiveType)) {
- m_connection = NULL;
- assert(fpHiveToSQLType != NULL);
- m_fpHiveToSQLType = fpHiveToSQLType;
- m_tbl_fetch_idx = -1;
- m_col_fetch_idx = -1;
- m_curr_row_data.reserve(18); /* The resultset will always have 18 columns */
-}
-
-HiveColumnsResultSet::~HiveColumnsResultSet() {
- /* Nothing to deallocate */
-}
-
-HiveReturn HiveColumnsResultSet::initialize(HiveConnection* connection,
- const char* tbl_search_pattern,
- const char* col_search_pattern, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(connection == NULL, __FUNCTION__,
- "Hive connection cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(connection->client == NULL, __FUNCTION__,
- "Hive connection client cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(tbl_search_pattern == NULL, __FUNCTION__,
- "Table search pattern cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(col_search_pattern == NULL, __FUNCTION__,
- "Column search pattern cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
-
- /* TODO: col_search_pattern is not currently supported; arg is ignored for now;
- * either add support in Hive Server or here */
-
- m_connection = connection;
- m_tbl_fetch_idx = -1;
- m_col_fetch_idx = -1;
-
- try {
- /* Just use the default database name for now b/c Hive does not yet support multiple
- * databases */
- connection->client->get_tables(m_tables, DEFAULT_DATABASE, tbl_search_pattern);
- } catch (Apache::Hadoop::Hive::MetaException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unknown Hive get tables error.", err_buf, err_buf_len, HIVE_ERROR);
- }
- /* Sort the table names */
- sort(m_tables.begin(), m_tables.end());
-
- return initializeSchema(err_buf, err_buf_len);
-}
-
-HiveReturn HiveColumnsResultSet::fetchNext(char* err_buf, size_t err_buf_len) {
- m_col_fetch_idx++;
- /* If there are no more columns in the current table */
- if (m_col_fetch_idx >= (int) m_columns.size()) {
- HiveReturn retval = getNextTableFields(err_buf, err_buf_len);
- if (retval != HIVE_SUCCESS) {
- /* Prevent the m_col_fetch_idx from wrapping around after too many calls */
- m_col_fetch_idx--;
- return retval;
- }
- /* If getNextTableFields() successful, m_columns must contain new field schemas for
- * next table */
- assert(m_columns.size() > 0);
- /* Set index back to first element (getNextTableColumns() would have reset its value) */
- m_col_fetch_idx = 0;
- }
-
- /* Populate m_curr_row_data with the latest row information */
- if (constructCurrentRow(err_buf, err_buf_len) == HIVE_ERROR) {
- return HIVE_ERROR; /* An error must have occurred */
- }
- m_vecstring_rowset.reset(); /* Remove old rowset data before saving next */
- m_vecstring_rowset.initialize(m_schema, &m_curr_row_data);
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveColumnsResultSet::hasResults(int* results, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(results == NULL, __FUNCTION__,
- "Pointer to has_results (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- /* If there are tables, then there must be columns to fetch */
- *results = (m_tables.size() > 0) ? 1 : 0;
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveColumnsResultSet::getColumnCount(size_t* col_count, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(col_count == NULL, __FUNCTION__,
- "Pointer to col_count (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- /* If m_schema has been initialized, then m_schema.fieldSchemas must be populated */
- *col_count = m_schema.fieldSchemas.size();
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveColumnsResultSet::createColumnDesc(size_t column_idx,
- HiveColumnDesc** column_desc_ptr, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(column_desc_ptr == NULL, __FUNCTION__,
- "Pointer to column_desc (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(m_schema.fieldSchemas.empty(), __FUNCTION__,
- "Resultset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= m_schema.fieldSchemas.size(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- *column_desc_ptr = new HiveColumnDesc();
- (*column_desc_ptr)->initialize(m_schema.fieldSchemas[column_idx]);
- return HIVE_SUCCESS;
-}
-
-HiveRowSet& HiveColumnsResultSet::getRowSet() {
- return m_vecstring_rowset;
-}
-
-HiveReturn HiveColumnsResultSet::getNextTableFields(char* err_buf, size_t err_buf_len) {
- /* Clear out the field schemas for the previous table */
- m_columns.clear();
-
- m_tbl_fetch_idx++;
- if (m_tbl_fetch_idx >= (int) m_tables.size()) /* If there are no more tables */
- {
- /* Prevent the m_tbl_fetch_idx from wrapping around after too many calls */
- m_tbl_fetch_idx--;
- return HIVE_NO_MORE_DATA; /* No more data to fetch */
- }
-
- assert(m_connection != NULL);
- assert(m_connection->client != NULL);
- try {
- /* Just use the default database name for now b/c Hive does not yet support multiple databases */
- m_connection->client->get_schema(m_columns, DEFAULT_DATABASE, m_tables[m_tbl_fetch_idx]);
- } catch (Apache::Hadoop::Hive::MetaException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (Apache::Hadoop::Hive::UnknownTableException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (Apache::Hadoop::Hive::UnknownDBException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unknown Hive get fields error.", err_buf, err_buf_len, HIVE_ERROR);
- }
- assert(m_columns.size() > 0); /* Every table must have at least one column */
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveColumnsResultSet::initializeSchema(char* err_buf, size_t err_buf_len) {
- /* Initialize the schema values needed for this resultset.
- * OK to hardcode because these fields should never change */
- m_schema.properties[SERIALIZATION_NULL_FORMAT] = DEFAULT_NULL_FORMAT;
-
- Apache::Hadoop::Hive::FieldSchema tmp_field_schema;
- for (unsigned int idx = 0; idx < LENGTH(g_columns_schema); idx++) {
- tmp_field_schema.name = g_columns_schema[idx][0];
- tmp_field_schema.type = g_columns_schema[idx][1];
- /* Makes a copy of this tmp FieldSchema */
- m_schema.fieldSchemas.push_back(tmp_field_schema);
- }
-
- /* There should be exactly 18 columns for this resultset */
- assert(m_schema.fieldSchemas.size() == 18);
-
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveColumnsResultSet::constructCurrentRow(char* err_buf, size_t err_buf_len) {
- /* Clear out the previous row data just to be safe */
- m_curr_row_data.clear();
-
- assert(m_fpHiveToSQLType != NULL);
-
- /* snprintf replaces boost::lexical_cast<string>(...) for string conversions
- * due to dev library compatibility issues (may be changed back to boost libs if desired) */
- char string_buffer[MAX_BYTE_LENGTH];
-
- /* Fill in the values that we can below, leave the rest to default values */
- HiveColumnDesc column_desc;
- column_desc.initialize(m_columns[m_col_fetch_idx]);
- int column_num;
- for (unsigned int idx = 0; idx < LENGTH(g_columns_schema); idx++) {
- /* column_num represents ordinal position instead of index to avoid confusion */
- column_num = idx + 1;
- switch (column_num)
- {
- case 3: // If Col3: TABLE_NAME
- m_curr_row_data.push_back(m_tables[m_tbl_fetch_idx]);
- break;
-
- case 4: // If Col4: COLUMN_NAME
- m_curr_row_data.push_back(m_columns[m_col_fetch_idx].name);
- break;
-
- case 5: // If Col5: DATA_TYPE
- snprintf(string_buffer, sizeof(string_buffer), "%i",
- (*m_fpHiveToSQLType)(column_desc.getHiveType()));
- m_curr_row_data.push_back(string_buffer);
- break;
-
- case 6: // If Col6: TYPE_NAME
- m_curr_row_data.push_back(m_columns[m_col_fetch_idx].type);
- break;
-
- case 7: // If Col7: COLUMN_SIZE
- snprintf(string_buffer, sizeof(string_buffer), "%zu", column_desc.getMaxDisplaySize());
- m_curr_row_data.push_back(string_buffer);
- break;
-
- case 8: // If Col8: BUFFER_LENGTH
- snprintf(string_buffer, sizeof(string_buffer), "%zu", column_desc.getFieldByteSize());
- m_curr_row_data.push_back(string_buffer);
- break;
-
- case 11: // If Col11: NULLABLE
- /* Slight breakage in abstraction: should return SQL_NULLABLE and SQL_NO_NULLS,
- * but currently no means to access these values */
- m_curr_row_data.push_back((column_desc.getIsNullable() ? "1" : "0"));
- break;
-
- case 12: // If Col12: REMARKS
- m_curr_row_data.push_back(m_columns[m_col_fetch_idx].comment);
- break;
-
- case 14: // If Col14: SQL_DATA_TYPE
- snprintf(string_buffer, sizeof(string_buffer), "%i",
- (*m_fpHiveToSQLType)(column_desc.getHiveType()));
- m_curr_row_data.push_back(string_buffer);
- break;
-
- case 17: // If Col17: ORDINAL_POSITION
- snprintf(string_buffer, sizeof(string_buffer), "%i", m_col_fetch_idx + 1);
- m_curr_row_data.push_back(string_buffer);
- break;
-
- case 18: // If Col18: IS_NULLABLE
- m_curr_row_data.push_back((column_desc.getIsNullable() ? "YES" : "NO"));
- break;
-
- default: // Add in default value
- m_curr_row_data.push_back(g_columns_schema[idx][2]);
- break;
- }
- }
-
- /* There should be exactly 18 columns for this resultset */
- assert(m_curr_row_data.size() == 18);
- return HIVE_SUCCESS;
-}
-
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveResultSet.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveResultSet.h b/odbc/src/cpp/HiveResultSet.h
deleted file mode 100644
index 25eabc4..0000000
--- a/odbc/src/cpp/HiveResultSet.h
+++ /dev/null
@@ -1,190 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file HiveResultSet.h
- * @brief Provides the HiveResultSet interface definition and subclasses.
- *
- *****************************************************************************/
-
-
-#ifndef __hive_resultset_h__
-#define __hive_resultset_h__
-
-#include <iostream>
-
-#include "hive_metastore_types.h"
-
-#include "hiveconstants.h"
-#include "HiveConnection.h"
-#include "HiveRowSet.h"
-#include "HiveColumnDesc.h"
-
-using namespace std;
-
-
-/*************************************************************************************************
- * Base HiveResultSet Class Abstract Declaration
- ************************************************************************************************/
-
-/**
- * @brief HiveResultSet interface definition.
- *
- * Abstract base class for Hive resultsets. Does not provide any additional logic for
- * subclasses, but defines the interface expected for all HiveResultSets.
- * All subclasses extending HiveResultSet need to at least implement the below methods.
- */
-class HiveResultSet {
- public:
- virtual ~HiveResultSet() {} ///< The constructor should be defined independently by each subclass
- virtual HiveReturn fetchNext(char* err_buf, size_t err_buf_len) =0;
- virtual HiveReturn hasResults(int* results, char* err_buf, size_t err_buf_len) =0;
- virtual HiveReturn getColumnCount(size_t* col_count, char* err_buf, size_t err_buf_len) =0;
- virtual HiveReturn createColumnDesc(size_t column_idx, HiveColumnDesc** column_desc_ptr,
- char* err_buf, size_t err_buf_len) =0;
- /// The rowset will ONLY be valid after fetchNext has been called at least once
- virtual HiveRowSet& getRowSet() =0;
-};
-
-
-/*************************************************************************************************
- * HiveQueryResultSet Subclass Declaration
- ************************************************************************************************/
-
-/**
- * @brief A container for the resultsets of Hive queries.
- *
- * Container class for a query result set (the result of a DBExecute).
- * This class was only meant to be created by DBExecute and destroyed by DBCloseResultSet.
- * Implements a lazy row/field extraction approach.
- * A single instance should only belong to no more than one thread.
- * All errors messages will be written to err_buf if err_buf and err_buf_len are provided.
- */
-class HiveQueryResultSet: public HiveResultSet {
- public:
- HiveQueryResultSet(int max_buf_rows);
- virtual ~HiveQueryResultSet();
- HiveReturn initialize(HiveConnection* connection, char* err_buf, size_t err_buf_len);
- HiveReturn fetchNext(char* err_buf, size_t err_buf_len);
- HiveReturn hasResults(int* results, char* err_buf, size_t err_buf_len);
- HiveReturn getColumnCount(size_t* col_count, char* err_buf, size_t err_buf_len);
- HiveReturn createColumnDesc(size_t column_idx, HiveColumnDesc** column_desc_ptr, char* err_buf,
- size_t err_buf_len);
- HiveRowSet& getRowSet();
-
- private:
- HiveConnection* m_connection; ///< Hive connection handle
- HiveSerializedRowSet m_serial_rowset; ///< Rowset associated with the current fetched row (if any)
- int m_max_buffered_rows; ///< Max number of rows to buffer in client memory
- int m_fetch_idx; ///< Last row fetched by the client
- bool m_has_results; ///< Indicates that at least one result row has been successfully fetched
- bool m_fetch_attempted; ///< Indicates that a Hive server fetch call has successfully executed
- vector<string> m_result_set_data; ///< Vector of serialized rows
- Apache::Hadoop::Hive::Schema m_schema; ///< Schema of the result table
-
- HiveReturn initializeSchema(char* err_buf, size_t err_buf_len);
- HiveReturn fetchNewResults(char* err_buf, size_t err_buf_len);
-};
-
-
-/*************************************************************************************************
- * HiveTablesResultSet Subclass Declaration
- ************************************************************************************************/
-
-/**
- * @brief A container for resultsets describing the database table catalog.
- *
- * Container class for a pre-scripted table list resultset (the result of a DBTables).
- * This class was only meant to be created by DBTables and destroyed by DBCloseResultSet.
- * All error messages will be written to err_buf if err_buf and err_buf_len are provided.
- * This is a very rudimentary implementation b/c not much table info is available.
- */
-class HiveTablesResultSet: public HiveResultSet {
- public:
- HiveTablesResultSet();
- virtual ~HiveTablesResultSet();
- HiveReturn initialize(HiveConnection* connection, const char* tbl_search_pattern, char* err_buf,
- size_t err_buf_len);
- HiveReturn fetchNext(char* err_buf, size_t err_buf_len);
- HiveReturn hasResults(int* results, char* err_buf, size_t err_buf_len);
- HiveReturn getColumnCount(size_t* col_count, char* err_buf, size_t err_buf_len);
- HiveReturn createColumnDesc(size_t column_idx, HiveColumnDesc** column_desc_ptr, char* err_buf,
- size_t err_buf_len);
- HiveRowSet& getRowSet();
-
- private:
- int m_fetch_idx; ///< Last row fetched by the client
- /// OK to use vector<string> b/c greatly simplifies work and class not used often
- vector<string> m_curr_row_data; ///< Vector with row data corresponding to row at m_fetch_idx
- /// Rowset associated with the current fetched row (if any)
- HiveStringVectorRowSet m_vecstring_rowset;
- vector<string> m_tables; ///< Vector of table names
- Apache::Hadoop::Hive::Schema m_schema; ///< Schema of the result table
-
- HiveReturn initializeSchema(char* err_buf, size_t err_buf_len);
- HiveReturn constructCurrentRow(char* err_buf, size_t err_buf_len);
-};
-
-
-/*************************************************************************************************
- * HiveColumnsResultSet Subclass Declaration
- ************************************************************************************************/
-
-/**
- * @brief A container for resultsets describing the columns of table(s).
- *
- * Container class for a pre-scripted column info resultset (the result of a DBColumns).
- * This class was only meant to be created by DBColumns and destroyed by DBCloseResultSet.
- * All error messages will be written to err_buf if err_buf and err_buf_len are provided.
- * This is a very rudimentary implementation b/c not much column info is available.
- */
-class HiveColumnsResultSet: public HiveResultSet {
- public:
- /// Constructor requires a Hive-to-SQL type convert function pointer as an argument
- HiveColumnsResultSet(int(*fpHiveToSQLType)(HiveType));
- virtual ~HiveColumnsResultSet();
- HiveReturn initialize(HiveConnection* connection, const char* tbl_search_pattern,
- const char* col_search_pattern, char* err_buf, size_t err_buf_len);
- HiveReturn fetchNext(char* err_buf, size_t err_buf_len);
- HiveReturn hasResults(int* results, char* err_buf, size_t err_buf_len);
- HiveReturn getColumnCount(size_t* col_count, char* err_buf, size_t err_buf_len);
- HiveReturn createColumnDesc(size_t column_idx, HiveColumnDesc** column_desc_ptr, char* err_buf,
- size_t err_buf_len);
- HiveRowSet& getRowSet();
-
- private:
- HiveConnection* m_connection; ///< Hive connection handle
- int (*m_fpHiveToSQLType)(HiveType); ///< Pointer to HiveType to SQLType convert function
- int m_tbl_fetch_idx; ///< Last table fetched
- int m_col_fetch_idx; ///< Last column fetched
- vector<string> m_tables; ///< Vector of table names
- vector<Apache::Hadoop::Hive::FieldSchema> m_columns; ///< Vector of column field schemas
- /// OK to use vector<string> b/c greatly simplifies work and class not used often
- vector<string> m_curr_row_data; ///< Vector with constructed row data
- /// Rowset associated with the current constructed row (if any)
- HiveStringVectorRowSet m_vecstring_rowset;
- Apache::Hadoop::Hive::Schema m_schema; ///< Schema of the result table
-
- HiveReturn getNextTableFields(char* err_buf, size_t err_buf_len);
- HiveReturn initializeSchema(char* err_buf, size_t err_buf_len);
- HiveReturn constructCurrentRow(char* err_buf, size_t err_buf_len);
-};
-
-
-#endif // __hive_resultset_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveRowSet.cpp
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveRowSet.cpp b/odbc/src/cpp/HiveRowSet.cpp
deleted file mode 100644
index 3de6124..0000000
--- a/odbc/src/cpp/HiveRowSet.cpp
+++ /dev/null
@@ -1,465 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <assert.h>
-#include <string.h>
-
-#include "HiveRowSet.h"
-#include "hiveclienthelper.h"
-
-
-/*************************************************************************************************
- * Base HiveRowSet Class Logic
- ************************************************************************************************/
-
-HiveRowSet::HiveRowSet() {
- m_is_completely_read = false;
- m_bytes_read = 0;
- m_last_column_fetched = 0;
- m_field_buffer[0] = '\0';
-}
-
-HiveRowSet::~HiveRowSet() {
-}
-
-void HiveRowSet::reset() {
- m_is_completely_read = false;
- m_bytes_read = 0;
- m_last_column_fetched = 0;
- m_field_buffer[0] = '\0';
- /* Non Virtual Calls Pure Virtual Idiom */
- specialized_reset(); /* Call the specialized subclass reset method */
-}
-
-void HiveRowSet::initFieldBuffer() {
- /* m_field_buffer should always correspond to the field indicated by m_last_column_fetched*/
- extractField(m_last_column_fetched);
-}
-
-HiveReturn HiveRowSet::getFieldDataLen(size_t column_idx, size_t* col_len, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(col_len == NULL, __FUNCTION__,
- "Pointer to col_len (output) cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
- *col_len = getFieldLen(column_idx);
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveRowSet::getFieldAsCString(size_t column_idx, char* buffer, size_t buffer_len,
- size_t* data_byte_size, int* is_null_value, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(buffer_len == 0, __FUNCTION__,
- "Output buffer cannot have a size of zero.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This field has already been completely fetched by a previous call*/
- }
- /* If the column data is the same as the null format spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- /* This value must be NULL */
- *is_null_value = 1;
- if (data_byte_size != NULL) {
- *data_byte_size = 0;
- }
- buffer[0] = '\0';
- } else {
- /* This value has been determined not to be NULL */
- *is_null_value = 0;
- size_t data_total_len = getFieldLen(column_idx);
- /* Cannot read more data then the total number of bytes available */
- assert(data_total_len >= m_bytes_read);
- size_t bytes_remaining = data_total_len - m_bytes_read; // Excludes null char
- if (data_byte_size != NULL) {
- /* Save the number of remaining characters to return before this fetch */
- *data_byte_size = bytes_remaining;
- }
- /* Move pointer to the read location */
- const char* src_str_ptr = m_field_buffer + m_bytes_read;
- /* The total number of bytes to read (+1 null terminator) should be no more than the
- * size of the field buffer */
- assert(m_bytes_read + bytes_remaining + 1 <= sizeof(m_field_buffer));
- /* Copy as many characters as possible from the read location */
- size_t bytes_copied = safe_strncpy(buffer, src_str_ptr, min(buffer_len, bytes_remaining + 1)); // +1 for null terminator
- /* bytes_copied does not count the null terminator */
- m_bytes_read += bytes_copied;
- if (m_bytes_read < data_total_len) {
- return HIVE_SUCCESS_WITH_MORE_DATA; /* Data truncated; more data to return */
- }
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS; /* All data successfully read */
-}
-
-HiveReturn HiveRowSet::getFieldAsDouble(size_t column_idx, double* buffer, int* is_null_value,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- /* Reset if this column was not fetched on the last attempt */
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This column has already been completely fetched */
- }
- /* If the column data is the same as the nullformat spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- *is_null_value = 1;
- *buffer = 0.0;
- } else {
- *is_null_value = 0;
- *buffer = atof(m_field_buffer);
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveRowSet::getFieldAsInt(size_t column_idx, int* buffer, int* is_null_value,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This column has already been completely fetched */
- }
- /* If the column data is the same as the null format spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- *is_null_value = 1;
- *buffer = 0;
- } else {
- *is_null_value = 0;
- *buffer = atoi(m_field_buffer);
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveRowSet::getFieldAsLong(size_t column_idx, long* buffer, int* is_null_value,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This column has already been completely fetched */
- }
- /* If the column data is the same as the null format spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- *is_null_value = 1;
- *buffer = 0;
- } else {
- *is_null_value = 0;
- *buffer = atol(m_field_buffer);
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveRowSet::getFieldAsULong(size_t column_idx, unsigned long* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This column has already been completely fetched */
- }
- /* If the column data is the same as the null format spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- *is_null_value = 1;
- *buffer = 0;
- } else {
- *is_null_value = 0;
- *buffer = strtoul(m_field_buffer, NULL, 10);
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveRowSet::getFieldAsI64(size_t column_idx, int64_t* buffer, int* is_null_value,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This column has already been completely fetched */
- }
- /* If the column data is the same as the null format spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- *is_null_value = 1;
- *buffer = 0;
- } else {
- *is_null_value = 0;
- *buffer = ATOI64(m_field_buffer);
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS;
-}
-
-HiveReturn HiveRowSet::getFieldAsI64U(size_t column_idx, uint64_t* buffer, int* is_null_value,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(buffer == NULL, __FUNCTION__,
- "Column data output buffer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(is_null_value == NULL, __FUNCTION__,
- "Column data is_null_value (output) cannot be NULL.", err_buf, err_buf_len,
- HIVE_ERROR);
- RETURN_ON_ASSERT(getColumnCount() == 0, __FUNCTION__,
- "Rowset contains zero columns.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(column_idx >= getColumnCount(), __FUNCTION__,
- "Column index out of bounds.", err_buf, err_buf_len, HIVE_ERROR);
-
- if (m_last_column_fetched != column_idx) {
- extractField(column_idx);
- m_bytes_read = 0; /* Reset the read offset if different from the last column fetched */
- m_last_column_fetched = column_idx;
- m_is_completely_read = false;
- }
- if (m_is_completely_read) {
- return HIVE_NO_MORE_DATA; /* This column has already been completely fetched */
- }
- /* If the column data is the same as the null format spec... */
- if (strcmp(getNullFormat(), m_field_buffer) == 0) {
- *is_null_value = 1;
- *buffer = 0;
- } else {
- *is_null_value = 0;
- *buffer = ATOI64U(m_field_buffer);
- }
- m_is_completely_read = true;
- return HIVE_SUCCESS;
-}
-
-/*************************************************************************************************
- * HiveSerializedRowSet Subclass Definition
- ************************************************************************************************/
-
-HiveSerializedRowSet::HiveSerializedRowSet() {
- m_row_weak_ptr = NULL;
- m_null_format_weak_ptr = NULL;
-}
-
-HiveSerializedRowSet::~HiveSerializedRowSet() {
- /* Nothing to deallocate */
-}
-
-void HiveSerializedRowSet::initialize(Apache::Hadoop::Hive::Schema& schema, string& serialized_row) {
- m_row_weak_ptr = &serialized_row;
- /* Allocate sufficient space to prevent further resizing */
- m_field_offsets.reserve(schema.fieldSchemas.size());
- initializeOffsets(schema, serialized_row); // Initialize m_field_offsets
- assert(m_field_offsets.size() == schema.fieldSchemas.size());
- assert(schema.properties[SERIALIZATION_NULL_FORMAT].length() > 0);
- m_null_format_weak_ptr = &(schema.properties[SERIALIZATION_NULL_FORMAT]);
- /* Synchronize m_field_buffer and m_last_column_fetched now that extractField() works */
- initFieldBuffer();
-}
-
-/* This method should never be called outside of the inherited HiveRowSet::reset() */
-void HiveSerializedRowSet::specialized_reset() {
- m_row_weak_ptr = NULL;
- m_field_offsets.clear();
- m_null_format_weak_ptr = NULL;
-}
-
-void HiveSerializedRowSet::initializeOffsets(Apache::Hadoop::Hive::Schema& schema, string& serialized_row) {
- m_field_offsets.push_back(0); // There will always be at least one column
- // Keep a temporary field_delim reference so we don't have to keep using the map
- string& field_delim(schema.properties[FIELD_DELIM]);
- assert(field_delim.length() > 0);
-
- // Assumes that field delimiters will only be one character
- size_t idx = serialized_row.find_first_of(field_delim);
- while (idx != string::npos) {
- // Set the field offset to the start of the following field
- m_field_offsets.push_back(idx + 1);
- idx = serialized_row.find_first_of(field_delim, idx + 1);
- }
-}
-
-size_t HiveSerializedRowSet::getColumnCount() {
- return m_field_offsets.size();
-}
-
-const char* HiveSerializedRowSet::getNullFormat() {
- assert(m_null_format_weak_ptr != NULL);
- return m_null_format_weak_ptr->c_str();
-}
-
-size_t HiveSerializedRowSet::getFieldLen(size_t column_idx) {
- assert(column_idx < getColumnCount());
- assert(m_row_weak_ptr != NULL);
- size_t len;
- // If this is the last column...
- if (column_idx == getColumnCount() - 1) {
- assert(m_row_weak_ptr->length() >= m_field_offsets[column_idx]);
- len = m_row_weak_ptr->length() - m_field_offsets[column_idx];
- } else {
- assert(m_field_offsets[column_idx + 1] > m_field_offsets[column_idx]);
- len = m_field_offsets[column_idx + 1] - m_field_offsets[column_idx] - 1;
- }
- /* Enforce the constraint that no data exceed MAX_BYTE_LENGTH */
- len = min(len, (size_t) MAX_BYTE_LENGTH);
- return len;
-}
-
-void HiveSerializedRowSet::extractField(size_t column_idx) {
- assert(column_idx < getColumnCount());
- assert(m_row_weak_ptr != NULL);
- /* The field buffer should always be large enough to hold the field */
- assert(getFieldLen(column_idx) < sizeof(m_field_buffer));
- /* Just safety precaution to prevent buffer overflow */
- /* Reduce buffer size by one to save space for null terminator */
- size_t extract_len = min(getFieldLen(column_idx), sizeof(m_field_buffer) - 1);
- size_t copied = m_row_weak_ptr->copy(m_field_buffer, extract_len, m_field_offsets[column_idx]);
- assert(copied == extract_len);
- /* Make sure the buffer is null terminated */
- m_field_buffer[extract_len] = '\0';
-}
-
-/*************************************************************************************************
- * HiveStringVectorRowSet Subclass Definition
- ************************************************************************************************/
-
-HiveStringVectorRowSet::HiveStringVectorRowSet() {
- m_fields_weak_ptr = NULL;
- m_null_format_weak_ptr = NULL;
-}
-
-HiveStringVectorRowSet::~HiveStringVectorRowSet() {
- /* Nothing to deallocate */
-}
-
-void HiveStringVectorRowSet::initialize(Apache::Hadoop::Hive::Schema& schema, vector<string>* fields) {
- assert(fields != NULL);
- m_fields_weak_ptr = fields;
- assert(schema.properties[SERIALIZATION_NULL_FORMAT].length() > 0);
- m_null_format_weak_ptr = &(schema.properties[SERIALIZATION_NULL_FORMAT]);
- /* Synchronize m_field_buffer and m_last_column_fetched now that extractField() works */
- initFieldBuffer();
-}
-
-/* This method should never be called outside of the inherited HiveRowSet::reset() */
-void HiveStringVectorRowSet::specialized_reset() {
- m_fields_weak_ptr = NULL;
- m_null_format_weak_ptr = NULL;
-}
-
-size_t HiveStringVectorRowSet::getColumnCount() {
- assert(m_fields_weak_ptr != NULL);
- return m_fields_weak_ptr->size();
-}
-
-const char* HiveStringVectorRowSet::getNullFormat() {
- assert(m_null_format_weak_ptr != NULL);
- return m_null_format_weak_ptr->c_str();
-}
-
-size_t HiveStringVectorRowSet::getFieldLen(size_t column_idx) {
- assert(column_idx < getColumnCount());
- assert(m_fields_weak_ptr != NULL);
- size_t len = m_fields_weak_ptr->at(column_idx).length();
- /* Enforce the constraint that no data exceed MAX_BYTE_LENGTH */
- len = min(len, (size_t) MAX_BYTE_LENGTH);
- return len;
-}
-
-void HiveStringVectorRowSet::extractField(size_t column_idx) {
- assert(column_idx < getColumnCount());
- assert(m_fields_weak_ptr != NULL);
- safe_strncpy(m_field_buffer, m_fields_weak_ptr->at(column_idx).c_str(), sizeof(m_field_buffer));
-}
-
-
[2/3] hive git commit: HIVE-13234: Remove dead ODBC driver from Hive
(Gopal V, reviewed by Thejas Nair)
Posted by go...@apache.org.
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/HiveRowSet.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/HiveRowSet.h b/odbc/src/cpp/HiveRowSet.h
deleted file mode 100644
index ca6e6af..0000000
--- a/odbc/src/cpp/HiveRowSet.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file HiveRowSet.h
- * @brief Provides the HiveRowSet interface and subclasses.
- *
- *****************************************************************************/
-
-
-#ifndef __hive_rowset_h__
-#define __hive_rowset_h__
-
-#include <iostream>
-
-#include "hive_metastore_types.h"
-
-#include "hiveconstants.h"
-#include "thriftserverconstants.h"
-
-using namespace std;
-
-
-/*************************************************************************************************
- * Base HiveRowSet Class Abstract Declaration
- ************************************************************************************************/
-
-/**
- * @brief HiveRowSet interface definition.
- *
- * Abstract base class for Hive rowsets. Provides the logic to extract fields as various
- * data types, allowing subclasses to focus on the storage and field parsing of the data.
- */
-class HiveRowSet {
- public:
- /// Cannot be called directly, but should be called automatically from subclass constructors
- HiveRowSet();
- virtual ~HiveRowSet();
- void reset(); ///< Not overrideable, implement specialized_reset() instead
- HiveReturn getFieldDataLen(size_t column_idx, size_t* col_len, char* err_buf, size_t err_buf_len);
- HiveReturn getFieldAsCString(size_t column_idx, char* buffer, size_t buffer_len,
- size_t* data_byte_size, int* is_null_value, char* err_buf,
- size_t err_buf_len);
- HiveReturn getFieldAsDouble(size_t column_idx, double* buffer, int* is_null_value, char* err_buf,
- size_t err_buf_len);
- HiveReturn getFieldAsInt(size_t column_idx, int* buffer, int* is_null_value, char* err_buf,
- size_t err_buf_len);
- HiveReturn getFieldAsLong(size_t column_idx, long* buffer, int* is_null_value, char* err_buf,
- size_t err_buf_len);
- HiveReturn getFieldAsULong(size_t column_idx, unsigned long* buffer, int* is_null_value,
- char* err_buf, size_t err_buf_len);
- HiveReturn getFieldAsI64(size_t column_idx, int64_t* buffer, int* is_null_value, char* err_buf,
- size_t err_buf_len);
- HiveReturn getFieldAsI64U(size_t column_idx, uint64_t* buffer, int* is_null_value, char* err_buf,
- size_t err_buf_len);
-
- protected:
- /// Forces all data retrieved to be no more than MAX_BYTE_LENGTH
- char m_field_buffer[MAX_BYTE_LENGTH + 1];
-
- /**
- * @brief Initializes m_field_buffer with the field indicated by m_last_column_fetched.
- *
- * Not overrideable, used by subclasses to synchronize m_field_buffer and m_last_column_fetched;
- * should be called by every subclass immediately after initialization. This is necessary at
- * the beginning to make sure that m_field_buffer will always have the field data indicated
- * by m_last_column_fetched.
- */
- void initFieldBuffer();
-
- private:
- bool m_is_completely_read;
- size_t m_last_column_fetched;
- /// Number of bytes read out of m_last_column_fetched since the last consecutive call
- size_t m_bytes_read;
-
- virtual void specialized_reset() =0; ///< Called by HiveRowSet::reset()
- virtual size_t getColumnCount() =0; ///< Only used within this class hierarchy for error checking
- virtual const char* getNullFormat() =0; ///< Should return a pointer to a locally stored C string
- virtual size_t getFieldLen(size_t column_idx) =0;
- /// Should copy the field data as a C string to m_field_buffer
- virtual void extractField(size_t column_idx) =0;
-};
-
-
-/*************************************************************************************************
- * HiveSerializedRowSet Subclass Declaration
- ************************************************************************************************/
-
-/**
- * @brief Container class for a fetched row from a HiveResultSet where each row is a serialized string.
- *
- * Container class for a fetched row from a HiveResultSet where each row is a serialized string.
- * - HiveSerializedRowSet is completely dependent on associated HiveResultSet and should not
- * be used independently; must always remain bound to associated HiveResultSet.
- * - Assumes the associated HiveResultSet manages the memory of all weak pointer members
- * - Constructed within the HiveResultSet by calling DBFetch
- * - All errors messages will be written to err_buf if err_buf and err_buf_len are provided
- */
-class HiveSerializedRowSet: public HiveRowSet {
- public:
- HiveSerializedRowSet();
- virtual ~HiveSerializedRowSet();
- void initialize(Apache::Hadoop::Hive::Schema& schema, string& serialized_row);
-
- private:
- string* m_row_weak_ptr; ///< Weak pointer to the row string associated with m_field_offsets
- vector<size_t> m_field_offsets; ///< Indexes into the serialized row string of column starting points
- string* m_null_format_weak_ptr; ///< Weak pointer to NULL format representation for this row
-
- void specialized_reset();
- void initializeOffsets(Apache::Hadoop::Hive::Schema& schema, string& serialized_row);
- size_t getColumnCount();
- const char* getNullFormat();
- size_t getFieldLen(size_t column_idx);
- void extractField(size_t column_idx);
-};
-
-
-/*************************************************************************************************
- * HiveStringVectorRowSet Subclass Declaration
- ************************************************************************************************/
-
-/**
- * @brief Container class for a fetched row from a HiveResultSet where each row is vector of string fields.
- *
- * Container class for a fetched row from a HiveResultSet where each row is vector of string fields
- * - HiveStringVectorRowSet is completely dependent on associated HiveResultSet and should not
- * be used independently; must always remain bound to associated HiveResultSet.
- * - Assumes the associated HiveResultSet manages the memory of all weak pointer members
- * - Constructed within the HiveResultSet by calling DBFetch
- * - All errors messages will be written to err_buf if err_buf and err_buf_len are provided
- */
-class HiveStringVectorRowSet: public HiveRowSet {
- public:
- HiveStringVectorRowSet();
- virtual ~HiveStringVectorRowSet();
- void initialize(Apache::Hadoop::Hive::Schema& schema, vector<string>* fields);
-
- private:
- vector<string>* m_fields_weak_ptr; ///< Weak pointer to a vector of fields represented as strings
- string* m_null_format_weak_ptr; ///< Weak pointer to NULL format representation for this row
-
- void specialized_reset();
- size_t getColumnCount();
- const char* getNullFormat();
- size_t getFieldLen(size_t column_idx);
- void extractField(size_t column_idx);
-};
-
-
-#endif // __hive_rowset_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/hiveclient.cpp
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/hiveclient.cpp b/odbc/src/cpp/hiveclient.cpp
deleted file mode 100644
index 450eb0b..0000000
--- a/odbc/src/cpp/hiveclient.cpp
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <assert.h>
-#include <iostream>
-#include <boost/shared_ptr.hpp>
-#include <boost/algorithm/string.hpp>
-
-#include "ThriftHive.h"
-#include <protocol/TBinaryProtocol.h>
-#include <transport/TTransportUtils.h>
-#include <transport/TTransport.h>
-#include <transport/TSocket.h>
-
-#include "hiveclient.h"
-#include "hiveclienthelper.h"
-#include "HiveColumnDesc.h"
-#include "HiveConnection.h"
-#include "HiveResultSet.h"
-#include "HiveRowSet.h"
-
-
-using namespace std;
-using namespace boost;
-using namespace apache::thrift::protocol;
-using namespace apache::thrift::transport;
-
-
-/*****************************************************************
- * Global Hive Client Functions (usable as C callback functions)
- *****************************************************************/
-
-HiveConnection* DBOpenConnection(const char* database, const char* host, int port, int framed,
- char* err_buf, size_t err_buf_len) {
- // TODO: add in database selection when Hive supports this feature
- shared_ptr<TSocket> socket(new TSocket(host, port));
- shared_ptr<TTransport> transport;
-
- if (framed) {
- shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
- transport = framedSocket;
- } else {
- shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
- transport = bufferedSocket;
- }
-
- shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
- shared_ptr<Apache::Hadoop::Hive::ThriftHiveClient> client(new Apache::Hadoop::Hive::ThriftHiveClient(protocol));
- try {
- transport->open();
- } catch (TTransportException& ttx) {
- RETURN_FAILURE(__FUNCTION__, ttx.what(), err_buf, err_buf_len, NULL);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unable to connect to Hive server.", err_buf, err_buf_len, NULL);
- }
-
- HiveConnection* conn = new HiveConnection(client, transport);
- return conn;
-}
-
-HiveReturn DBCloseConnection(HiveConnection* connection, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(connection == NULL, __FUNCTION__,
- "Hive connection cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(connection->transport == NULL, __FUNCTION__,
- "Hive connection transport cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- try {
- connection->transport->close();
- } catch (...) {
- /* Ignore the exception, we just want to clean up everything... */
- }
- delete connection;
- return HIVE_SUCCESS;
-}
-
-HiveReturn DBExecute(HiveConnection* connection, const char* query, HiveResultSet** resultset_ptr,
- int max_buf_rows, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(connection == NULL, __FUNCTION__,
- "Hive connection cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(connection->client == NULL, __FUNCTION__,
- "Hive connection client cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- RETURN_ON_ASSERT(query == NULL, __FUNCTION__,
- "Query string cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
-
- // TODO: remove
- string query_str(query);
- // TODO: this may not need to happen if Hive allows for multiple successive queries in
- // one execute statement (and permits a terminating semicolon).
- /* Strip off a query's terminating semicolon if it exists */
- trim(query_str); /* Trim white space from string to check if last character is semicolon */
- if (query_str.length() > 0 && query_str[query_str.length() - 1] == ';') {
- query_str.erase(query_str.length() - 1);
- }
-
- /* Pass the query onto the Hive server for execution */
- /* Query execution is kept separate from the resultset b/c results may not always be needed (i.e. DML) */
- try {
- connection->client->execute(query_str); /* This is currently implemented as a blocking operation */
- } catch (Apache::Hadoop::Hive::HiveServerException& ex) {
- RETURN_FAILURE(__FUNCTION__, ex.what(), err_buf, err_buf_len, HIVE_ERROR);
- } catch (...) {
- RETURN_FAILURE(__FUNCTION__,
- "Unknown Hive query execution error.", err_buf, err_buf_len, HIVE_ERROR);
- }
-
- /* resultset_ptr may be NULL if the caller does not care about the result */
- if (resultset_ptr != NULL) {
- HiveQueryResultSet* query_resultset = new HiveQueryResultSet(max_buf_rows);
- *resultset_ptr = query_resultset; /* Store into generic HiveResultSet pointer */
- return query_resultset->initialize(connection, err_buf, err_buf_len);
- }
- return HIVE_SUCCESS;
-}
-
-HiveReturn DBTables(HiveConnection* connection, const char* tbl_search_pattern,
- HiveResultSet** resultset_ptr, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset_ptr == NULL, __FUNCTION__,
- "Resultset pointer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
-
- HiveTablesResultSet* tables_resultset = new HiveTablesResultSet();
- *resultset_ptr = tables_resultset; /* Store into generic HiveResultSet pointer */
- return tables_resultset->initialize(connection, tbl_search_pattern, err_buf, err_buf_len);
-}
-
-HiveReturn DBColumns(HiveConnection* connection, int(*fpHiveToSQLType)(HiveType),
- const char* tbl_search_pattern, const char* col_search_pattern,
- HiveResultSet** resultset_ptr, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset_ptr == NULL, __FUNCTION__,
- "Resultset pointer cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
-
- HiveColumnsResultSet* columns_resultset = new HiveColumnsResultSet(fpHiveToSQLType);
- *resultset_ptr = columns_resultset; /* Store into generic HiveResultSet pointer */
- return columns_resultset->initialize(connection, tbl_search_pattern, col_search_pattern, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBCloseResultSet(HiveResultSet* resultset, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- delete resultset;
- return HIVE_SUCCESS;
-}
-
-HiveReturn DBFetch(HiveResultSet* resultset, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->fetchNext(err_buf, err_buf_len);
-}
-
-HiveReturn DBHasResults(HiveResultSet* resultset, int* has_results, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->hasResults(has_results, err_buf, err_buf_len);
-}
-
-HiveReturn DBGetColumnCount(HiveResultSet* resultset, size_t* col_count, char* err_buf,
- size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getColumnCount(col_count, err_buf, err_buf_len);
-}
-
-HiveReturn DBCreateColumnDesc(HiveResultSet* resultset, size_t column_idx,
- HiveColumnDesc** column_desc_ptr, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->createColumnDesc(column_idx, column_desc_ptr, err_buf, err_buf_len);
-}
-
-HiveReturn DBGetFieldDataLen(HiveResultSet* resultset, size_t column_idx, size_t* col_len,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldDataLen(column_idx, col_len, err_buf, err_buf_len);
-}
-
-HiveReturn DBGetFieldAsCString(HiveResultSet* resultset, size_t column_idx, char* buffer,
- size_t buffer_len, size_t* data_byte_size, int* is_null_value,
- char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsCString(column_idx, buffer, buffer_len, data_byte_size,
- is_null_value, err_buf, err_buf_len);
-}
-
-HiveReturn DBGetFieldAsDouble(HiveResultSet* resultset, size_t column_idx, double* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsDouble(column_idx, buffer, is_null_value, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBGetFieldAsInt(HiveResultSet* resultset, size_t column_idx, int* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsInt(column_idx, buffer, is_null_value, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBGetFieldAsLong(HiveResultSet* resultset, size_t column_idx, long* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsLong(column_idx, buffer, is_null_value, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBGetFieldAsULong(HiveResultSet* resultset, size_t column_idx, unsigned long* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsULong(column_idx, buffer, is_null_value, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBGetFieldAsI64(HiveResultSet* resultset, size_t column_idx, int64_t* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsI64(column_idx, buffer, is_null_value, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBGetFieldAsI64U(HiveResultSet* resultset, size_t column_idx, uint64_t* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(resultset == NULL, __FUNCTION__,
- "Hive resultset cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- return resultset->getRowSet().getFieldAsI64U(column_idx, buffer, is_null_value, err_buf,
- err_buf_len);
-}
-
-HiveReturn DBCloseColumnDesc(HiveColumnDesc* column_desc, char* err_buf, size_t err_buf_len) {
- RETURN_ON_ASSERT(column_desc == NULL, __FUNCTION__,
- "Hive column descriptor cannot be NULL.", err_buf, err_buf_len, HIVE_ERROR);
- delete column_desc;
- return HIVE_SUCCESS;
-}
-
-/* Forego the error message handling in these accessor functions b/c of trivial implementations */
-void DBGetColumnName(HiveColumnDesc* column_desc, char* buffer, size_t buffer_len) {
- assert(column_desc != NULL);
- assert(buffer != NULL);
- column_desc->getColumnName(buffer, buffer_len);
-}
-
-void DBGetColumnType(HiveColumnDesc* column_desc, char* buffer, size_t buffer_len) {
- assert(column_desc != NULL);
- assert(buffer != NULL);
- column_desc->getColumnType(buffer, buffer_len);
-}
-
-HiveType DBGetHiveType(HiveColumnDesc* column_desc) {
- assert(column_desc != NULL);
- return column_desc->getHiveType();
-}
-
-int DBGetIsNullable(HiveColumnDesc* column_desc) {
- assert(column_desc != NULL);
- return column_desc->getIsNullable();
-}
-
-int DBGetIsCaseSensitive(HiveColumnDesc* column_desc) {
- assert(column_desc != NULL);
- return column_desc->getIsCaseSensitive();
-}
-
-size_t DBGetMaxDisplaySize(HiveColumnDesc* column_desc) {
- assert(column_desc != NULL);
- return column_desc->getMaxDisplaySize();
-}
-
-size_t DBGetFieldByteSize(HiveColumnDesc* column_desc) {
- assert(column_desc != NULL);
- return column_desc->getFieldByteSize();
-}
-
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/hiveclient.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/hiveclient.h b/odbc/src/cpp/hiveclient.h
deleted file mode 100644
index f1af670..0000000
--- a/odbc/src/cpp/hiveclient.h
+++ /dev/null
@@ -1,598 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file hiveclient.h
- * @brief Hive client library interface.
- *
- * This header file defines the Hive client library interface (C compatible).
- * All interactions with Hive client should be directed through the following
- * declared functions.
- *
- * Here is an example of a typical order with which to call these functions:
- *
- * DBOpenConnection
- * ..-> DBExecute or DBTables or DBColumns
- * ..-> DBCreateColumnDesc
- * ....-> DBGetColumnName
- * ....-> DBGetColumnType
- * ....-> DBGetHiveType
- * ....-> DBGetIsNullable
- * ....-> DBGetIsCaseSensitive
- * ....-> DBGetMaxDisplaySize
- * ....-> DBGetFieldByteSize
- * ....-> DBCloseColumnDesc
- * ..-> DBHasResults
- * ..-> DBGetColumnCount
- * ..-> DBFetch
- * ....-> DBGetFieldDataLen
- * ....-> DBGetFieldAsCString
- * ....-> DBGetFieldAsDouble
- * ....-> DBGetFieldAsInt
- * ....-> DBGetFieldAsLong
- * ....-> DBGetFieldAsULong
- * ....-> DBGetFieldAsI64
- * ....-> DBGetFieldAsI64U
- * ..-> DBCloseResultSet
- * ..-> DBCloseConnection
- *
- *****************************************************************************/
-
-
-#ifndef __hive_client_h__
-#define __hive_client_h__
-
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
-#include <inttypes.h>
-#include <stdint.h>
-
-#include "hiveconstants.h"
-
-
-/******************************************************************************
- * Hive Client C++ Class Placeholders
- *****************************************************************************/
-
-typedef enum HiveReturn HiveReturn;
-typedef enum HiveType HiveType;
-typedef struct HiveConnection HiveConnection;
-typedef struct HiveResultSet HiveResultSet;
-typedef struct HiveColumnDesc HiveColumnDesc;
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-
-/******************************************************************************
- * Global Hive Client Functions (usable as C callback functions)
- *****************************************************************************/
-
-/**
- * @brief Connect to a Hive database.
- *
- * Connects to a Hive database on the specified Hive server. The caller takes
- * ownership of the returned HiveConnection and is responsible for deallocating
- * the memory and connection by calling DBCloseConnection.
- *
- * @see DBCloseConnection()
- *
- * @param database Name of the Hive database on the Hive server to which to connect.
- * @param host Host address of the Hive server.
- * @param port Host port of the Hive server.
- * @param framed Set as 1 to use a framed socket, or 0 to use a buffered socket.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return A HiveConnection object representing the established database connection,
- * or NULL if an error occurred. Error messages will be stored in err_buf.
- */
-HiveConnection* DBOpenConnection(const char* database, const char* host, int port, int framed,
- char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Disconnects from a Hive database.
- *
- * Disconnects from a Hive database and destroys the supplied HiveConnection object.
- * This function should eventually be called for every HiveConnection created by
- * DBOpenConnection.
- *
- * @see DBOpenConnection()
- *
- * @param connection A HiveConnection object associated a database connection.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBCloseConnection(HiveConnection* connection, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Execute a query.
- *
- * Executes a query on a Hive connection and associates a HiveResultSet with the result.
- * Caller takes ownership of returned HiveResultSet and is responsible for deallocating
- * the object by calling DBCloseResultSet.
- *
- * @see DBCloseResultSet()
- *
- * @param connection A HiveConnection object associated a database connection.
- * @param query The Hive query string to be executed.
- * @param resultset_ptr A pointer to a HiveResultSet pointer which will be associated with the
- * result, or NULL if the result is not needed.
- * @param max_buf_rows Maximum number of rows to buffer in the new HiveResultSet for the query
- * results
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBExecute(HiveConnection* connection, const char* query, HiveResultSet** resultset_ptr,
- int max_buf_rows, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Query for database tables.
- *
- * Gets a resultset containing the set of tables in the database matching a regex pattern.
- * Caller takes ownership of returned HiveResultSet and is responsible for deallocating
- * the object by calling DBCloseResultSet.
- *
- * @see DBCloseResultSet()
- *
- * @param connection A HiveConnection object associated a database connection.
- * @param tbl_search_pattern A regex pattern used to match with table names (use '*' to match all).
- * @param resultset_ptr A pointer to a HiveResultSet pointer which will be associated with the
- * result.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBTables(HiveConnection* connection, const char* tbl_search_pattern,
- HiveResultSet** resultset_ptr, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Query for columns in table(s).
- *
- * Gets a resultset containing the set of columns in the database matching a regex pattern
- * from a set of tables matching another regex pattern. Caller takes ownership of returned
- * HiveResultSet and is responsible for deallocating the object by calling DBCloseResultSet.
- *
- * @see DBCloseResultSet()
- *
- * @param connection A HiveConnection object associated with a database connection.
- * @param fpHiveToSQLType Pointer to a function that takes a HiveType argument and returns a
- * corresponding int value (possibly a SQL type).
- * @param tbl_search_pattern A regex pattern used to match with table names (use '*' to match all).
- * @param col_search_pattern A regex pattern used to match with column names (use '*' to match all).
- * @param resultset_ptr A pointer to a HiveResultSet pointer which will be associated with the
- * result.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBColumns(HiveConnection* connection, int (*fpHiveToSQLType)(HiveType),
- const char* tbl_search_pattern, const char* col_search_pattern,
- HiveResultSet** resultset_ptr, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Destroys any specified HiveResultSet object.
- *
- * Destroys any specified HiveResultSet object. The HiveResultSet may have been
- * created by a number of other functions.
- *
- * @param resultset A HiveResultSet object to be removed from memory.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBCloseResultSet(HiveResultSet* resultset, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Fetches the next unfetched row in a HiveResultSet.
- *
- * Fetches the next unfetched row in a HiveResultSet. The fetched row will be stored
- * internally within the resultset and may be accessed through other DB functions.
- *
- * @param resultset A HiveResultSet from which to fetch rows.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful,
- * HIVE_ERROR if an error occurred,
- * HIVE_NO_MORE_DATA if there are no more rows to fetch.
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBFetch(HiveResultSet* resultset, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Check for results.
- *
- * Determines whether the HiveResultSet has ever had any result rows.
- *
- * @param resultset A HiveResultSet from which to check for results.
- * @param has_results Pointer to an int which will be set to 1 if results, 0 if no results.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBHasResults(HiveResultSet* resultset, int* has_results, char* err_buf,
- size_t err_buf_len);
-
-/**
- * @brief Determines the number of columns in the HiveResultSet.
- *
- * @param resultset A HiveResultSet from which to retrieve the column count.
- * @param col_count Pointer to a size_t which will be set to the number of columns in the result.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBGetColumnCount(HiveResultSet* resultset, size_t* col_count, char* err_buf,
- size_t err_buf_len);
-
-/**
- * @brief Construct a HiveColumnDesc.
- *
- * Constructs a HiveColumnDesc with information about a specified column in the resultset.
- * Caller takes ownership of returned HiveColumnDesc and is responsible for deallocating
- * the object by calling DBCloseColumnDesc.
- *
- * @see DBCloseColumnDesc()
- *
- * @param resultset A HiveResultSet context from which to construct the HiveColumnDesc.
- * @param column_idx Zero offset index of a column.
- * @param column_desc_ptr A pointer to a HiveColumnDesc pointer which will receive the new
- * HiveColumnDesc.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBCreateColumnDesc(HiveResultSet* resultset, size_t column_idx,
- HiveColumnDesc** column_desc_ptr, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Find the size of a field as a string.
- *
- * Determines the number of characters needed to display a field stored in the fetched row
- * of a HiveResultSet.
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param col_len Pointer to an size_t which will be set to the byte length of the specified field.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBGetFieldDataLen(HiveResultSet* resultset, size_t column_idx, size_t* col_len,
- char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as a C string.
- *
- * Reads out a field from the currently fetched rowset in a resultset as a C String.
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to a buffer that will receive the data.
- * @param buffer_len Number of bytes allocated to buffer.
- * @param data_byte_size Pointer to an size_t which will contain the length of the data available
- * to return before calling this function. Can be set to NULL if this
- * information is not needed.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful and there is no more data to fetch
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_SUCCESS_WITH_MORE_DATA if data has been successfully fetched, but there is still
- * more data to get
- * HIVE_NO_MORE_DATA if this field has already been completely fetched
- */
-HiveReturn DBGetFieldAsCString(HiveResultSet* resultset, size_t column_idx, char* buffer,
- size_t buffer_len, size_t* data_byte_size, int* is_null_value,
- char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as a double.
- *
- * Reads out a field from the currently fetched rowset in a resultset as a double
- * (platform specific).
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to a double that will receive the data.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful.
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_NO_MORE_DATA if this field has already been fetched
- */
-HiveReturn DBGetFieldAsDouble(HiveResultSet* resultset, size_t column_idx, double* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as an int.
- *
- * Reads out a field from the currently fetched rowset in a resultset as an int
- * (platform specific).
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to an int that will receive the data.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful.
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_NO_MORE_DATA if this field has already been fetched
- */
-HiveReturn DBGetFieldAsInt(HiveResultSet* resultset, size_t column_idx, int* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as a long int.
- *
- * Reads out a field from the currently fetched rowset in a resultset as a long int
- * (platform specific).
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to a long int that will receive the data.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful.
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_NO_MORE_DATA if this field has already been fetched
- */
-HiveReturn DBGetFieldAsLong(HiveResultSet* resultset, size_t column_idx, long* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as an unsigned long int.
- *
- * Reads out a field from the currently fetched rowset in a resultset as an unsigned long int
- * (platform specific).
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to an unsigned long int that will receive the data.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful.
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_NO_MORE_DATA if this field has already been fetched
- */
-HiveReturn DBGetFieldAsULong(HiveResultSet* resultset, size_t column_idx, unsigned long* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as an int64_t.
- *
- * Reads out a field from the currently fetched rowset in a resultset as a int64_t
- * (platform independent).
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to a int64_t that will receive the data.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful.
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_NO_MORE_DATA if this field has already been fetched
- */
-HiveReturn DBGetFieldAsI64(HiveResultSet* resultset, size_t column_idx, int64_t* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a field as an uint64_t.
- *
- * Reads out a field from the currently fetched rowset in a resultset as a uint64_t
- * (platform independent).
- *
- * @param resultset An initialized HiveResultSet.
- * @param column_idx Zero offset index of a column.
- * @param buffer Pointer to a uint64_t that will receive the data.
- * @param is_null_value Pointer to an int which will be set to 1 if the field contains a NULL value,
- * or 0 otherwise
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful.
- * HIVE_ERROR if an error occurred (error messages will be stored in err_buf)
- * HIVE_NO_MORE_DATA if this field has already been fetched
- */
-HiveReturn DBGetFieldAsI64U(HiveResultSet* resultset, size_t column_idx, uint64_t* buffer,
- int* is_null_value, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Destroys a HiveColumnDesc object.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc object to be removed from memory.
- * @param err_buf Buffer to receive an error message if HIVE_ERROR is returned.
- * NULL can be used if the caller does not care about the error message.
- * @param err_buf_len Size of the err_buf buffer.
- *
- * @return HIVE_SUCCESS if successful, or HIVE_ERROR if an error occurred
- * (error messages will be stored in err_buf)
- */
-HiveReturn DBCloseColumnDesc(HiveColumnDesc* column_desc, char* err_buf, size_t err_buf_len);
-
-/**
- * @brief Get a column name.
- *
- * Retrieves the column name of the associated column in the result table from
- * a HiveColumnDesc.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- * @param buffer Pointer to a buffer that will receive the column name as a C string
- * @param buffer_len Number of bytes allocated to buffer
- *
- * @return void
- */
-void DBGetColumnName(HiveColumnDesc* column_desc, char* buffer, size_t buffer_len);
-
-/**
- * @brief Get the column type name.
- *
- * Retrieves the name of the column type of the associated column in the result table
- * from a HiveColumnDesc.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- * @param buffer Pointer to a buffer that will receive the column type name as a C string
- * @param buffer_len Number of bytes allocated to buffer
- *
- * @return void
- */
-void DBGetColumnType(HiveColumnDesc* column_desc, char* buffer, size_t buffer_len);
-
-/**
- * @brief Get the column type as a HiveType.
- *
- * Retrieves the column type as a HiveType for the associated column in the result table
- * from a HiveColumnDesc.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- *
- * @return HiveType of the column.
- */
-HiveType DBGetHiveType(HiveColumnDesc* column_desc);
-
-/**
- * @brief Finds whether a column is nullable.
- *
- * Determines from a HiveColumnDesc whether a particular column in the result table is
- * able to contain NULLs.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- *
- * @return 1 if the column can contain NULLs, or
- * 0 if the column cannot contain NULLs
- */
-int DBGetIsNullable(HiveColumnDesc* column_desc);
-
-/**
- * @brief Finds whether a column is case sensitive.
- *
- * Determines from a HiveColumnDesc whether a particular column in the result table contains case
- * sensitive data
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- *
- * @return 1 if the column data is case sensitive, or
- * 0 otherwise
- */
-int DBGetIsCaseSensitive(HiveColumnDesc* column_desc);
-
-/**
- * @brief Finds the max display size of a column's fields.
- *
- * From a HiveColumnDesc, determines the maximum number of characters needed to represent a
- * field within this column.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- *
- * @return The maximum number of characters needed to represent a field within this column.
- */
-size_t DBGetMaxDisplaySize(HiveColumnDesc* column_desc);
-
-/**
- * @brief Finds the max (native) byte size of a column's fields.
- *
- * From a HiveColumnDesc, determines the number of bytes needed to store a field within this
- * column in its native type.
- *
- * @see DBCreateColumnDesc()
- *
- * @param column_desc A HiveColumnDesc associated with the column in question.
- *
- * @return The number of bytes needed to store a field within this column in its native type.
- */
-size_t DBGetFieldByteSize(HiveColumnDesc* column_desc);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif // __cpluscplus
-
-
-#endif // __hive_client_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/hiveclienthelper.cpp
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/hiveclienthelper.cpp b/odbc/src/cpp/hiveclienthelper.cpp
deleted file mode 100644
index b0f3aae..0000000
--- a/odbc/src/cpp/hiveclienthelper.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <algorithm>
-#include <assert.h>
-#include <string.h>
-
-#include "hiveclienthelper.h"
-#include "thriftserverconstants.h"
-
-using namespace std;
-
-/*****************************************************************
- * File Scope Variables (used only within this file)
- *****************************************************************/
-
-/*
- * g_hive_type_table: An array of HiveTypePairs used to define the mapping
- * between the name of a HiveType and its value. This array is only
- * used by the hiveTypeLookup function.
- */
-struct HiveTypePair {
- const char* type_name;
- const HiveType type_value;
-};
-
-static const HiveTypePair g_hive_type_table[] = {
- {VOID_TYPE_NAME, HIVE_VOID_TYPE},
- {BOOLEAN_TYPE_NAME, HIVE_BOOLEAN_TYPE},
- {TINYINT_TYPE_NAME, HIVE_TINYINT_TYPE},
- {SMALLINT_TYPE_NAME, HIVE_SMALLINT_TYPE},
- {INT_TYPE_NAME, HIVE_INT_TYPE},
- {BIGINT_TYPE_NAME, HIVE_BIGINT_TYPE},
- {FLOAT_TYPE_NAME, HIVE_FLOAT_TYPE},
- {DOUBLE_TYPE_NAME, HIVE_DOUBLE_TYPE},
- {STRING_TYPE_NAME, HIVE_STRING_TYPE},
- {DATE_TYPE_NAME, HIVE_DATE_TYPE},
- {DATETIME_TYPE_NAME, HIVE_DATETIME_TYPE},
- {TIMESTAMP_TYPE_NAME, HIVE_TIMESTAMP_TYPE},
- {LIST_TYPE_NAME, HIVE_LIST_TYPE},
- {MAP_TYPE_NAME, HIVE_MAP_TYPE},
- {STRUCT_TYPE_NAME, HIVE_STRUCT_TYPE}
-};
-
-/*****************************************************************
- * Global Helper Functions
- *****************************************************************/
-
-HiveType hiveTypeLookup(const char* hive_type_name) {
- assert(hive_type_name != NULL);
- for (unsigned int idx = 0; idx < LENGTH(g_hive_type_table); idx++) {
- if (strcmp(hive_type_name, g_hive_type_table[idx].type_name) == 0) {
- return g_hive_type_table[idx].type_value;
- }
- }
- return HIVE_UNKNOWN_TYPE;
-}
-
-size_t safe_strncpy(char* dest_buffer, const char* src_buffer, size_t num) {
- /* Make sure arguments are valid */
- if (num == 0 || dest_buffer == NULL || src_buffer == NULL)
- return 0;
-
- size_t len = min(num - 1, strlen(src_buffer));
- strncpy(dest_buffer, src_buffer, len); /* Copy only as much as needed */
- dest_buffer[len] = '\0'; /* NULL terminate in case strncpy copies exactly num-1 characters */
-
- /* Returns the number of bytes copied into the destination buffer (excluding the null terminator)*/
- return len;
-}
-
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/hiveclienthelper.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/hiveclienthelper.h b/odbc/src/cpp/hiveclienthelper.h
deleted file mode 100644
index 5814a03..0000000
--- a/odbc/src/cpp/hiveclienthelper.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file hiveclienthelper.h
- * @brief Provides some commonly used functions and macros.
- *
- *****************************************************************************/
-
-
-#ifndef __hive_client_helper_h__
-#define __hive_client_helper_h__
-
-#include <iostream>
-
-#include "hiveconstants.h"
-
-
-// TODO: add architecture specific macro definitions here if needed
-#ifdef ARCH32
-
-#elif defined(ARCH64)
-
-#else
-
-#endif
-
-/*****************************************************************
- * Macro Functions
- *****************************************************************/
-
-/**
- * @brief A macro that converts a string to a signed 64 bit integer.
- *
- * Macro will work for both 32 and 64 bit architectures
- */
-#define ATOI64(val) int64_t(strtoll(val, NULL, 10))
-
-/**
- * @brief A macro that converts a string to an unsigned 64 bit integer.
- *
- * Macro will work for both 32 and 64 bit architectures
- */
-#define ATOI64U(val) uint64_t(strtoull(val, NULL, 10))
-
-/**
- * @brief Convert a Macro'ed value to a string.
- *
- * Callers should only call STRINGIFY(x) and
- * should never use XSTRINGIFY(x)
- */
-#define STRINGIFY(x) XSTRINGIFY(x)
-#define XSTRINGIFY(x) #x
-
-/**
- * @brief Finds the number of elements in an array
- */
-#define LENGTH(arr) (sizeof(arr)/sizeof(arr[0]))
-
-/**
- * Checks an error condition, and if true:
- * 1. prints the error
- * 2. saves the message to err_buf
- * 3. returns the specified ret_val
- */
-#define RETURN_ON_ASSERT(condition, funct_name, error_msg, err_buf, err_buf_len, ret_val) { \
- if (condition) { \
- cerr << funct_name << ": " << error_msg << endl << flush; \
- safe_strncpy(err_buf, error_msg, err_buf_len); \
- return ret_val; \
- } \
-}
-
-/**
- * Always performs the following:
- * 1. prints the error
- * 2. saves the message to err_buf
- * 3. returns the specified ret_val
- */
-#define RETURN_FAILURE(funct_name, error_msg, err_buf, err_buf_len, ret_val) { \
- RETURN_ON_ASSERT(true, funct_name, error_msg, err_buf, err_buf_len, ret_val); \
-}
-
-/*****************************************************************
- * Global Helper Functions
- *****************************************************************/
-
-/**
- * @brief Convert the name of a HiveType to its actual value.
- *
- * Returns the corresponding HiveType enum given the name of a Hive data type.
- * This function is case sensitive.
- * For example: hiveTypeLookup("string") => HIVE_STRING_TYPE
- *
- * @param hive_type_name Name of a HiveType
- * @return The corresponding HiveType
- */
-HiveType hiveTypeLookup(const char* hive_type_name);
-
-/**
- * @brief Safe version of strncpy.
- *
- * A version of strncpy that guarantees the existance of '\0' at the end of the supplied buffer
- * to prevent buffer overruns. Instead of returning dest_buffer like strncpy, safe_strncpy
- * returns the number of bytes written to dest_buffer (excluding the null terminator).
- *
- * @param dest_buffer Buffer to write into.
- * @param src_buffer Buffer to copy from.
- * @param num The size of the destination buffer in bytes.
- *
- * @return Number of bytes copied into the destination buffer (excluding the null terminator).
- */
-size_t safe_strncpy(char* dest_buffer, const char* src_buffer, size_t num);
-
-
-#endif // __hive_client_helper_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/hiveconstants.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/hiveconstants.h b/odbc/src/cpp/hiveconstants.h
deleted file mode 100644
index 72f1049..0000000
--- a/odbc/src/cpp/hiveconstants.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file hiveconstants.h
- * @brief Provides constants necessary for library caller interaction with Hive Client
- *
- *****************************************************************************/
-
-
-#ifndef __hive_constants_h__
-#define __hive_constants_h__
-
-/// Maximum length of a Hive Client error message
-static const int MAX_HIVE_ERR_MSG_LEN = 128;
-/// Maximum length of a column name
-static const int MAX_COLUMN_NAME_LEN = 64;
-/// Maximum length of a column type name
-static const int MAX_COLUMN_TYPE_LEN = 64;
-
-
-/* Default connection parameters */
-/// Default Hive database name
-static const char* DEFAULT_DATABASE = "default";
-/// Default Hive Server host
-static const char* DEFAULT_HOST = "localhost";
-/// Default Hive Server port
-static const char* DEFAULT_PORT = "10000";
-/// Default connection socket type
-static const char* DEFAULT_FRAMED = "0";
-
-/**
- * Enumeration of known Hive data types
- */
-enum HiveType
-{
- HIVE_VOID_TYPE,
- HIVE_BOOLEAN_TYPE,
- HIVE_TINYINT_TYPE,
- HIVE_SMALLINT_TYPE,
- HIVE_INT_TYPE,
- HIVE_BIGINT_TYPE,
- HIVE_FLOAT_TYPE,
- HIVE_DOUBLE_TYPE,
- HIVE_STRING_TYPE,
- HIVE_DATE_TYPE,
- HIVE_DATETIME_TYPE,
- HIVE_TIMESTAMP_TYPE,
- HIVE_LIST_TYPE,
- HIVE_MAP_TYPE,
- HIVE_STRUCT_TYPE,
- HIVE_UNKNOWN_TYPE
-};
-
-/**
- * Enumeration of Hive return values
- */
-enum HiveReturn
-{
- HIVE_SUCCESS,
- HIVE_ERROR,
- HIVE_NO_MORE_DATA,
- HIVE_SUCCESS_WITH_MORE_DATA,
- HIVE_STILL_EXECUTING
-};
-
-#endif // __hive_constants_h__
http://git-wip-us.apache.org/repos/asf/hive/blob/3468a666/odbc/src/cpp/thriftserverconstants.h
----------------------------------------------------------------------
diff --git a/odbc/src/cpp/thriftserverconstants.h b/odbc/src/cpp/thriftserverconstants.h
deleted file mode 100644
index fe4bac4..0000000
--- a/odbc/src/cpp/thriftserverconstants.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**************************************************************************//**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- *
- * @file thriftserverconstants.h
- * @brief Provides constants necessary for Hive Client interaction with Hive Server
- *
- *****************************************************************************/
-
-
-#ifndef __thrift_server_constants_h__
-#define __thrift_server_constants_h__
-
-/// Maximum number of characters needed to display any field
-static const int MAX_DISPLAY_SIZE = 334;
-/// Maximum number of bytes needed to store any field
-static const int MAX_BYTE_LENGTH = 334;
-
-
-/// Default null format string representation
-static const char* DEFAULT_NULL_FORMAT = "\\N";
-
-/// Schema map property key for field delimiters
-static const char* FIELD_DELIM = "field.delim";
-/// Schema map property key for null format
-static const char* SERIALIZATION_NULL_FORMAT = "serialization.null.format";
-
-
-// From: serde/src/gen-java/org/apache/hadoop/hive/serde/Constants.java
-
-static const char* VOID_TYPE_NAME = "void";
-static const char* BOOLEAN_TYPE_NAME = "boolean";
-static const char* TINYINT_TYPE_NAME = "tinyint";
-static const char* SMALLINT_TYPE_NAME = "smallint";
-static const char* INT_TYPE_NAME = "int";
-static const char* BIGINT_TYPE_NAME = "bigint";
-static const char* FLOAT_TYPE_NAME = "float";
-static const char* DOUBLE_TYPE_NAME = "double";
-static const char* STRING_TYPE_NAME = "string";
-static const char* DATE_TYPE_NAME = "date";
-static const char* DATETIME_TYPE_NAME = "datetime";
-static const char* TIMESTAMP_TYPE_NAME = "timestamp";
-static const char* LIST_TYPE_NAME = "array";
-static const char* MAP_TYPE_NAME = "map";
-static const char* STRUCT_TYPE_NAME = "struct";
-
-
-#endif // __thrift_server_constants_h__