Skip to content

Commit 04693c0

Browse files
author
easydatawarehousing
committed
C updates for Presto 0.66
1 parent 26bdb41 commit 04693c0

File tree

6 files changed

+1197
-1093
lines changed

6 files changed

+1197
-1093
lines changed

C/prestoclient/prestoclient.c

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ static PRESTOCLIENT* new_prestoclient()
153153
client->port = PRESTOCLIENT_DEFAULT_PORT;
154154
client->catalog = NULL;
155155
client->user = NULL;
156+
client->timezone = NULL;
157+
client->language = NULL;
156158
client->results = NULL;
157159
client->active_results = 0;
158160

@@ -310,6 +312,8 @@ static unsigned int openuri(enum E_HTTP_REQUEST_TYPES in_request_type,
310312
const char *in_schema,
311313
const char *in_useragent,
312314
const char *in_user,
315+
const char *in_timezone,
316+
const char *in_language,
313317
const unsigned long *in_buffersize,
314318
PRESTOCLIENT_RESULT *result
315319
)
@@ -410,11 +414,13 @@ static unsigned int openuri(enum E_HTTP_REQUEST_TYPES in_request_type,
410414
}
411415

412416
// HTTP Headers
413-
if (in_catalog) add_headerline(&headers, "X-Presto-Catalog", (char*)in_catalog);
414-
add_headerline(&headers, "X-Presto-Source", uasource);
415-
if (in_schema) add_headerline(&headers, "X-Presto-Schema", (char*)in_schema);
416-
if (in_useragent) add_headerline(&headers, "User-Agent", (char*)in_useragent);
417-
if (in_user) add_headerline(&headers, "X-Presto-User", (char*)in_user);
417+
if (in_catalog) add_headerline(&headers, "X-Presto-Catalog", (char*)in_catalog);
418+
add_headerline(&headers, "X-Presto-Source", uasource);
419+
if (in_schema) add_headerline(&headers, "X-Presto-Schema", (char*)in_schema);
420+
if (in_useragent) add_headerline(&headers, "User-Agent", (char*)in_useragent);
421+
if (in_user) add_headerline(&headers, "X-Presto-User", (char*)in_user);
422+
if (in_timezone) add_headerline(&headers, "X-Presto-Time-Zone", (char*)in_timezone);
423+
if (in_language) add_headerline(&headers, "X-Presto-Language", (char*)in_language);
418424

419425
// Set Writeback function and request body
420426
if (in_request_type == PRESTOCLIENT_HTTP_REQUEST_TYPE_POST || in_request_type == PRESTOCLIENT_HTTP_REQUEST_TYPE_GET)
@@ -505,6 +511,8 @@ static void cancel(PRESTOCLIENT_RESULT *result)
505511
result->client->useragent,
506512
result->client->user,
507513
NULL,
514+
NULL,
515+
NULL,
508516
(void*)result);
509517
}
510518
}
@@ -543,6 +551,8 @@ static bool prestoclient_queryisrunning(PRESTOCLIENT_RESULT *result)
543551
prestoclient->useragent,
544552
prestoclient->user,
545553
NULL,
554+
NULL,
555+
NULL,
546556
(void*)result) == PRESTOCLIENT_RESULT_OK)
547557
{
548558
// Determine client state
@@ -607,7 +617,8 @@ char* prestoclient_getversion()
607617
}
608618

