Skip to content
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
13 changes: 13 additions & 0 deletions flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"org.apache.flink.sql.parser.ddl.SqlAlterCatalogOptions"
"org.apache.flink.sql.parser.ddl.SqlAlterCatalogReset"
"org.apache.flink.sql.parser.ddl.SqlAlterCatalogComment"
"org.apache.flink.sql.parser.ddl.SqlAlterConnection"
"org.apache.flink.sql.parser.ddl.SqlAlterConnectionRename"
"org.apache.flink.sql.parser.ddl.SqlAlterConnectionReset"
"org.apache.flink.sql.parser.ddl.SqlAlterConnectionSet"
"org.apache.flink.sql.parser.ddl.SqlAlterDatabase"
"org.apache.flink.sql.parser.ddl.SqlAlterFunction"
"org.apache.flink.sql.parser.ddl.SqlAlterMaterializedTable"
Expand Down Expand Up @@ -76,6 +80,7 @@
"org.apache.flink.sql.parser.ddl.SqlAlterViewRename"
"org.apache.flink.sql.parser.ddl.SqlCompilePlan"
"org.apache.flink.sql.parser.ddl.SqlCreateCatalog"
"org.apache.flink.sql.parser.ddl.SqlCreateConnection"
"org.apache.flink.sql.parser.ddl.SqlCreateDatabase"
"org.apache.flink.sql.parser.ddl.SqlCreateFunction"
"org.apache.flink.sql.parser.ddl.SqlCreateModel"
Expand All @@ -87,6 +92,7 @@
"org.apache.flink.sql.parser.ddl.SqlCreateView"
"org.apache.flink.sql.parser.ddl.SqlDistribution"
"org.apache.flink.sql.parser.ddl.SqlDropCatalog"
"org.apache.flink.sql.parser.ddl.SqlDropConnection"
"org.apache.flink.sql.parser.ddl.SqlDropDatabase"
"org.apache.flink.sql.parser.ddl.SqlDropFunction"
"org.apache.flink.sql.parser.ddl.SqlDropMaterializedTable"
Expand Down Expand Up @@ -137,12 +143,15 @@
"org.apache.flink.sql.parser.dql.SqlShowTables"
"org.apache.flink.sql.parser.dql.SqlShowTables.SqlTableKind"
"org.apache.flink.sql.parser.dql.SqlShowColumns"
"org.apache.flink.sql.parser.dql.SqlShowConnections"
"org.apache.flink.sql.parser.dql.SqlShowCreate"
"org.apache.flink.sql.parser.dql.SqlShowCreateConnection"
"org.apache.flink.sql.parser.dql.SqlShowCreateMaterializedTable"
"org.apache.flink.sql.parser.dql.SqlShowCreateModel"
"org.apache.flink.sql.parser.dql.SqlShowCreateTable"
"org.apache.flink.sql.parser.dql.SqlShowCreateView"
"org.apache.flink.sql.parser.dql.SqlShowCreateCatalog"
"org.apache.flink.sql.parser.dql.SqlRichDescribeConnection"
"org.apache.flink.sql.parser.dql.SqlRichDescribeFunction"
"org.apache.flink.sql.parser.dql.SqlRichDescribeModel"
"org.apache.flink.sql.parser.dql.SqlRichDescribeTable"
Expand Down Expand Up @@ -185,6 +194,7 @@
"COMMENT"
"COMPILE"
"COMPUTE"
"CONNECTIONS",
"CONTINUOUS"
"DATABASES"
"DISTRIBUTED"
Expand Down Expand Up @@ -618,12 +628,14 @@
"SqlAlterFunction()"
"SqlShowFunctions()"
"SqlShowModels()"
"SqlShowConnections()"
"SqlShowTables()"
"SqlShowColumns()"
"SqlShowCreate()"
"SqlReplaceTable()"
"SqlAlterMaterializedTable()"
"SqlAlterModel()"
"SqlAlterConnection()"
"SqlAlterTable()"
"SqlAlterView()"
"SqlShowModules()"
Expand All @@ -648,6 +660,7 @@
"SqlDescribeJob()"
"SqlRichDescribeFunction()"
"SqlRichDescribeModel()"
"SqlRichDescribeConnection()"
"SqlRichDescribeTable()"
]

Expand Down
216 changes: 210 additions & 6 deletions flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,13 @@ SqlShowCreate SqlShowCreate() :
{
return new SqlShowCreateModel(pos, sqlIdentifier);
}
|
<CONNECTION>
{ pos = getPos(); }
sqlIdentifier = CompoundIdentifier()
{
return new SqlShowCreateConnection(pos, sqlIdentifier);
}
|
<MATERIALIZED> <TABLE>
{ pos = getPos(); }
Expand All @@ -787,7 +794,7 @@ SqlShowCreate SqlShowCreate() :
}

