Skip to content

Commit

Permalink
organize enums, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-nl committed Dec 21, 2024
1 parent ed33af6 commit 75e6565
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 21 deletions.
17 changes: 9 additions & 8 deletions include/snowflake/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,20 @@ typedef enum SF_STMT_ATTRIBUTE {
* The query status
*/
typedef enum SF_QUERY_STATUS {
SF_QUERY_STATUS_RUNNING,
SF_QUERY_STATUS_ABORTED,
SF_QUERY_STATUS_ABORTING,
SF_QUERY_STATUS_SUCCESS,
SF_QUERY_STATUS_BLOCKED,
SF_QUERY_STATUS_DISCONNECTED,
SF_QUERY_STATUS_FAILED_WITH_ERROR,
SF_QUERY_STATUS_ABORTED,
SF_QUERY_STATUS_QUEUED,
SF_QUERY_STATUS_FAILED_WITH_INCIDENT,
SF_QUERY_STATUS_DISCONNECTED,
SF_QUERY_STATUS_RESUMING_WAREHOUSE,
SF_QUERY_STATUS_NO_DATA,
SF_QUERY_STATUS_RUNNING,
SF_QUERY_STATUS_QUEUED,
SF_QUERY_STATUS_QUEUED_REPAIRING_WAREHOUSE,
SF_QUERY_STATUS_RESTARTED,
SF_QUERY_STATUS_BLOCKED,
SF_QUERY_STATUS_NO_DATA
SF_QUERY_STATUS_RESUMING_WAREHOUSE,
SF_QUERY_STATUS_SUCCESS,
SF_QUERY_STATUS_UNKNOWN
} SF_QUERY_STATUS;

/**
Expand Down
2 changes: 1 addition & 1 deletion include/snowflake/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void STDCALL sf_memory_error_handler();
// this should be called by application before any calls of sfclient
void STDCALL sf_exception_on_memory_failure();

void STDCALL sf_sleep_ms(int sleep_ms);
void sf_sleep_ms(int sleep_ms);


#ifdef __cplusplus
Expand Down
23 changes: 12 additions & 11 deletions lib/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ _reset_connection_parameters(SF_CONNECT *sf, cJSON *parameters,
cJSON *session_info, sf_bool do_validate);

static const char* query_status_names[] = {
"RUNNING",
"ABORTED",
"ABORTING",
"SUCCESS",
"BLOCKED",
"DISCONNECTED",
"FAILED_WITH_ERROR",
"ABORTED",
"QUEUED",
"FAILED_WITH_INCIDENT",
"DISCONNECTED",
"RESUMING_WAREHOUSE",
"NO_DATA",
"RUNNING",
"QUEUED",
"QUEUED_REPAIRING_WAREHOUSE",
"RESTARTED",
"BLOCKED",
"NO_DATA"
"RESUMING_WAREHOUSE",
"SUCCESS",
"UNKNOWN"
};

/**
Expand All @@ -84,10 +85,10 @@ sf_bool validate_application(const char *application);
*/
SF_QUERY_STATUS get_status_from_string(const char *query_status) {
if (query_status == NULL) {
return SF_QUERY_STATUS_NO_DATA;
return SF_QUERY_STATUS_UNKNOWN;
}
int idx = 0, last = 0;
for (idx = 0, last = (int)SF_QUERY_STATUS_NO_DATA; idx <= last; ++idx) {
for (idx = 0, last = (int)SF_QUERY_STATUS_UNKNOWN; idx <= last; ++idx) {
size_t len = strlen(query_status_names[idx]);
if (sf_strncasecmp(query_status_names[idx], query_status, len) == 0) {
return (SF_QUERY_STATUS)idx;
Expand All @@ -108,7 +109,7 @@ char *get_query_metadata(SF_STMT* sfstmt) {
cJSON *data = NULL;
cJSON *queries = NULL;
char *s_resp = NULL;
size_t url_size = strlen(QUERY_MONITOR_URL) -2 + strlen(sfstmt->sfqid) + 1;
size_t url_size = strlen(QUERY_MONITOR_URL) - 2 + strlen(sfstmt->sfqid) + 1;
char *status_query = (char*)SF_CALLOC(1, url_size);
sf_sprintf(status_query, url_size, QUERY_MONITOR_URL, sfstmt->sfqid);

Expand Down
2 changes: 1 addition & 1 deletion lib/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ struct tm* sfchrono_localtime(const time_t *timep, struct tm *tm)
}
#endif

void STDCALL sf_sleep_ms(int sleep_ms)
void sf_sleep_ms(int sleep_ms)
{
#ifdef _WIN32
Sleep(sleep_ms);
Expand Down
38 changes: 38 additions & 0 deletions tests/test_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,43 @@ void test_invalid_query_id() {
assert_null(async_sfstmt->result_set);
}

void test_multiple_chunk() {
SF_CONNECT* sf = setup_snowflake_connection();
SF_STATUS status = snowflake_connect(sf);
if (status != SF_STATUS_SUCCESS) {
dump_error(&(sf->error));
}
assert_int_equal(status, SF_STATUS_SUCCESS);

/* query */
SF_STMT* sfstmt = snowflake_stmt(sf);
status = snowflake_prepare(sfstmt, "select randstr(100,random()) from table(generator(rowcount=>10000))", 0);
assert_int_equal(status, SF_STATUS_SUCCESS);
status = snowflake_async_execute(sfstmt);
if (status != SF_STATUS_SUCCESS) {
dump_error(&(sfstmt->error));
}
assert_int_equal(status, SF_STATUS_SUCCESS);

/* get results */
char* value = NULL;
size_t value_len = 0;
size_t max_value_size = 0;
assert_int_equal(snowflake_num_rows(sfstmt), 10000);

while ((status = snowflake_fetch(sfstmt)) == SF_STATUS_SUCCESS) {
snowflake_column_as_str(sfstmt, 1, &value, &value_len, &max_value_size);
assert_int_equal(strlen(value), 100);
}
SF_FREE(value);
if (status != SF_STATUS_EOF) {
dump_error(&(sfstmt->error));
}
assert_int_equal(status, SF_STATUS_EOF);
snowflake_stmt_term(sfstmt);
snowflake_term(sf);
}

int main(void) {
initialize_test(SF_BOOLEAN_FALSE);
const struct CMUnitTest tests[] = {
Expand All @@ -238,6 +275,7 @@ int main(void) {
cmocka_unit_test(test_new_connection),
cmocka_unit_test(test_fake_table),
cmocka_unit_test(test_invalid_query_id),
cmocka_unit_test(test_multiple_chunk),
};
int ret = cmocka_run_group_tests(tests, NULL, NULL);
snowflake_global_term();
Expand Down

0 comments on commit 75e6565

Please sign in to comment.