Skip to content

Commit

Permalink
Rename fromSchema to fromDatabase (apache#31876)
Browse files Browse the repository at this point in the history
* Rename fromSchema to fromDatabase

* Refactor database assert
  • Loading branch information
RaigorJiang authored Jun 26, 2024
1 parent da5fd98 commit 9f0395c
Show file tree
Hide file tree
Showing 52 changed files with 223 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ShowColumnsStatement getSqlStatement() {
@Override
public Collection<SQLSegment> getRemoveSegments() {
Collection<SQLSegment> result = new LinkedList<>();
getSqlStatement().getFromSchema().ifPresent(result::add);
getSqlStatement().getFromDatabase().ifPresent(result::add);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ShowIndexStatement getSqlStatement() {
@Override
public Collection<SQLSegment> getRemoveSegments() {
Collection<SQLSegment> result = new LinkedList<>();
getSqlStatement().getFromSchema().ifPresent(result::add);
getSqlStatement().getFromDatabase().ifPresent(result::add);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ShowTableStatusStatement getSqlStatement() {
@Override
public Collection<SQLSegment> getRemoveSegments() {
Collection<SQLSegment> result = new LinkedList<>();
getSqlStatement().getFromSchema().ifPresent(result::add);
getSqlStatement().getFromDatabase().ifPresent(result::add);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ShowTablesStatement getSqlStatement() {
@Override
public Collection<SQLSegment> getRemoveSegments() {
Collection<SQLSegment> result = new LinkedList<>();
getSqlStatement().getFromSchema().ifPresent(result::add);
getSqlStatement().getFromDatabase().ifPresent(result::add);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;

import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromSchemaSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
Expand All @@ -44,14 +44,14 @@ void assertNewInstance() {
String tableName = "tbl_1";
String databaseName = "sharding_db";
SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(tableName)));
FromSchemaSegment fromSchema = new FromSchemaSegment(0, 0, new DatabaseSegment(0, 0, new IdentifierValue(databaseName)));
FromDatabaseSegment fromDatabase = new FromDatabaseSegment(0, 0, new DatabaseSegment(0, 0, new IdentifierValue(databaseName)));
when(showColumnsStatement.getTable()).thenReturn(table);
when(showColumnsStatement.getFromSchema()).thenReturn(Optional.of(fromSchema));
when(showColumnsStatement.getFromDatabase()).thenReturn(Optional.of(fromDatabase));
ShowColumnsStatementContext actual = new ShowColumnsStatementContext(showColumnsStatement);
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(showColumnsStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Collections.singletonList(tableName)));
assertThat(actual.getRemoveSegments(), is(Collections.singletonList(fromSchema)));
assertThat(actual.getRemoveSegments(), is(Collections.singletonList(fromDatabase)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -649,24 +649,24 @@ transactionAccessMode
: READ (WRITE | ONLY)
;

schemaName
databaseName
: identifier
;

schemaNames
: schemaName (COMMA_ schemaName)*
databaseNames
: databaseName (COMMA_ databaseName)*
;

charsetName
: textOrIdentifier | BINARY | DEFAULT
;

schemaPairs
: schemaPair (COMMA_ schemaPair)*
databasePairs
: databasePair (COMMA_ databasePair)*
;

schemaPair
: LP_ schemaName COMMA_ schemaName RP_
databasePair
: LP_ databaseName COMMA_ databaseName RP_
;

tableName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ grammar DALStatement;
import DMLStatement;

use
: USE schemaName
: USE databaseName
;

help
Expand All @@ -34,8 +34,8 @@ explain
| ANALYZE (FORMAT EQ_ TREE)? (select | delete | update | insert))
;

fromSchema
: (FROM | IN) schemaName
fromDatabase
: (FROM | IN) databaseName
;

fromTable
Expand Down Expand Up @@ -99,11 +99,11 @@ showCollation
;

showColumns
: SHOW EXTENDED? FULL? (COLUMNS | FIELDS) fromTable fromSchema? showFilter?
: SHOW EXTENDED? FULL? (COLUMNS | FIELDS) fromTable fromDatabase? showFilter?
;

showCreateDatabase
: SHOW CREATE (DATABASE | SCHEMA) ifNotExists? schemaName
: SHOW CREATE (DATABASE | SCHEMA) ifNotExists? databaseName
;

showCreateEvent
Expand Down Expand Up @@ -151,7 +151,7 @@ showErrors
;

showEvents
: SHOW EVENTS fromSchema? showFilter?
: SHOW EVENTS fromDatabase? showFilter?
;

showFunctionCode
Expand All @@ -167,15 +167,15 @@ showGrants
;

showIndex
: SHOW EXTENDED? (INDEX | INDEXES | KEYS) fromTable fromSchema? showWhereClause?
: SHOW EXTENDED? (INDEX | INDEXES | KEYS) fromTable fromDatabase? showWhereClause?
;

showMasterStatus
: SHOW MASTER STATUS
;

showOpenTables
: SHOW OPEN TABLES fromSchema? showFilter?
: SHOW OPEN TABLES fromDatabase? showFilter?
;

showPlugins
Expand Down Expand Up @@ -231,15 +231,15 @@ showStatus
;

showTableStatus
: SHOW TABLE STATUS fromSchema? showFilter?
: SHOW TABLE STATUS fromDatabase? showFilter?
;

showTables
: SHOW EXTENDED? FULL? TABLES fromSchema? showFilter?
: SHOW EXTENDED? FULL? TABLES fromDatabase? showFilter?
;

showTriggers
: SHOW TRIGGERS fromSchema? showFilter?
: SHOW TRIGGERS fromDatabase? showFilter?
;

showVariables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ aclType
grantIdentifier
: ASTERISK_ # grantLevelGlobal
| ASTERISK_ DOT_ASTERISK_ # grantLevelGlobal
| schemaName DOT_ASTERISK_ # grantLevelSchemaGlobal
| databaseName DOT_ASTERISK_ # grantLevelDatabaseGlobal
| tableName # grantLevelTable
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ createIndex
;

createDatabase
: CREATE (DATABASE | SCHEMA) ifNotExists? schemaName createDatabaseSpecification_*
: CREATE (DATABASE | SCHEMA) ifNotExists? databaseName createDatabaseSpecification_*
;

alterDatabase
: ALTER (DATABASE | SCHEMA) schemaName? alterDatabaseSpecification_*
: ALTER (DATABASE | SCHEMA) databaseName? alterDatabaseSpecification_*
;

createDatabaseSpecification_
Expand All @@ -263,7 +263,7 @@ alterDatabaseSpecification_
;

dropDatabase
: DROP (DATABASE | SCHEMA) ifExists? schemaName
: DROP (DATABASE | SCHEMA) ifExists? databaseName
;

alterInstance
Expand Down Expand Up @@ -453,7 +453,7 @@ createTrigger
;

dropTrigger
: DROP TRIGGER ifExists? (schemaName DOT_)? triggerName
: DROP TRIGGER ifExists? (databaseName DOT_)? triggerName
;

renameTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ filterDefs
;

filterDef
: REPLICATE_DO_DB EQ_ LP_ schemaNames? RP_
| REPLICATE_IGNORE_DB EQ_ LP_ schemaNames? RP_
: REPLICATE_DO_DB EQ_ LP_ databaseNames? RP_
| REPLICATE_IGNORE_DB EQ_ LP_ databaseNames? RP_
| REPLICATE_DO_TABLE EQ_ LP_ tableList? RP_
| REPLICATE_IGNORE_TABLE EQ_ LP_ tableList? RP_
| REPLICATE_WILD_DO_TABLE EQ_ LP_ wildTables? RP_
| REPLICATE_WILD_IGNORE_TABLE EQ_ LP_ wildTables? RP_
| REPLICATE_REWRITE_DB EQ_ LP_ schemaPairs? RP_
| REPLICATE_REWRITE_DB EQ_ LP_ databasePairs? RP_
;

wildTables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CteClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CurrentUserFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.DataTypeContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.DatabaseNameContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.DeleteContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.DuplicateSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.EngineRefContext;
Expand Down Expand Up @@ -110,7 +111,6 @@
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ReplaceSelectClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ReplaceValuesClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.RowConstructorListContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.SchemaNameContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.SelectContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.SelectSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.SelectWithIntoContext;
Expand Down Expand Up @@ -334,7 +334,7 @@ public final ASTNode visitIdentifier(final IdentifierContext ctx) {
}

@Override
public final ASTNode visitSchemaName(final SchemaNameContext ctx) {
public final ASTNode visitDatabaseName(final DatabaseNameContext ctx) {
return new DatabaseSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
}

Expand Down Expand Up @@ -1719,8 +1719,8 @@ private ShorthandProjectionSegment createShorthandProjection(final QualifiedShor
OwnerSegment owner = new OwnerSegment(identifier.getStart().getStartIndex(), identifier.getStop().getStopIndex(), new IdentifierValue(identifier.getText()));
result.setOwner(owner);
if (shorthand.identifier().size() > 1) {
IdentifierContext schemaIdentifier = shorthand.identifier().get(0);
owner.setOwner(new OwnerSegment(schemaIdentifier.getStart().getStartIndex(), schemaIdentifier.getStop().getStopIndex(), new IdentifierValue(schemaIdentifier.getText())));
IdentifierContext databaseIdentifier = shorthand.identifier().get(0);
owner.setOwner(new OwnerSegment(databaseIdentifier.getStart().getStartIndex(), databaseIdentifier.getStop().getStopIndex(), new IdentifierValue(databaseIdentifier.getText())));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ExplainContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ExplainableStatementContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.FlushContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.FromSchemaContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.FromDatabaseContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.FromTableContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.HelpContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.IndexNameContext;
Expand Down Expand Up @@ -119,7 +119,7 @@
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CacheTableIndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneActionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneInstanceSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromSchemaSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.LoadTableIndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionDefinitionSegment;
Expand Down Expand Up @@ -235,7 +235,7 @@ public ASTNode visitUninstallPlugin(final UninstallPluginContext ctx) {
@Override
public ASTNode visitShowCreateDatabase(final ShowCreateDatabaseContext ctx) {
DorisShowCreateDatabaseStatement result = new DorisShowCreateDatabaseStatement();
result.setDatabaseName(((DatabaseSegment) visit(ctx.schemaName())).getIdentifier().getValue());
result.setDatabaseName(((DatabaseSegment) visit(ctx.databaseName())).getIdentifier().getValue());
return result;
}

Expand Down Expand Up @@ -551,7 +551,7 @@ public ASTNode visitOptimizeTable(final OptimizeTableContext ctx) {
@Override
public ASTNode visitUse(final UseContext ctx) {
DorisUseStatement result = new DorisUseStatement();
result.setSchema(((DatabaseSegment) visit(ctx.schemaName())).getIdentifier().getValue());
result.setDatabase(((DatabaseSegment) visit(ctx.databaseName())).getIdentifier().getValue());
return result;
}

Expand Down Expand Up @@ -630,8 +630,8 @@ public ASTNode visitShowDatabases(final ShowDatabasesContext ctx) {
@Override
public ASTNode visitShowEvents(final ShowEventsContext ctx) {
DorisShowEventsStatement result = new DorisShowEventsStatement();
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.showFilter()) {
result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
Expand All @@ -643,8 +643,8 @@ public ASTNode visitShowEvents(final ShowEventsContext ctx) {
@Override
public ASTNode visitShowTables(final ShowTablesContext ctx) {
DorisShowTablesStatement result = new DorisShowTablesStatement();
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.showFilter()) {
result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
Expand All @@ -657,8 +657,8 @@ public ASTNode visitShowTables(final ShowTablesContext ctx) {
@Override
public ASTNode visitShowTriggers(final ShowTriggersContext ctx) {
DorisShowTriggersStatement result = new DorisShowTriggersStatement();
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.showFilter()) {
result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
Expand All @@ -675,8 +675,8 @@ public ASTNode visitShowWhereClause(final ShowWhereClauseContext ctx) {
@Override
public ASTNode visitShowTableStatus(final ShowTableStatusContext ctx) {
DorisShowTableStatusStatement result = new DorisShowTableStatusStatement();
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.showFilter()) {
result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
Expand All @@ -691,8 +691,8 @@ public ASTNode visitShowColumns(final ShowColumnsContext ctx) {
if (null != ctx.fromTable()) {
result.setTable(((FromTableSegment) visit(ctx.fromTable())).getTable());
}
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.showFilter()) {
result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
Expand All @@ -716,8 +716,8 @@ public ASTNode visitShowFilter(final ShowFilterContext ctx) {
@Override
public ASTNode visitShowIndex(final ShowIndexContext ctx) {
DorisShowIndexStatement result = new DorisShowIndexStatement();
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.fromTable()) {
result.setTable(((FromTableSegment) visitFromTable(ctx.fromTable())).getTable());
Expand Down Expand Up @@ -866,8 +866,8 @@ public ASTNode visitShowProcedureStatus(final ShowProcedureStatusContext ctx) {
@Override
public ASTNode visitShowOpenTables(final ShowOpenTablesContext ctx) {
DorisShowOpenTablesStatement result = new DorisShowOpenTablesStatement();
if (null != ctx.fromSchema()) {
result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
if (null != ctx.fromDatabase()) {
result.setFromDatabase((FromDatabaseSegment) visit(ctx.fromDatabase()));
}
if (null != ctx.showFilter()) {
result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
Expand Down Expand Up @@ -987,8 +987,8 @@ public ASTNode visitSetCharacter(final SetCharacterContext ctx) {
}

@Override
public ASTNode visitFromSchema(final FromSchemaContext ctx) {
return new FromSchemaSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (DatabaseSegment) visit(ctx.schemaName()));
public ASTNode visitFromDatabase(final FromDatabaseContext ctx) {
return new FromDatabaseSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (DatabaseSegment) visit(ctx.databaseName()));
}

@Override
Expand Down
Loading

0 comments on commit 9f0395c

Please sign in to comment.