609619
PRESTOCLIENT* prestoclient_init(const char *in_server, const unsigned int *in_port, const char *in_catalog,
610-
const char *in_user, const char *in_pwd)
620+
const char *in_user, const char *in_pwd, const char *in_timezone,
621+
const char *in_language)
611622
{
612623
PRESTOCLIENT *client = NULL;
613624
char *uasource, *uaversion, *defaultcatalog;
@@ -649,6 +660,12 @@ PRESTOCLIENT* prestoclient_init(const char *in_server, const unsigned int *in_po
649660
{
650661
client->user = get_username();
651662
}
663+
664+
if (in_timezone)
665+
alloc_copy(&client->timezone, in_timezone);
666+
667+
if (in_language)
668+
alloc_copy(&client->language, in_language);
652669
}
653670

654671
return client;
@@ -672,6 +689,12 @@ void prestoclient_close(PRESTOCLIENT *prestoclient)
672689
if (prestoclient->user)
673690
free(prestoclient->user);
674691

692+
if (prestoclient->timezone)
693+
free(prestoclient->timezone);
694+
695+
if (prestoclient->language)
696+
free(prestoclient->language);
697+
675698
if (prestoclient->results)
676699
{
677700
for (i = 0; i < prestoclient->active_results; i++)
@@ -741,6 +764,8 @@ PRESTOCLIENT_RESULT* prestoclient_query(PRESTOCLIENT *prestoclient, const char *
741764
in_schema ? in_schema : defschema,
742765
prestoclient->useragent,
743766
prestoclient->user,
767+
prestoclient->timezone,
768+
prestoclient->language,
744769
&buffersize,
745770
(void*)result) == PRESTOCLIENT_RESULT_OK)
746771
{
@@ -840,6 +865,48 @@ char* prestoclient_getcolumntypedescription(PRESTOCLIENT_RESULT *result, const u
840865
break;
841866
}
842867

868+
case PRESTOCLIENT_TYPE_DATE:
869+
{
870+
return "PRESTO_DATE";
871+
break;
872+
}
873+
874+
case PRESTOCLIENT_TYPE_TIME:
875+
{
876+
return "PRESTO_TIME";
877+
break;
878+
}
879+
880+
case PRESTOCLIENT_TYPE_TIME_WITH_TIME_ZONE:
881+
{
882+
return "PRESTO_TIME_WITH_TIME_ZONE";
883+
break;
884+
}
885+
886+
case PRESTOCLIENT_TYPE_TIMESTAMP:
887+
{
888+
return "PRESTO_TIMESTAMP";
889+
break;
890+
}
891+
892+
case PRESTOCLIENT_TYPE_TIMESTAMP_WITH_TIME_ZONE:
893+
{
894+
return "PRESTO_TIMESTAMP_WITH_TIME_ZONE";
895+
break;
896+
}
897+
898+
case PRESTOCLIENT_TYPE_INTERVAL_YEAR_TO_MONTH:
899+
{
900+
return "PRESTO_INTERVAL_YEAR_TO_MONTH";
901+
break;
902+
}
903+
904+
case PRESTOCLIENT_TYPE_INTERVAL_DAY_TO_SECOND:
905+
{
906+
return "PRESTO_INTERVAL_DAY_TO_SECOND";
907+
break;
908+
}
909+
843910
default:
844911
{
845912
return "PRESTO_UNDEFINED";

C/prestoclient/prestoclient.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern "C" {
3737

3838
/* --- Defines -------------------------------------------------------------------------------------------------------- */
3939
#define PRESTOCLIENT_SOURCE "cPrestoClient" /**< Client name sent to Presto server */
40-
#define PRESTOCLIENT_VERSION "0.3.0" /**< PrestoClient version string */
40+
#define PRESTOCLIENT_VERSION "0.3.1" /**< PrestoClient version string */
4141
#define PRESTOCLIENT_URLTIMEOUT 5000 /**< Timeout in millisec to wait for Presto server to respond */
4242
#define PRESTOCLIENT_UPDATEWAITTIMEMSEC 1500 /**< Wait time in millisec to wait between requests to Presto server */
4343
#define PRESTOCLIENT_RETRIEVEWAITTIMEMSEC 50 /**< Wait time in millisec to wait before getting next data packet */
@@ -53,14 +53,22 @@ extern "C" {
5353
*/
5454
enum E_FIELDTYPES
5555
{
56-
PRESTOCLIENT_TYPE_UNDEFINED = 0,
57-
PRESTOCLIENT_TYPE_VARCHAR,
58-
PRESTOCLIENT_TYPE_BIGINT,
59-
PRESTOCLIENT_TYPE_BOOLEAN,
60-
PRESTOCLIENT_TYPE_DOUBLE
61-
// PRESTOCLIENT_TYPE_ARRAY,
62-
// PRESTOCLIENT_TYPE_MAP,
63-
// PRESTOCLIENT_TYPE_TIMESTAMP
56+
PRESTOCLIENT_TYPE_UNDEFINED = 0,
57+
PRESTOCLIENT_TYPE_VARCHAR,
58+
PRESTOCLIENT_TYPE_BIGINT,
59+
PRESTOCLIENT_TYPE_BOOLEAN,
60+
PRESTOCLIENT_TYPE_DOUBLE,
61+
// New in Presto V0.66
62+
PRESTOCLIENT_TYPE_DATE,
63+
PRESTOCLIENT_TYPE_TIME,
64+
PRESTOCLIENT_TYPE_TIME_WITH_TIME_ZONE,
65+
PRESTOCLIENT_TYPE_TIMESTAMP,
66+
PRESTOCLIENT_TYPE_TIMESTAMP_WITH_TIME_ZONE,
67+
PRESTOCLIENT_TYPE_INTERVAL_YEAR_TO_MONTH,
68+
PRESTOCLIENT_TYPE_INTERVAL_DAY_TO_SECOND
69+
// For future implementation
70+
// PRESTOCLIENT_TYPE_ARRAY,
71+
// PRESTOCLIENT_TYPE_MAP,
6472
};
6573

6674
/**
@@ -101,14 +109,18 @@ char* prestoclient_getversion();
101109
* \param in_catalog String contaning the Hive catalog name. May be NULL
102110
* \param in_user String contaning the username for the Presto server. May be NULL
103111
* \param in_pwd String contaning the password for the Presto server. May be NULL. Currently not used
112+
* \param in_timezone String contaning the Timezone for the Presto server. May be NULL. (IANA timezone format)
113+
* \param in_language String contaning the Language for the Presto server. May be NULL. (ISO-639-1 code)
104114
*
105115
* \return A handle to the PRESTOCLIENT object if successful or NULL if init failed
106116
*/
107117
PRESTOCLIENT* prestoclient_init ( const char *in_server
108118
, const unsigned int *in_port
109119
, const char *in_catalog
110120
, const char *in_user
111-
, const char *in_pwd);
121+
, const char *in_pwd
122+
, const char *in_timezone
123+
, const char *in_language);
112124

113125
/**
114126
* \brief Close client connection

0 commit comments

Comments
 (0)