This is an automated email from the ASF dual-hosted git repository. imaxon pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 7f7af27cfd08d75345d33c5e1c8b40ed5380a4ca Author: Shahrzad Shirazi <[email protected]> AuthorDate: Tue Feb 17 10:58:06 2026 -0800 [ASTERIXDB-3706][COMP] Support IF NOT EXISTS Before and After identifier in DDL Statements - user model changes: yes - storage format changes: no - interface changes: no Details: This change will support IF NOT EXISTS both before and after the identifier. Ext-ref: MB-70013 Change-Id: Ib731eb88db4dfbd9c312cbcb4700029821a85717 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20905 Reviewed-by: Shahrzad Shirazi <[email protected]> Tested-by: Jenkins <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> --- .../src/test/resources/runtimets/sqlpp_queries.xml | 2 +- .../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj | 245 ++++++++++++++++++--- 2 files changed, 211 insertions(+), 36 deletions(-) diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml index bc1834fefe..9db0281b6d 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -4333,7 +4333,7 @@ <test-case FilePath="ddl/create-index"> <compilation-unit name="create-index-4"> <output-dir compare="Text">create-index-4</output-dir> - <expected-error>Syntax error: In line 53 >>create primary index if not exists sec_primary_idx1 if not exists on LineItem;<< Encountered <IDENTIFIER> "sec_primary_idx1" at column 37.</expected-error> + <expected-error>Syntax error: In line 53 >>create primary index if not exists sec_primary_idx1 if not exists on LineItem;<< Encountered "if" at column 55.</expected-error> </compilation-unit> </test-case> <test-case FilePath="ddl/create-index"> diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj index e04afb68ea..23105fde09 100644 --- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj +++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj @@ -1157,7 +1157,13 @@ TypeDecl TypeSpecification(Token startStmtToken) throws ParseException: TypeExpression typeExpr = null; } { - nameComponents = TypeName() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() + nameComponents = TypeName() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <AS> typeExpr = RecordTypeDef() { boolean dgen = false; @@ -1200,7 +1206,12 @@ NodegroupDecl NodegroupSpecification(Token startStmtToken) throws ParseException List<Identifier> ncNames = new ArrayList<Identifier>(); } { - name = Identifier() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() name = Identifier() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <ON> tmp = Identifier() { ncNames.add(new Identifier(tmp)); @@ -1253,8 +1264,14 @@ CatalogCreateStatement CatalogSpecification(Token startStmtToken) throws ParseEx { // this identifier is the soft keyword CATALOG, consume it then continue <IDENTIFIER> - catalogName = Identifier() ifNotExists = IfNotExists() + catalogName = Identifier() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } + <TYPE> catalogType = Identifier() (LOOKAHEAD({laIdentifier(SOURCE)}) <IDENTIFIER> catalogSource = Identifier())? <WITH> withRecord = RecordConstructor() @@ -1308,6 +1325,7 @@ DatasetDecl DatasetSpecification(Token startStmtToken) throws ParseException: Query query = null; } { + ifNotExists = IfNotExists() nameComponents = QualifiedName() (typeExpr = DatasetTypeSpecification(RecordTypeDefinition.RecordKind.OPEN))? ( @@ -1322,7 +1340,11 @@ DatasetDecl DatasetSpecification(Token startStmtToken) throws ParseException: } metaTypeExpr = DatasetTypeSpecification(RecordTypeDefinition.RecordKind.OPEN) )? - ifNotExists = IfNotExists() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } (LOOKAHEAD(3) primaryKeyFieldsWithTypes = PrimaryKeyWithType() | primaryKeyFields = PrimaryKey()) (<AUTOGENERATED> { autogenerated = true; } )? @@ -1381,9 +1403,14 @@ DatasetDecl ExternalDatasetSpecification(Token startStmtToken) throws ParseExcep RecordConstructor withRecord = null; } { + ifNotExists = IfNotExists() nameComponents = QualifiedName() typeExpr = DatasetTypeSpecification(RecordTypeDefinition.RecordKind.OPEN) - ifNotExists = IfNotExists() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <USING> adapterName = AdapterName() properties = Configuration() ( <HINTS> hints = Properties() )? ( <WITH> withRecord = RecordConstructor() )? @@ -1504,7 +1531,13 @@ CreateIndexStatement IndexSpecification(Token startStmtToken) throws ParseExcept } { ( - indexName = Identifier() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() + indexName = Identifier() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <ON> nameComponents = QualifiedName() <LEFTPAREN> { startElementToken = token; } indexedElement = IndexedElement(startElementToken) { @@ -1674,7 +1707,12 @@ CreateIndexStatement PrimaryIndexSpecification(Token startStmtToken) throws Pars boolean ifNotExists = false; } { - (indexName = Identifier())? ifNotExists = IfNotExists() + ifNotExists = IfNotExists() (indexName = Identifier())? + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)? { if (indexName == null) { @@ -1757,7 +1795,12 @@ CreateDatabaseStatement DatabaseSpecification(Token startStmtToken) throws Parse boolean ifNotExists = false; } { - dbName = Identifier() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() + dbName = Identifier() + { if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } { CreateDatabaseStatement stmt = new CreateDatabaseStatement(new Identifier(dbName), ifNotExists); return addSourceLocation(stmt, startStmtToken); @@ -1781,7 +1824,13 @@ CreateDataverseStatement DataverseSpecification(Token startStmtToken) throws Par boolean ifNotExists = false; } { - ns = Namespace() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() + ns = Namespace() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } { CreateDataverseStatement stmt = new CreateDataverseStatement(ns, null, ifNotExists); return addSourceLocation(stmt, startStmtToken); @@ -1807,8 +1856,13 @@ CreateAdapterStatement AdapterSpecification(Token startStmtToken) throws ParseEx boolean ifNotExists = false; } { - adapterName = QualifiedName() ifNotExists = IfNotExists() + adapterName = QualifiedName() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <AS> externalIdentifier = FunctionExternalIdentifier() <AT> libraryName = QualifiedName() { @@ -1848,11 +1902,16 @@ CreateViewStatement ViewSpecification(Token startStmtToken, boolean orReplace) t Namespace currentNamespace = defaultNamespace; } { + ifNotExists = IfNotExists() nameComponents = QualifiedName() ( ( typeExpr = DatasetTypeSpecification(RecordTypeDefinition.RecordKind.CLOSED) - ifNotExists = IfNotExists() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } viewConfigDefaultNull = CastDefaultNull() { viewConfig = viewConfigDefaultNull.first; @@ -1874,9 +1933,14 @@ CreateViewStatement ViewSpecification(Token startStmtToken, boolean orReplace) t foreignKeyFields.first, refNameComponents.first, refNameComponents.second)); } )* - ) + ) | - ( ifNotExists = IfNotExists() ) + ( { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } + ) ) { if (orReplace && ifNotExists) { @@ -1986,6 +2050,7 @@ CreateFunctionStatement FunctionSpecification(Token startStmtToken, boolean orRe Namespace currentNamespace = defaultNamespace; } { + ifNotExists = IfNotExists() fctName = FunctionName() { defaultDataverse = fctName.dataverse; @@ -1998,7 +2063,11 @@ CreateFunctionStatement FunctionSpecification(Token startStmtToken, boolean orRe params = paramsWithArity.second; signature = new FunctionSignature(fctName.database, fctName.dataverse, fctName.function, arity); } - ifNotExists = IfNotExists() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } { if (orReplace && ifNotExists) { throw new SqlppParseException(getSourceLocation(token), "Unexpected IF NOT EXISTS"); @@ -2169,7 +2238,11 @@ CreateFeedStatement FeedSpecification(Token startStmtToken) throws ParseExceptio RecordConstructor withRecord = null; } { - nameComponents = QualifiedName() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() nameComponents = QualifiedName() + { if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <WITH> withRecord = RecordConstructor() { try { @@ -2203,7 +2276,12 @@ CreateFeedPolicyStatement FeedPolicySpecification(Token startStmtToken) throws P CreateFeedPolicyStatement stmt = null; } { - policyName = Identifier() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() policyName = Identifier() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <FROM> (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())? { @@ -2245,7 +2323,12 @@ CreateFullTextFilterStatement CreateFullTextFilterSpec(Token startStmtToken) thr } { ( - nameComponents = QualifiedName() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() nameComponents = QualifiedName() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <AS> expr = RecordConstructor() ) @@ -2268,7 +2351,12 @@ CreateFullTextConfigStatement CreateFullTextConfigSpec(Token startStmtToken) thr } { ( - nameComponents = QualifiedName() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() nameComponents = QualifiedName() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <AS> expr = RecordConstructor() ) @@ -2300,7 +2388,12 @@ CreateSynonymStatement SynonymSpecification(Token startStmtToken) throws ParseEx boolean ifNotExists = false; } { - nameComponents = QualifiedName() ifNotExists = IfNotExists() + ifNotExists = IfNotExists() nameComponents = QualifiedName() + { + if (ifNotExists == false) { + ifNotExists = IfNotExists(); + } + } <FOR> objectNameComponents = QualifiedName() { CreateSynonymStatement stmt = new CreateSynonymStatement(nameComponents.first, nameComponents.second.getValue(), @@ -2495,7 +2588,12 @@ TruncateDatasetStatement TruncateDatasetSpecification(Token startStmtToken) thro boolean ifExists = false; } { - pairId = QualifiedName() ifExists = IfExists() + ifExists = IfExists() pairId = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { TruncateDatasetStatement stmt = new TruncateDatasetStatement(pairId.first, pairId.second.getValue(), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2547,7 +2645,12 @@ DropDatasetStatement DropDatasetSpecification(Token startStmtToken) throws Parse boolean ifExists = false; } { - pairId = QualifiedName() ifExists = IfExists() + ifExists = IfExists() pairId = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { DropDatasetStatement stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2571,7 +2674,12 @@ ViewDropStatement DropViewSpecification(Token startStmtToken) throws ParseExcept boolean ifExists = false; } { - pairId = QualifiedName() ifExists = IfExists() + ifExists = IfExists() pairId = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { ViewDropStatement stmt = new ViewDropStatement(pairId.first, pairId.second, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2595,7 +2703,13 @@ IndexDropStatement DropIndexSpecification(Token startStmtToken) throws ParseExce boolean ifExists = false; } { - tripleId = DoubleQualifiedName() ifExists = IfExists() + ifExists = IfExists() tripleId = DoubleQualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } + { IndexDropStatement stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2624,7 +2738,12 @@ FullTextFilterDropStatement DropFullTextFilterSpec(Token startStmtToken) throws boolean ifExists = false; } { - nameComponents = QualifiedName() ifExists = IfExists() + ifExists = IfExists() nameComponents = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { stmt = new FullTextFilterDropStatement(nameComponents.first, nameComponents.second.getValue(), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2638,7 +2757,12 @@ FullTextConfigDropStatement DropFullTextConfigSpec(Token startStmtToken) throws boolean ifExists = false; } { - nameComponents = QualifiedName() ifExists = IfExists() + ifExists = IfExists() nameComponents = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { stmt = new FullTextConfigDropStatement(nameComponents.first, nameComponents.second.getValue(), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2663,7 +2787,13 @@ NodeGroupDropStatement DropNodeGroupSpecification(Token startStmtToken) throws P boolean ifExists = false; } { - id = Identifier() ifExists = IfExists() + ifExists = IfExists() id = Identifier() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } + { NodeGroupDropStatement stmt = new NodeGroupDropStatement(new Identifier(id), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2687,7 +2817,12 @@ TypeDropStatement DropTypeSpecification(Token startStmtToken) throws ParseExcept boolean ifExists = false; } { - pairId = TypeName() ifExists = IfExists() + ifExists = IfExists() pairId = TypeName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { TypeDropStatement stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2711,7 +2846,12 @@ DatabaseDropStatement DropDatabaseSpecification(Token startStmtToken) throws Par boolean ifExists = false; } { - dbName = Identifier() ifExists = IfExists() + ifExists = IfExists() dbName = Identifier() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { DatabaseDropStatement stmt = new DatabaseDropStatement(new Identifier(dbName), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2735,7 +2875,12 @@ DataverseDropStatement DropDataverseSpecification(Token startStmtToken) throws P boolean ifExists = false; } { - ns = Namespace() ifExists = IfExists() + ifExists = IfExists() ns = Namespace() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { DataverseDropStatement stmt = new DataverseDropStatement(ns, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2759,7 +2904,12 @@ AdapterDropStatement DropAdapterSpecification(Token startStmtToken) throws Parse boolean ifExists = false; } { - adapterName = QualifiedName() ifExists = IfExists() + ifExists = IfExists() adapterName = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { AdapterDropStatement stmt = new AdapterDropStatement(adapterName.first, adapterName.second.getValue(), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2783,7 +2933,12 @@ FunctionDropStatement DropFunctionSpecification(Token startStmtToken) throws Par boolean ifExists = false; } { - funcSig = FunctionSignature() ifExists = IfExists() + ifExists = IfExists() funcSig = FunctionSignature() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { FunctionDropStatement stmt = new FunctionDropStatement(funcSig, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2807,7 +2962,12 @@ FeedDropStatement DropFeedSpecification(Token startStmtToken) throws ParseExcept boolean ifExists = false; } { - pairId = QualifiedName() ifExists = IfExists() + ifExists = IfExists() pairId = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { FeedDropStatement stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2831,7 +2991,12 @@ FeedPolicyDropStatement DropFeedPolicySpecification(Token startStmtToken) throws boolean ifExists = false; } { - pairId = QualifiedName() ifExists = IfExists() + ifExists = IfExists() pairId = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { FeedPolicyDropStatement stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2855,7 +3020,12 @@ SynonymDropStatement DropSynonymSpecification(Token startStmtToken) throws Parse boolean ifExists = false; } { - pairId = QualifiedName() ifExists = IfExists() + ifExists = IfExists() pairId = QualifiedName() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } { SynonymDropStatement stmt = new SynonymDropStatement(pairId.first, pairId.second.getValue(), ifExists); return addSourceLocation(stmt, startStmtToken); @@ -2882,8 +3052,13 @@ CatalogDropStatement DropCatalogSpecification(Token startStmtToken) throws Parse boolean isCascade = false; } { - catalogName = Identifier() ifExists = IfExists() + catalogName = Identifier() + { + if (ifExists == false) { + ifExists = IfExists(); + } + } (LOOKAHEAD({laIdentifier(CASCADE)}) <IDENTIFIER> { isCascade = true; })? { CatalogDropStatement stmt = new CatalogDropStatement(catalogName, ifExists, isCascade);