/**
* DESCRIBE | DESC FUNCTION [ EXTENDED] [[catalogName.] dataBasesName].functionName sql call.
* (DESCRIBE | DESC) FUNCTION [ EXTENDED] [[catalogName.] dataBasesName].functionName sql call.
* Here we add Rich in className to match the naming of SqlRichDescribeTable.
*/
SqlRichDescribeFunction SqlRichDescribeFunction() :
Expand All @@ -806,7 +813,7 @@ SqlRichDescribeFunction SqlRichDescribeFunction() :
}

/**
* DESCRIBE | DESC MODEL [ EXTENDED] [[catalogName.] dataBasesName].modelName sql call.
* (DESCRIBE | DESC) MODEL [ EXTENDED] [[catalogName.] dataBasesName].modelName sql call.
* Here we add Rich in className to match the naming of SqlRichDescribeTable.
*/
SqlRichDescribeModel SqlRichDescribeModel() :
Expand All @@ -825,7 +832,26 @@ SqlRichDescribeModel SqlRichDescribeModel() :
}

/**
* DESCRIBE | DESC [ EXTENDED] [[catalogName.] dataBasesName].tableName sql call.
* (DESCRIBE | DESC) CONNECTION [ EXTENDED] [[catalogName.] dataBasesName].connectionName sql call.
* Here we add Rich in className to match the naming of SqlRichDescribeTable.
*/
SqlRichDescribeConnection SqlRichDescribeConnection() :
{
SqlIdentifier connectionName;
SqlParserPos pos;
boolean isExtended = false;
}
{
( <DESCRIBE> | <DESC> ) <CONNECTION> { pos = getPos();}
[ <EXTENDED> { isExtended = true;} ]
connectionName = CompoundIdentifier()
{
return new SqlRichDescribeConnection(pos, connectionName, isExtended);
}
}

/**
* (DESCRIBE | DESC) [ EXTENDED] [[catalogName.] dataBasesName].tableName sql call.
* Here we add Rich in className to distinguish from calcite's original SqlDescribeTable.
*/
SqlRichDescribeTable SqlRichDescribeTable() :
Expand Down Expand Up @@ -2663,9 +2689,13 @@ SqlCreate SqlCreateExtended(Span s, boolean replace) :
|
create = SqlCreateDatabase(s, replace)
|
create = SqlCreateModel(s, isTemporary)
|
// Lookahead to distinguish <SYSTEM> FUNCTION and <SYSTEM> <CONNECTION>
LOOKAHEAD(2)
create = SqlCreateFunction(s, replace, isTemporary)
|
create = SqlCreateModel(s, isTemporary)
create = SqlCreateConnection(s, isTemporary)
)
{
return create;
Expand All @@ -2692,9 +2722,13 @@ SqlDrop SqlDropExtended(Span s, boolean replace) :
|
drop = SqlDropDatabase(s, replace)
|
drop = SqlDropModel(s, isTemporary)
|
// Lookahead to distinguish <SYSTEM> FUNCTION and <SYSTEM> <CONNECTION>
LOOKAHEAD(2)
drop = SqlDropFunction(s, replace, isTemporary)
|
drop = SqlDropModel(s, isTemporary)
drop = SqlDropConnection(s, isTemporary)
)
{
return drop;
Expand Down Expand Up @@ -3325,7 +3359,7 @@ SqlTruncateTable SqlTruncateTable() :
}

/**
* SHOW MODELS [FROM [catalog.] database] [[NOT] LIKE pattern]; sql call.
* SHOW MODELS [FROM [catalog.] database] [[NOT] LIKE pattern];
*/
SqlShowModels SqlShowModels() :
{
Expand Down Expand Up @@ -3361,6 +3395,43 @@ SqlShowModels SqlShowModels() :
}
}

/**
* SHOW CONNECTIONS [LIKE 'pattern'] [FROM catalog_name.db_name];
*/
SqlShowConnections SqlShowConnections() :
{
SqlIdentifier databaseName = null;
SqlCharStringLiteral likeLiteral = null;
String prep = null;
boolean notLike = false;
SqlParserPos pos;
}
{
<SHOW> <CONNECTIONS>
{ pos = getPos(); }
[
( <FROM> { prep = "FROM"; } | <IN> { prep = "IN"; } )
{ pos = getPos(); }
databaseName = CompoundIdentifier()
]
[
[
<NOT>
{
notLike = true;
}
]
<LIKE> <QUOTED_STRING>
{
String likeCondition = SqlParserUtil.parseString(token.image);
likeLiteral = SqlLiteral.createCharString(likeCondition, getPos());
}
]
{
return new SqlShowConnections(pos, prep, databaseName, notLike, likeLiteral);
}
}

