Skip to content

Commit

Permalink
SQL: Return functions in JDBC driver metadata (#33672)
Browse files Browse the repository at this point in the history
Update JDBC database metadata to advertised the supported functions
Add aliases to some date/time functions to match the ODBC spec

Fix #33671
  • Loading branch information
costin authored Sep 14, 2018
1 parent 0b4960f commit 736053c
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 195 deletions.
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

0 comments on commit 736053c

Please sign in to comment.