Skip to content

Commit

Permalink
add keyword and functions support for sqlinfo (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
madesroches-ubi authored Dec 9, 2024
1 parent 6ec21af commit cdba7a7
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/public/src/servers/flight_sql_service_impl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use super::sqlinfo::{
SQL_INFO_DATE_TIME_FUNCTIONS, SQL_INFO_NUMERIC_FUNCTIONS, SQL_INFO_SQL_KEYWORDS,
SQL_INFO_STRING_FUNCTIONS, SQL_INFO_SYSTEM_FUNCTIONS,
};
use anyhow::Result;
use arrow_flight::encode::FlightDataEncoderBuilder;
use arrow_flight::error::FlightError;
Expand Down Expand Up @@ -63,6 +67,11 @@ static INSTANCE_SQL_DATA: Lazy<SqlInfoData> = Lazy::new(|| {
builder.append(SqlInfo::FlightSqlServerVersion, "1");
// 1.3 comes from https://github.com/apache/arrow/blob/f9324b79bf4fc1ec7e97b32e3cce16e75ef0f5e3/format/Schema.fbs#L24
builder.append(SqlInfo::FlightSqlServerArrowVersion, "1.3");
builder.append(SqlInfo::SqlKeywords, SQL_INFO_SQL_KEYWORDS);
builder.append(SqlInfo::SqlNumericFunctions, SQL_INFO_NUMERIC_FUNCTIONS);
builder.append(SqlInfo::SqlStringFunctions, SQL_INFO_STRING_FUNCTIONS);
builder.append(SqlInfo::SqlSystemFunctions, SQL_INFO_SYSTEM_FUNCTIONS);
builder.append(SqlInfo::SqlDatetimeFunctions, SQL_INFO_DATE_TIME_FUNCTIONS);
builder.build().unwrap()
});

Expand Down
3 changes: 3 additions & 0 deletions rust/public/src/servers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ pub mod maintenance;

/// minimal FlightSQL protocol implementation
pub mod flight_sql_service_impl;

/// metadata about this implementation of FlightSQL
pub mod sqlinfo;
299 changes: 299 additions & 0 deletions rust/public/src/servers/sqlinfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
// from https://github.com/influxdata/influxdb3_core/blob/main/flightsql/src/sql_info/

pub const SQL_INFO_SQL_KEYWORDS: &[&str] = &[
// SQL-92 Reserved Words
"absolute",
"action",
"add",
"all",
"allocate",
"alter",
"and",
"any",
"are",
"as",
"asc",
"assertion",
"at",
"authorization",
"avg",
"begin",
"between",
"bit",
"bit_length",
"both",
"by",
"cascade",
"cascaded",
"case",
"cast",
"catalog",
"char",
"char_length",
"character",
"character_length",
"check",
"close",
"coalesce",
"collate",
"collation",
"column",
"commit",
"connect",
"connection",
"constraint",
"constraints",
"continue",
"convert",
"corresponding",
"count",
"create",
"cross",
"current",
"current_date",
"current_time",
"current_timestamp",
"current_user",
"cursor",
"date",
"day",
"deallocate",
"dec",
"decimal",
"declare",
"default",
"deferrable",
"deferred",
"delete",
"desc",
"describe",
"descriptor",
"diagnostics",
"disconnect",
"distinct",
"domain",
"double",
"drop",
"else",
"end",
"end-exec",
"escape",
"except",
"exception",
"exec",
"execute",
"exists",
"external",
"extract",
"false",
"fetch",
"first",
"float",
"for",
"foreign",
"found",
"from",
"full",
"get",
"global",
"go",
"goto",
"grant",
"group",
"having",
"hour",
"identity",
"immediate",
"in",
"indicator",
"initially",
"inner",
"input",
"insensitive",
"insert",
"int",
"integer",
"intersect",
"interval",
"into",
"is",
"isolation",
"join",
"key",
"language",
"last",
"leading",
"left",
"level",
"like",
"local",
"lower",
"match",
"max",
"min",
"minute",
"module",
"month",
"names",
"national",
"natural",
"nchar",
"next",
"no",
"not",
"null",
"nullif",
"numeric",
"octet_length",
"of",
"on",
"only",
"open",
"option",
"or",
"order",
"outer",
"output",
"overlaps",
"pad",
"partial",
"position",
"precision",
"prepare",
"preserve",
"primary",
"prior",
"privileges",
"procedure",
"public",
"read",
"real",
"references",
"relative",
"restrict",
"revoke",
"right",
"rollback",
"rows",
"schema",
"scroll",
"second",
"section",
"select",
"session",
"session_user",
"set",
"size",
"smallint",
"some",
"space",
"sql",
"sqlcode",
"sqlerror",
"sqlstate",
"substring",
"sum",
"system_user",
"table",
"temporary",
"then",
"time",
"timestamp",
"timezone_hour",
"timezone_minute",
"to",
"trailing",
"transaction",
"translate",
"translation",
"trim",
"true",
"union",
"unique",
"unknown",
"update",
"upper",
"usage",
"user",
"using",
"value",
"values",
"varchar",
"varying",
"view",
"when",
"whenever",
"where",
"with",
"work",
"write",
"year",
"zone",
];

pub const SQL_INFO_NUMERIC_FUNCTIONS: &[&str] = &[
"abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "exp", "floor", "ln", "log", "log10",
"log2", "pow", "power", "round", "signum", "sin", "sqrt", "tan", "trunc",
];

pub const SQL_INFO_DATE_TIME_FUNCTIONS: &[&str] = &[
"current_date",
"current_time",
"date_bin",
"date_part",
"date_trunc",
"datepart",
"datetrunc",
"from_unixtime",
"now",
"to_timestamp",
"to_timestamp_micros",
"to_timestamp_millis",
"to_timestamp_seconds",
];

pub const SQL_INFO_SYSTEM_FUNCTIONS: &[&str] = &["array", "arrow_typeof", "struct"];

pub const SQL_INFO_STRING_FUNCTIONS: &[&str] = &[
"arrow_typeof",
"ascii",
"bit_length",
"btrim",
"char_length",
"character_length",
"chr",
"concat",
"concat_ws",
"digest",
"from_unixtime",
"initcap",
"left",
"length",
"lower",
"lpad",
"ltrim",
"md5",
"octet_length",
"random",
"regexp_match",
"regexp_replace",
"repeat",
"replace",
"reverse",
"right",
"rpad",
"rtrim",
"sha224",
"sha256",
"sha384",
"sha512",
"split_part",
"starts_with",
"strpos",
"substr",
"to_hex",
"translate",
"trim",
"upper",
"uuid",
];

0 comments on commit cdba7a7

Please sign in to comment.