Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Return functions in JDBC driver metadata #33672

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,34 @@ public String getSQLKeywords() throws SQLException {

@Override
public String getNumericFunctions() throws SQLException {
// TODO: sync this with the grammar
return "";
//https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/numeric-functions?view=sql-server-2017
return "ABS,ACOS,ASIN,ATAN,ATAN2,"
+ "CEILING,COS,"
+ "DEGREES,"
+ "EXP,"
+ "FLOOR,"
+ "LOG,LOG10,"
+ "MOD,"
+ "PI,POWER,"
+ "RADIANS,RAND,ROUND,"
+ "SIGN,SIN,SQRT,"
+ "TAN";
}

@Override
public String getStringFunctions() throws SQLException {
// TODO: sync this with the grammar
return "";
//https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/string-functions?view=sql-server-2017
return "ASCII,"
+ "BIT_LENGTH,"
+ "CHAR,CHAR_LENGTH,CHARACTER_LENGTH,CONCAT,"
+ "INSERT,"
+ "LCASE,LEFT,LENGTH,LOCATE,LTRIM,"
// waiting on https://github.com/elastic/elasticsearch/issues/33477
//+ "OCTET_LENGTH,"
+ "POSITION,"
+ "REPEAT,REPLACE,RIGHT,RTRIM,"
+ "SPACE,SUBSTRING,"
+ "UCASE";
}

@Override
Expand All @@ -197,7 +217,15 @@ public String getSystemFunctions() throws SQLException {

@Override
public String getTimeDateFunctions() throws SQLException {
return "";
//https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/time-date-and-interval-functions?view=sql-server-2017
return "DAYNAME,DAYOFMONTH,DAYOFWEEK,DAYOFYEAR"
+ "EXTRACT,"
+ "HOUR,"
+ "MINUTE,MONTH,MONTHNAME"
+ "QUARTER,"
+ "SECOND,"
+ "WEEK,"
+ "YEAR";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public class FunctionRegistry {
def(Kurtosis.class, Kurtosis::new),
// Scalar functions
// Date
def(DayOfMonth.class, DayOfMonth::new, "DAY", "DOM"),
def(DayOfWeek.class, DayOfWeek::new, "DOW"),
def(DayOfYear.class, DayOfYear::new, "DOY"),
def(DayOfMonth.class, DayOfMonth::new, "DAYOFMONTH", "DAY", "DOM"),
def(DayOfWeek.class, DayOfWeek::new, "DAYOFWEEK", "DOW"),
def(DayOfYear.class, DayOfYear::new, "DAYOFYEAR", "DOY"),
def(HourOfDay.class, HourOfDay::new, "HOUR"),
def(MinuteOfDay.class, MinuteOfDay::new),
def(MinuteOfHour.class, MinuteOfHour::new, "MINUTE"),
Expand Down Expand Up @@ -163,7 +163,7 @@ public class FunctionRegistry {
def(Ascii.class, Ascii::new),
def(Char.class, Char::new),
def(BitLength.class, BitLength::new),
def(CharLength.class, CharLength::new),
def(CharLength.class, CharLength::new, "CHARACTER_LENGTH"),
def(LCase.class, LCase::new),
def(Length.class, Length::new),
def(LTrim.class, LTrim::new),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ public void testShowFunctionsLikeInfix() throws IOException {
assertThat(command("SHOW FUNCTIONS LIKE '%DAY%'"), RegexMatcher.matches("\\s*name\\s*\\|\\s*type\\s*"));
assertThat(readLine(), containsString("----------"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAY_OF_MONTH\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAYOFMONTH\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAY\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAY_OF_WEEK\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAYOFWEEK\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAY_OF_YEAR\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAYOFYEAR\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*HOUR_OF_DAY\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*MINUTE_OF_DAY\\s*\\|\\s*SCALAR\\s*"));
assertThat(readLine(), RegexMatcher.matches("\\s*DAY_NAME\\s*\\|\\s*SCALAR\\s*"));
Expand Down
199 changes: 103 additions & 96 deletions x-pack/qa/sql/src/main/resources/command.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,97 @@ showFunctions
SHOW FUNCTIONS;

name:s | type:s
AVG |AGGREGATE
COUNT |AGGREGATE
MAX |AGGREGATE
MIN |AGGREGATE
SUM |AGGREGATE
STDDEV_POP |AGGREGATE
VAR_POP |AGGREGATE
PERCENTILE |AGGREGATE
PERCENTILE_RANK |AGGREGATE
SUM_OF_SQUARES |AGGREGATE
SKEWNESS |AGGREGATE
KURTOSIS |AGGREGATE
DAY_OF_MONTH |SCALAR
DAY |SCALAR
DOM |SCALAR
DAY_OF_WEEK |SCALAR
DOW |SCALAR
DAY_OF_YEAR |SCALAR
DOY |SCALAR
HOUR_OF_DAY |SCALAR
HOUR |SCALAR
MINUTE_OF_DAY |SCALAR
MINUTE_OF_HOUR |SCALAR
MINUTE |SCALAR
SECOND_OF_MINUTE|SCALAR
SECOND |SCALAR
MONTH_OF_YEAR |SCALAR
MONTH |SCALAR
YEAR |SCALAR
WEEK_OF_YEAR |SCALAR
WEEK |SCALAR
DAY_NAME |SCALAR
DAYNAME |SCALAR
MONTH_NAME |SCALAR
MONTHNAME |SCALAR
QUARTER |SCALAR
ABS |SCALAR
ACOS |SCALAR
ASIN |SCALAR
ATAN |SCALAR
ATAN2 |SCALAR
CBRT |SCALAR
CEIL |SCALAR
CEILING |SCALAR
COS |SCALAR
COSH |SCALAR
COT |SCALAR
DEGREES |SCALAR
E |SCALAR
EXP |SCALAR
EXPM1 |SCALAR
FLOOR |SCALAR
LOG |SCALAR
LOG10 |SCALAR
MOD |SCALAR
PI |SCALAR
POWER |SCALAR
RADIANS |SCALAR
RANDOM |SCALAR
RAND |SCALAR
ROUND |SCALAR
SIGN |SCALAR
SIGNUM |SCALAR
SIN |SCALAR
SINH |SCALAR
SQRT |SCALAR
TAN |SCALAR
ASCII |SCALAR
CHAR |SCALAR
BIT_LENGTH |SCALAR
CHAR_LENGTH |SCALAR
LCASE |SCALAR
LENGTH |SCALAR
LTRIM |SCALAR
RTRIM |SCALAR
SPACE |SCALAR
CONCAT |SCALAR
INSERT |SCALAR
LEFT |SCALAR
LOCATE |SCALAR
POSITION |SCALAR
REPEAT |SCALAR
REPLACE |SCALAR
RIGHT |SCALAR
SUBSTRING |SCALAR
UCASE |SCALAR
SCORE |SCORE
AVG |AGGREGATE
COUNT |AGGREGATE
MAX |AGGREGATE
MIN |AGGREGATE
SUM |AGGREGATE
STDDEV_POP |AGGREGATE
VAR_POP |AGGREGATE
PERCENTILE |AGGREGATE
PERCENTILE_RANK |AGGREGATE
SUM_OF_SQUARES |AGGREGATE
SKEWNESS |AGGREGATE
KURTOSIS |AGGREGATE
DAY_OF_MONTH |SCALAR
DAYOFMONTH |SCALAR
DAY |SCALAR
DOM |SCALAR
DAY_OF_WEEK |SCALAR
DAYOFWEEK |SCALAR
DOW |SCALAR
DAY_OF_YEAR |SCALAR
DAYOFYEAR |SCALAR
DOY |SCALAR
HOUR_OF_DAY |SCALAR
HOUR |SCALAR
MINUTE_OF_DAY |SCALAR
MINUTE_OF_HOUR |SCALAR
MINUTE |SCALAR
SECOND_OF_MINUTE|SCALAR
SECOND |SCALAR
MONTH_OF_YEAR |SCALAR
MONTH |SCALAR
YEAR |SCALAR
WEEK_OF_YEAR |SCALAR
WEEK |SCALAR
DAY_NAME |SCALAR
DAYNAME |SCALAR
MONTH_NAME |SCALAR
MONTHNAME |SCALAR
QUARTER |SCALAR
ABS |SCALAR
ACOS |SCALAR
ASIN |SCALAR
ATAN |SCALAR
ATAN2 |SCALAR
CBRT |SCALAR
CEIL |SCALAR
CEILING |SCALAR
COS |SCALAR
COSH |SCALAR
COT |SCALAR
DEGREES |SCALAR
E |SCALAR
EXP |SCALAR
EXPM1 |SCALAR
FLOOR |SCALAR
LOG |SCALAR
LOG10 |SCALAR
MOD |SCALAR
PI |SCALAR
POWER |SCALAR
RADIANS |SCALAR
RANDOM |SCALAR
RAND |SCALAR
ROUND |SCALAR
SIGN |SCALAR
SIGNUM |SCALAR
SIN |SCALAR
SINH |SCALAR
SQRT |SCALAR
TAN |SCALAR
ASCII |SCALAR
CHAR |SCALAR
BIT_LENGTH |SCALAR
CHAR_LENGTH |SCALAR
CHARACTER_LENGTH|SCALAR
LCASE |SCALAR
LENGTH |SCALAR
LTRIM |SCALAR
RTRIM |SCALAR
SPACE |SCALAR
CONCAT |SCALAR
INSERT |SCALAR
LEFT |SCALAR
LOCATE |SCALAR
POSITION |SCALAR
REPEAT |SCALAR
REPLACE |SCALAR
RIGHT |SCALAR
SUBSTRING |SCALAR
UCASE |SCALAR
SCORE |SCORE
;

showFunctionsWithExactMatch
Expand Down Expand Up @@ -128,15 +132,18 @@ ABS |SCALAR
showFunctionsWithLeadingPattern
SHOW FUNCTIONS LIKE '%DAY%';

name:s | type:s
DAY_OF_MONTH |SCALAR
DAY |SCALAR
DAY_OF_WEEK |SCALAR
DAY_OF_YEAR |SCALAR
HOUR_OF_DAY |SCALAR
MINUTE_OF_DAY |SCALAR
DAY_NAME |SCALAR
DAYNAME |SCALAR
name:s | type:s
DAY_OF_MONTH |SCALAR
DAYOFMONTH |SCALAR
DAY |SCALAR
DAY_OF_WEEK |SCALAR
DAYOFWEEK |SCALAR
DAY_OF_YEAR |SCALAR
DAYOFYEAR |SCALAR
HOUR_OF_DAY |SCALAR
MINUTE_OF_DAY |SCALAR
DAY_NAME |SCALAR
DAYNAME |SCALAR
;

showTables
Expand Down
Loading