@@ -776,6 +776,13 @@ SqlShowCreate SqlShowCreate() :
776776 {
777777 return new SqlShowCreateModel(pos, sqlIdentifier);
778778 }
779+ |
780+ <CONNECTION >
781+ { pos = getPos(); }
782+ sqlIdentifier = CompoundIdentifier()
783+ {
784+ return new SqlShowCreateConnection(pos, sqlIdentifier);
785+ }
779786 |
780787 <MATERIALIZED > <TABLE >
781788 { pos = getPos(); }
@@ -787,7 +794,7 @@ SqlShowCreate SqlShowCreate() :
787794}
788795
789796/**
790- * DESCRIBE | DESC FUNCTION [ EXTENDED] [[catalogName.] dataBasesName].functionName sql call.
797+ * ( DESCRIBE | DESC) FUNCTION [ EXTENDED] [[catalogName.] dataBasesName].functionName sql call.
791798 * Here we add Rich in className to match the naming of SqlRichDescribeTable.
792799 */
793800SqlRichDescribeFunction SqlRichDescribeFunction() :
@@ -806,7 +813,7 @@ SqlRichDescribeFunction SqlRichDescribeFunction() :
806813}
807814
808815/**
809- * DESCRIBE | DESC MODEL [ EXTENDED] [[catalogName.] dataBasesName].modelName sql call.
816+ * ( DESCRIBE | DESC) MODEL [ EXTENDED] [[catalogName.] dataBasesName].modelName sql call.
810817 * Here we add Rich in className to match the naming of SqlRichDescribeTable.
811818 */
812819SqlRichDescribeModel SqlRichDescribeModel() :
@@ -825,7 +832,26 @@ SqlRichDescribeModel SqlRichDescribeModel() :
825832}
826833
827834/**
828- * DESCRIBE | DESC [ EXTENDED] [[catalogName.] dataBasesName].tableName sql call.
835+ * (DESCRIBE | DESC) CONNECTION [ EXTENDED] [[catalogName.] dataBasesName].connectionName sql call.
836+ * Here we add Rich in className to match the naming of SqlRichDescribeTable.
837+ */
838+ SqlRichDescribeConnection SqlRichDescribeConnection() :
839+ {
840+ SqlIdentifier connectionName;
841+ SqlParserPos pos;
842+ boolean isExtended = false;
843+ }
844+ {
845+ ( <DESCRIBE > | <DESC > ) <CONNECTION > { pos = getPos();}
846+ [ <EXTENDED > { isExtended = true;} ]
847+ connectionName = CompoundIdentifier()
848+ {
849+ return new SqlRichDescribeConnection(pos, connectionName, isExtended);
850+ }
851+ }
852+
853+ /**
854+ * (DESCRIBE | DESC) [ EXTENDED] [[catalogName.] dataBasesName].tableName sql call.
829855 * Here we add Rich in className to distinguish from calcite's original SqlDescribeTable.
830856 */
831857SqlRichDescribeTable SqlRichDescribeTable() :
@@ -2683,9 +2709,13 @@ SqlCreate SqlCreateExtended(Span s, boolean replace) :
26832709 |
26842710 create = SqlCreateDatabase(s, replace)
26852711 |
2712+ create = SqlCreateModel(s, isTemporary)
2713+ |
2714+ // Lookahead to distinguish <SYSTEM > FUNCTION and <SYSTEM > <CONNECTION >
2715+ LOOKAHEAD(2)
26862716 create = SqlCreateFunction(s, replace, isTemporary)
26872717 |
2688- create = SqlCreateModel (s, isTemporary)
2718+ create = SqlCreateConnection (s, isTemporary)
26892719 )
26902720 {
26912721 return create;
@@ -2712,9 +2742,13 @@ SqlDrop SqlDropExtended(Span s, boolean replace) :
27122742 |
27132743 drop = SqlDropDatabase(s, replace)
27142744 |
2745+ drop = SqlDropModel(s, isTemporary)
2746+ |
2747+ // Lookahead to distinguish <SYSTEM > FUNCTION and <SYSTEM > <CONNECTION >
2748+ LOOKAHEAD(2)
27152749 drop = SqlDropFunction(s, replace, isTemporary)
27162750 |
2717- drop = SqlDropModel (s, isTemporary)
2751+ drop = SqlDropConnection (s, isTemporary)
27182752 )
27192753 {
27202754 return drop;
@@ -3345,7 +3379,7 @@ SqlTruncateTable SqlTruncateTable() :
33453379}
33463380
33473381/**
3348- * SHOW MODELS [FROM [catalog.] database] [[NOT] LIKE pattern]; sql call.
3382+ * SHOW MODELS [FROM [catalog.] database] [[NOT] LIKE pattern];
33493383*/
33503384SqlShowModels SqlShowModels() :
33513385{
@@ -3381,6 +3415,43 @@ SqlShowModels SqlShowModels() :
33813415 }
33823416}
33833417
3418+ /**
3419+ * SHOW CONNECTIONS [LIKE 'pattern'] [FROM catalog_name.db_name];
3420+ */
3421+ SqlShowConnections SqlShowConnections() :
3422+ {
3423+ SqlIdentifier databaseName = null;
3424+ SqlCharStringLiteral likeLiteral = null;
3425+ String prep = null;
3426+ boolean notLike = false;
3427+ SqlParserPos pos;
3428+ }
3429+ {
3430+ <SHOW > <CONNECTIONS >
3431+ { pos = getPos(); }
3432+ [
3433+ ( <FROM > { prep = "FROM"; } | <IN > { prep = "IN"; } )
3434+ { pos = getPos(); }
3435+ databaseName = CompoundIdentifier()
3436+ ]
3437+ [
3438+ [
3439+ <NOT >
3440+ {
3441+ notLike = true;
3442+ }
3443+ ]
3444+ <LIKE > <QUOTED _STRING >
3445+ {
3446+ String likeCondition = SqlParserUtil.parseString(token.image);
3447+ likeLiteral = SqlLiteral.createCharString(likeCondition, getPos());
3448+ }
3449+ ]
3450+ {
3451+ return new SqlShowConnections(pos, prep, databaseName, notLike, likeLiteral);
3452+ }
3453+ }
3454+
33843455/**
33853456* ALTER MODEL [IF EXISTS] modelName SET (property_key = property_val, ...)
33863457* ALTER MODEL [IF EXISTS] modelName RENAME TO newModelName
@@ -3433,6 +3504,59 @@ SqlAlterModel SqlAlterModel() :
34333504 )
34343505}
34353506
3507+ /**
3508+ * ALTER CONNECTION [IF EXISTS] connectionName SET (property_key = property_val, ...)
3509+ * ALTER CONNECTION [IF EXISTS] connectionName RENAME TO newConnectionName
3510+ * ALTER CONNECTION [IF EXISTS] connectionName RESET (property_key, ...)
3511+ * Alter temporary or system connection is not supported.
3512+ */
3513+ SqlAlterConnection SqlAlterConnection() :
3514+ {
3515+ SqlParserPos startPos;
3516+ boolean ifExists = false;
3517+ SqlIdentifier connectionIdentifier;
3518+ SqlIdentifier newConnectionIdentifier = null;
3519+ SqlNodeList propertyList = SqlNodeList.EMPTY;
3520+ SqlNodeList propertyKeyList = SqlNodeList.EMPTY;
3521+ }
3522+ {
3523+ <ALTER > <CONNECTION > { startPos = getPos(); }
3524+ ifExists = IfExistsOpt()
3525+ connectionIdentifier = CompoundIdentifier()
3526+ (
3527+ LOOKAHEAD(2)
3528+ <RENAME > <TO >
3529+ newConnectionIdentifier = CompoundIdentifier()
3530+ {
3531+ return new SqlAlterConnectionRename(
3532+ startPos.plus(getPos()),
3533+ connectionIdentifier,
3534+ newConnectionIdentifier,
3535+ ifExists);
3536+ }
3537+ |
3538+ <SET >
3539+ propertyList = Properties()
3540+ {
3541+ return new SqlAlterConnectionSet(
3542+ startPos.plus(getPos()),
3543+ connectionIdentifier,
3544+ ifExists,
3545+ propertyList);
3546+ }
3547+ |
3548+ <RESET >
3549+ propertyKeyList = PropertyKeys()
3550+ {
3551+ return new SqlAlterConnectionReset(
3552+ startPos.plus(getPos()),
3553+ connectionIdentifier,
3554+ ifExists,
3555+ propertyKeyList);
3556+ }
3557+ )
3558+ }
3559+
34363560/**
34373561* DROP MODEL [IF EXIST] modelName
34383562*/
@@ -3453,6 +3577,38 @@ SqlDrop SqlDropModel(Span s, boolean isTemporary) :
34533577 }
34543578}
34553579
3580+ /**
3581+ * DROP [TEMPORARY] [SYSTEM] CONNECTION [IF EXIST] connectionName
3582+ */
3583+ SqlDrop SqlDropConnection(Span s, boolean isTemporary) :
3584+ {
3585+ SqlIdentifier connectionIdentifier = null;
3586+ boolean ifExists = false;
3587+ boolean isSystemConnection = false;
3588+ }
3589+ {
3590+ [
3591+ <SYSTEM >
3592+ {
3593+ if (!isTemporary){
3594+ throw SqlUtil.newContextException(getPos(),
3595+ ParserResource.RESOURCE.dropSystemConnectionOnlySupportTemporary());
3596+ }
3597+ isSystemConnection = true;
3598+ }
3599+ ]
3600+
3601+ <CONNECTION >
3602+
3603+ ifExists = IfExistsOpt()
3604+
3605+ connectionIdentifier = CompoundIdentifier()
3606+
3607+ {
3608+ return new SqlDropConnection(s.pos(), connectionIdentifier, ifExists, isTemporary, isSystemConnection);
3609+ }
3610+ }
3611+
34563612/**
34573613* CREATE MODEL [IF NOT EXIST] modelName
34583614* [INPUT(col1 type1, col2 type2, ...)]
@@ -3539,6 +3695,54 @@ SqlCreate SqlCreateModel(Span s, boolean isTemporary) :
35393695 }
35403696}
35413697
3698+ /**
3699+ * CREATE [TEMPORARY] [SYSTEM] CONNECTION [IF NOT EXISTS] [catalog_name.][db_name.]connection_name
3700+ * [COMMENT connection_comment]
3701+ * WITH (property_key = property_val, ...)
3702+ */
3703+ SqlCreate SqlCreateConnection(Span s, boolean isTemporary) :
3704+ {
3705+ final SqlParserPos startPos = s.pos();
3706+ boolean ifNotExists = false;
3707+ boolean isSystem = false;
3708+ SqlIdentifier connectionIdentifier;
3709+ SqlCharStringLiteral comment = null;
3710+ SqlNodeList propertyList = SqlNodeList.EMPTY;
3711+ }
3712+ {
3713+ [
3714+ <SYSTEM >
3715+ {
3716+ if (!isTemporary){
3717+ throw SqlUtil.newContextException(getPos(),
3718+ ParserResource.RESOURCE.createSystemConnectionOnlySupportTemporary());
3719+ }
3720+ isSystem = true;
3721+ }
3722+ ]
3723+ <CONNECTION >
3724+
3725+ ifNotExists = IfNotExistsOpt()
3726+
3727+ connectionIdentifier = CompoundIdentifier()
3728+ [ <COMMENT > <QUOTED _STRING >
3729+ {
3730+ comment = Comment();
3731+ }
3732+ ]
3733+ <WITH >
3734+ propertyList = Properties()
3735+ {
3736+ return new SqlCreateConnection(startPos.plus(getPos()),
3737+ connectionIdentifier,
3738+ comment,
3739+ propertyList,
3740+ isTemporary,
3741+ isSystem,
3742+ ifNotExists);
3743+ }
3744+ }
3745+
35423746SqlCharStringLiteral Comment() :
35433747{
35443748}
0 commit comments