/**
* ALTER MODEL [IF EXISTS] modelName SET (property_key = property_val, ...)
* ALTER MODEL [IF EXISTS] modelName RENAME TO newModelName
Expand Down Expand Up @@ -3413,6 +3484,59 @@ SqlAlterModel SqlAlterModel() :
)
}

/**
* ALTER CONNECTION [IF EXISTS] connectionName SET (property_key = property_val, ...)
* ALTER CONNECTION [IF EXISTS] connectionName RENAME TO newConnectionName
* ALTER CONNECTION [IF EXISTS] connectionName RESET (property_key, ...)
* Alter temporary or system connection is not supported.
*/
SqlAlterConnection SqlAlterConnection() :
{
SqlParserPos startPos;
boolean ifExists = false;
SqlIdentifier connectionIdentifier;
SqlIdentifier newConnectionIdentifier = null;
SqlNodeList propertyList = SqlNodeList.EMPTY;
SqlNodeList propertyKeyList = SqlNodeList.EMPTY;
}
{
<ALTER> <CONNECTION> { startPos = getPos(); }
ifExists = IfExistsOpt()
connectionIdentifier = CompoundIdentifier()
(
LOOKAHEAD(2)
<RENAME> <TO>
newConnectionIdentifier = CompoundIdentifier()
{
return new SqlAlterConnectionRename(
startPos.plus(getPos()),
connectionIdentifier,
newConnectionIdentifier,
ifExists);
}
|
<SET>
propertyList = Properties()
{
return new SqlAlterConnectionSet(
startPos.plus(getPos()),
connectionIdentifier,
ifExists,
propertyList);
}
|
<RESET>
propertyKeyList = PropertyKeys()
{
return new SqlAlterConnectionReset(
startPos.plus(getPos()),
connectionIdentifier,
ifExists,
propertyKeyList);
}
)
}

/**
* DROP MODEL [IF EXIST] modelName
*/
Expand All @@ -3433,6 +3557,38 @@ SqlDrop SqlDropModel(Span s, boolean isTemporary) :
}
}

/**
* DROP [TEMPORARY] [SYSTEM] CONNECTION [IF EXIST] connectionName
*/
SqlDrop SqlDropConnection(Span s, boolean isTemporary) :
{
SqlIdentifier connectionIdentifier = null;
boolean ifExists = false;
boolean isSystemConnection = false;
}
{
[
<SYSTEM>
{
if (!isTemporary){
throw SqlUtil.newContextException(getPos(),
ParserResource.RESOURCE.dropSystemConnectionOnlySupportTemporary());
}
isSystemConnection = true;
}
]

<CONNECTION>

ifExists = IfExistsOpt()

connectionIdentifier = CompoundIdentifier()

{
return new SqlDropConnection(s.pos(), connectionIdentifier, ifExists, isTemporary, isSystemConnection);
}
}

/**
* CREATE MODEL [IF NOT EXIST] modelName
* [INPUT(col1 type1, col2 type2, ...)]
Expand Down Expand Up @@ -3519,6 +3675,54 @@ SqlCreate SqlCreateModel(Span s, boolean isTemporary) :
}
}

/**
* CREATE [TEMPORARY] [SYSTEM] CONNECTION [IF NOT EXISTS] [catalog_name.][db_name.]connection_name
* [COMMENT connection_comment]
* WITH (property_key = property_val, ...)
*/
SqlCreate SqlCreateConnection(Span s, boolean isTemporary) :
{
final SqlParserPos startPos = s.pos();
boolean ifNotExists = false;
boolean isSystem = false;
SqlIdentifier connectionIdentifier;
SqlCharStringLiteral comment = null;
SqlNodeList propertyList = SqlNodeList.EMPTY;
}
{
[
<SYSTEM>
{
if (!isTemporary){
throw SqlUtil.newContextException(getPos(),
ParserResource.RESOURCE.createSystemConnectionOnlySupportTemporary());
}
isSystem = true;
}
]
<CONNECTION>

ifNotExists = IfNotExistsOpt()

connectionIdentifier = CompoundIdentifier()
[ <COMMENT> <QUOTED_STRING>
{
comment = Comment();
}
]
<WITH>
propertyList = Properties()
{
return new SqlCreateConnection(startPos.plus(getPos()),
connectionIdentifier,
comment,
propertyList,
isTemporary,
isSystem,
ifNotExists);
}
}

SqlCharStringLiteral Comment() :
{
}
Expand Down
Loading