diff --git a/docs/content.zh/docs/dev/table/functions/systemFunctions.md b/docs/content.zh/docs/dev/table/functions/systemFunctions.md index f3721c49321ad..db98900271744 100644 --- a/docs/content.zh/docs/dev/table/functions/systemFunctions.md +++ b/docs/content.zh/docs/dev/table/functions/systemFunctions.md @@ -118,43 +118,44 @@ JSON 函数使用符合 ISO/IEC TR 19075-6 SQL标准的 JSON 路径表达式。 下表列出了时间间隔单位和时间点单位标识符。 对于 Table API,请使用 `_` 代替空格(例如 `DAY_TO_HOUR`)。 - -| 时间间隔单位 | 时间点单位 | -| :------------------------ | :------------------------------ | -| `MILLENNIUM` | | -| `CENTURY` | | -| `DECADE` | | -| `YEAR` | `YEAR` | -| `YEAR TO MONTH` | | -| `QUARTER` | `QUARTER` | -| `MONTH` | `MONTH` | -| `WEEK` | `WEEK` | -| `DAY` | `DAY` | -| `DAY TO HOUR` | | -| `DAY TO MINUTE` | | -| `DAY TO SECOND` | | -| `HOUR` | `HOUR` | -| `HOUR TO MINUTE` | | -| `HOUR TO SECOND` | | -| `MINUTE` | `MINUTE` | -| `MINUTE TO SECOND` | | -| `SECOND` | `SECOND` | -| `MILLISECOND` | `MILLISECOND` | -| `MICROSECOND` | `MICROSECOND` | -| `NANOSECOND` | | -| `EPOCH` | | -| `DOY` _(仅适用SQL)_ | | -| `DOW` _(仅适用SQL)_ | | -| `ISODOW` _(仅适用SQL)_ | | -| `ISOYEAR` _(仅适用SQL)_ | | -| | `SQL_TSI_YEAR` _(仅适用SQL)_ | -| | `SQL_TSI_QUARTER` _(仅适用SQL)_ | -| | `SQL_TSI_MONTH` _(仅适用SQL)_ | -| | `SQL_TSI_WEEK` _(仅适用SQL)_ | -| | `SQL_TSI_DAY` _(仅适用SQL)_ | -| | `SQL_TSI_HOUR` _(仅适用SQL)_ | -| | `SQL_TSI_MINUTE` _(仅适用SQL)_ | -| | `SQL_TSI_SECOND ` _(仅适用SQL)_ | +Plural works for SQL only. + +| 时间间隔单位 | 时间点单位 | +|:-------------------------|:-----------------------------| +| `MILLENNIUM` | | +| `CENTURY` | | +| `DECADE` | | +| `YEAR(S)` | `YEAR` | +| `YEAR(S) TO MONTH(S)` | | +| `QUARTER(S)` | `QUARTER` | +| `MONTH(S)` | `MONTH` | +| `WEEK(S)` | `WEEK` | +| `DAY(S)` | `DAY` | +| `DAY(S) TO HOUR(S)` | | +| `DAY(S) TO MINUTE(S)` | | +| `DAY(S) TO SECOND(S)` | | +| `HOUR(S)` | `HOUR` | +| `HOUR(S) TO MINUTE(S)` | | +| `HOUR(S) TO SECOND(S)` | | +| `MINUTE(S)` | `MINUTE` | +| `MINUTE(S) TO SECOND(S)` | | +| `SECOND(S)` | `SECOND` | +| `MILLISECOND` | `MILLISECOND` | +| `MICROSECOND` | `MICROSECOND` | +| `NANOSECOND` | | +| `EPOCH` | | +| `DOY` _(仅适用SQL)_ | | +| `DOW` _(仅适用SQL)_ | | +| `ISODOW` _(仅适用SQL)_ | | +| `ISOYEAR` _(仅适用SQL)_ | | +| | `SQL_TSI_YEAR` _(仅适用SQL)_ | +| | `SQL_TSI_QUARTER` _(仅适用SQL)_ | +| | `SQL_TSI_MONTH` _(仅适用SQL)_ | +| | `SQL_TSI_WEEK` _(仅适用SQL)_ | +| | `SQL_TSI_DAY` _(仅适用SQL)_ | +| | `SQL_TSI_HOUR` _(仅适用SQL)_ | +| | `SQL_TSI_MINUTE` _(仅适用SQL)_ | +| | `SQL_TSI_SECOND ` _(仅适用SQL)_ | {{< top >}} diff --git a/docs/content.zh/docs/dev/table/sql/queries/overview.md b/docs/content.zh/docs/dev/table/sql/queries/overview.md index 6f8b12193f047..d478ce446e532 100644 --- a/docs/content.zh/docs/dev/table/sql/queries/overview.md +++ b/docs/content.zh/docs/dev/table/sql/queries/overview.md @@ -426,6 +426,21 @@ Flink SQL> SELECT 'Hello World', 'It''s me'; - 使用反斜杠(`\`)作为转义字符 (默认):`SELECT U&'\263A'` - 使用自定义的转义字符:`SELECT U&'#263A' UESCAPE '#'` +Starting Flink 2.0 there is C-style escape available + +| Backslash Escape Sequence | Interpretation | +|:----------------------------------|:--------------------------------------------------| +| \b | backspace | +| \f | form feed | +| \n | newline | +| \r | carriage return | +| \t | tab | +| \o, \oo, \ooo (o = 0–7) | octal byte value | +| \xh, \xhh (h = 0–9, A–F) | hexadecimal byte value | +| \uxxxx, \Uxxxxxxxx (x = 0–9, A–F) | 16 or 32-bit hexadecimal Unicode character value | + +Example: `SELECT e'\u0061\x61\141' AS c` or `SELECT E'\u0061\x61\141' AS c`; + {{< top >}} ## 操作 diff --git a/docs/content/docs/dev/table/functions/systemFunctions.md b/docs/content/docs/dev/table/functions/systemFunctions.md index 104aa47b9b267..7be1337f7b3cc 100644 --- a/docs/content/docs/dev/table/functions/systemFunctions.md +++ b/docs/content/docs/dev/table/functions/systemFunctions.md @@ -121,27 +121,28 @@ Time Interval and Point Unit Specifiers The following table lists specifiers for time interval and time point units. For Table API, please use `_` for spaces (e.g., `DAY_TO_HOUR`). +Plural works for SQL only. | Time Interval Unit | Time Point Unit | |:-------------------------|:-------------------------------| | `MILLENNIUM` | | | `CENTURY` | | | `DECADE` | | -| `YEAR` | `YEAR` | -| `YEAR TO MONTH` | | -| `QUARTER` | `QUARTER` | -| `MONTH` | `MONTH` | -| `WEEK` | `WEEK` | -| `DAY` | `DAY` | -| `DAY TO HOUR` | | -| `DAY TO MINUTE` | | -| `DAY TO SECOND` | | -| `HOUR` | `HOUR` | -| `HOUR TO MINUTE` | | -| `HOUR TO SECOND` | | -| `MINUTE` | `MINUTE` | -| `MINUTE TO SECOND` | | -| `SECOND` | `SECOND` | +| `YEAR(S)` | `YEAR` | +| `YEAR(S) TO MONTH(S)` | | +| `QUARTER(S)` | `QUARTER` | +| `MONTH(S)` | `MONTH` | +| `WEEK(S)` | `WEEK` | +| `DAY(S)` | `DAY` | +| `DAY(S) TO HOUR(S)` | | +| `DAY(S) TO MINUTE(S)` | | +| `DAY(S) TO SECOND(S)` | | +| `HOUR(S)` | `HOUR` | +| `HOUR(S) TO MINUTE(S)` | | +| `HOUR(S) TO SECOND(S)` | | +| `MINUTE(S)` | `MINUTE` | +| `MINUTE(S) TO SECOND(S)` | | +| `SECOND(S)` | `SECOND` | | `MILLISECOND` | `MILLISECOND` | | `MICROSECOND` | `MICROSECOND` | | `NANOSECOND` | | diff --git a/docs/content/docs/dev/table/sql/queries/overview.md b/docs/content/docs/dev/table/sql/queries/overview.md index a5cebac833c6d..006db6eddd9eb 100644 --- a/docs/content/docs/dev/table/sql/queries/overview.md +++ b/docs/content/docs/dev/table/sql/queries/overview.md @@ -426,6 +426,21 @@ Unicode characters are supported in string literals. If explicit unicode code po - Use the backslash (`\`) as escaping character (default): `SELECT U&'\263A'` - Use a custom escaping character: `SELECT U&'#263A' UESCAPE '#'` +Starting Flink 2.0 there is C-style escape available + +| Backslash Escape Sequence | Interpretation | +|:----------------------------------|:--------------------------------------------------| +| \b | backspace | +| \f | form feed | +| \n | newline | +| \r | carriage return | +| \t | tab | +| \o, \oo, \ooo (o = 0–7) | octal byte value | +| \xh, \xhh (h = 0–9, A–F) | hexadecimal byte value | +| \uxxxx, \Uxxxxxxxx (x = 0–9, A–F) | 16 or 32-bit hexadecimal Unicode character value | + +Example: `SELECT e'\u0061\x61\141' AS c` or `SELECT E'\u0061\x61\141' AS c`; + {{< top >}} ## Operations diff --git a/docs/content/docs/dev/table/sql/queries/select.md b/docs/content/docs/dev/table/sql/queries/select.md index 4b29d6e4de694..33a4024506033 100644 --- a/docs/content/docs/dev/table/sql/queries/select.md +++ b/docs/content/docs/dev/table/sql/queries/select.md @@ -32,7 +32,7 @@ The general syntax of the `SELECT` statement is: SELECT select_list FROM table_expression [ WHERE boolean_expression ] ``` -The `table_expression` refers to any source of data. It could be an existing table, view, or `VALUES` clause, the joined results of multiple existing tables, or a subquery. Assuming that the table is available in the catalog, the following would read all rows from `Orders`. +The `table_expression` refers to any source of data. It could be an existing table, view, `VALUES`, or `VALUE` clause, the joined results of multiple existing tables, or a subquery. Assuming that the table is available in the catalog, the following would read all rows from `Orders`. ```sql SELECT * FROM Orders diff --git a/flink-table/flink-sql-parser/pom.xml b/flink-table/flink-sql-parser/pom.xml index f7f10cc3dcb76..4e7c463db7818 100644 --- a/flink-table/flink-sql-parser/pom.xml +++ b/flink-table/flink-sql-parser/pom.xml @@ -62,12 +62,13 @@ under the License. ${calcite.version} diff --git a/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd b/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd index 64c450d573ec7..2a366116e93cd 100644 --- a/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd +++ b/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd @@ -708,4 +708,5 @@ includeCompoundIdentifier: true includeBraces: true includeAdditionalDeclarations: false + includeParsingStringLiteralAsArrayLiteral: false } diff --git a/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj b/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj index b299a703457df..57c5eec2373d8 100644 --- a/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj +++ b/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj @@ -161,7 +161,6 @@ public class ${parser.class} extends SqlAbstractParserImpl private Casing unquotedCasing; private Casing quotedCasing; private int identifierMaxLength; - private ImmutableMap timeUnitCodes; private SqlConformance conformance; /** @@ -223,10 +222,6 @@ public class ${parser.class} extends SqlAbstractParserImpl this.identifierMaxLength = identifierMaxLength; } - public void setTimeUnitCodes(Map timeUnitCodes) { - this.timeUnitCodes = ImmutableMap.copyOf(timeUnitCodes); - } - public void setConformance(SqlConformance conformance) { this.conformance = conformance; } @@ -243,6 +238,17 @@ public class ${parser.class} extends SqlAbstractParserImpl return SqlStmtList(); } + public SqlNode parseArray() throws SqlParseException { + switchTo(LexicalState.BQID); + try { + return ArrayLiteral(); + } catch (ParseException ex) { + throw normalizeException(ex); + } catch (TokenMgrError ex) { + throw normalizeException(ex); + } + } + private SqlNode extend(SqlNode table, SqlNodeList extendList) { return SqlStdOperatorTable.EXTEND.createCall( Span.of(table, extendList).pos(), table, extendList); @@ -2437,7 +2443,17 @@ SqlNode TableConstructor() : final Span s; } { - { s = span(); } + ( + { s = span(); } + | + + { + s = span(); + if (!this.conformance.isValueAllowed()) { + throw SqlUtil.newContextException(getPos(), RESOURCE.valueNotAllowed()); + } + } + ) AddRowConstructor(list) ( LOOKAHEAD(2) @@ -3485,9 +3501,9 @@ SqlNode LeafQueryOrExpr(ExprContext exprContext) : SqlNode e; } { - e = Expression(exprContext) { return e; } -| e = LeafQuery(exprContext) { return e; } +| + e = Expression(exprContext) { return e; } } /** As {@link #Expression} but appends to a list. */ @@ -4503,6 +4519,17 @@ SqlNode StringLiteral() : return SqlStdOperatorTable.LITERAL_CHAIN.createCall(pos2, rands); } } +| + + { + try { + p = SqlParserUtil.parseCString(getToken(0).image); + } catch (SqlParserUtil.MalformedUnicodeEscape e) { + throw SqlUtil.newContextException(getPos(), + RESOURCE.unicodeEscapeMalformed(e.i)); + } + return SqlLiteral.createCharString(p, "UTF16", getPos()); + } | { @@ -4581,15 +4608,24 @@ SqlLiteral DateTimeLiteral() : } | { s = span(); } p = SimpleStringLiteral() { - return SqlParserUtil.parseDateLiteral(p, s.end(this)); + return SqlLiteral.createUnknown("DATE", p, s.end(this)); + } +| + { s = span(); } p = SimpleStringLiteral() { + return SqlLiteral.createUnknown("DATETIME", p, s.end(this)); } |