Skip to content

Commit

Permalink
Add VERSION type support (#312)
Browse files Browse the repository at this point in the history
This adds support for the ES/SQL 'VERSION' type.
The type is mapped to varchar.

(cherry picked from commit 0d8b656)
  • Loading branch information
bpintea committed Oct 4, 2022
1 parent e836e51 commit 6d5b4ac
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
11 changes: 10 additions & 1 deletion driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#define TYPE_BOOLEAN "BOOLEAN"
#define TYPE_INTEGER "INTEGER"
#define TYPE_KEYWORD "KEYWORD"
#define TYPE_VERSION "VERSION"
/* 8 */
#define TYPE_DATETIME "DATETIME"
/* 9 */
Expand Down Expand Up @@ -2297,7 +2298,7 @@ static BOOL elastic_name2types(wstr_st *type_name,
}
break;

/* 7: INTEGER, BOOLEAN, KEYWORD */
/* 7: INTEGER, BOOLEAN, KEYWORD, VERSION */
case sizeof(TYPE_INTEGER) - 1:
switch (tolower(type_name->str[0])) {
case (SQLWCHAR)'i': /* integer */
Expand All @@ -2324,6 +2325,14 @@ static BOOL elastic_name2types(wstr_st *type_name,
return TRUE;
}
break;
case (SQLWCHAR)'v': /* version */
if (wmemncasecmp(type_name->str, MK_WPTR(TYPE_VERSION),
type_name->cnt) == 0) {
*c_sql = ES_VERSION_TO_CSQL;
*sql = ES_VERSION_TO_SQL;
return TRUE;
}
break;
}
break;

Expand Down
5 changes: 4 additions & 1 deletion driver/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
#define ESODBC_SQL_NESTED 2002

/* the SQL type ES/SQL uses for string types (KEYWORD, TEXT),
* plus IP and GEO */
* plus IP, VERSION and GEO */
#define ESODBC_SQL_VARCHAR SQL_VARCHAR

/* C SQL and SQL types for ES types that
Expand Down Expand Up @@ -474,6 +474,9 @@
/* 12: IP */
#define ES_IP_TO_CSQL ES_VARCHAR_CSQL
#define ES_IP_TO_SQL ES_VARCHAR_SQL
/* 12: VERSION */
#define ES_VERSION_TO_CSQL ES_VARCHAR_CSQL
#define ES_VERSION_TO_SQL ES_VARCHAR_SQL
/* 92: TIME */
#define ES_TIME_TO_CSQL SQL_C_TYPE_TIME
#define ES_TIME_TO_SQL SQL_TYPE_TIME
Expand Down
9 changes: 5 additions & 4 deletions driver/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -2513,8 +2513,9 @@ esodbc_estype_st *lookup_es_type(esodbc_dbc_st *dbc,
SQLULEN i;
SQLINTEGER sz;

/* for strings, choose text straight away: some type (IP, GEO) must coform
* to a format and no content inspection is done in the driver */
/* for strings, choose text straight away: some types (IP, VERSION, GEO)
* must conform to a format and no content inspection is done in the driver
*/
if (es_type == ES_VARCHAR_SQL || es_type == ES_WVARCHAR_SQL) {
return dbc->max_varchar_type;
}
Expand Down Expand Up @@ -2554,7 +2555,7 @@ static esodbc_estype_st *match_es_type(esodbc_rec_st *irec)
return dbc->max_float_type;
break;
case ES_WVARCHAR_SQL: /* KEYWORD, TEXT */
case ES_VARCHAR_SQL: /* IP, GEO+ */
case ES_VARCHAR_SQL: /* IP, VERSION, GEO+ */
return dbc->max_varchar_type;
default:
/* unequivocal match */
Expand Down Expand Up @@ -2877,7 +2878,7 @@ static SQLRETURN convert_param_val(esodbc_rec_st *arec, esodbc_rec_st *irec,

/* JSON string */
case ES_WVARCHAR_SQL: /* KEYWORD, TEXT */
case ES_VARCHAR_SQL: /* IP, GEO+ */
case ES_VARCHAR_SQL: /* IP, VERSION, GEO+ */
return c2sql_varchar(arec, irec, pos, dest, len);

case SQL_TYPE_DATE:
Expand Down
1 change: 1 addition & 0 deletions test/connected_dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extern "C" {
[\"IP\", 12, 45, \"'\", \"'\", null, 2, false, 3, true, false, false, null, null, null, 12, 0, null, null],\
[\"KEYWORD\", 12, 32766, \"'\", \"'\", null, 2, true, 3, true, false, false, null, null, null, 12, 0, null, null],\
[\"TEXT\", 12, 2147483647, \"'\", \"'\", null, 2, true, 3, true, false, false, null, null, null, 12, 0, null, null],\
[\"VERSION\", 12, 2147483647, \"'\", \"'\", null, 2, true, 3, true, false, false, null, null, null, 12, 0, null, null],\
[\"BOOLEAN\", 16, 1, \"'\", \"'\", null, 2, false, 3, true, false, false, null, null, null, 16, 0, null, null],\
[\"DATE\", 91, 29, \"'\", \"'\", null, 2, false, 3, true, false, false, null, 3, 3, 91, 0, null, null],\
[\"TIME\", 92, 18, \"'\", \"'\", null, 2, false, 3, true, false, false, null, null, null, 92, 0, null, null],\
Expand Down
1 change: 1 addition & 0 deletions test/integration/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _update_es_yaml(self, es_dir, append=True):
with open(yaml, mode="a" if append else "w", newline="\n") as f:
f.write("#\n# ODBC Integration Test\n#\n")
f.write("xpack.security.enabled: True\n")
f.write("xpack.watcher.enabled: False\n")
f.write("http.port: %s\n" % self._port) # don't bind on next avail port
f.write("cluster.routing.allocation.disk.threshold_enabled: False\n")

Expand Down

0 comments on commit 6d5b4ac

Please sign in to comment.