Skip to content

Commit

Permalink
Refactor DistSQLParserFacade (#29632)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jan 2, 2024
1 parent 28a322b commit 1b8303c
Show file tree
Hide file tree
Showing 20 changed files with 7 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return BroadcastDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "broadcast";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return EncryptDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "encrypt";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return MaskDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "mask";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return ReadwriteSplittingDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "readwrite-splitting";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return ShadowDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "shadow";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
package org.apache.shardingsphere.sharding.distsql.update;

import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
import org.apache.shardingsphere.distsql.parser.engine.spi.DistSQLParserFacade;
import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
Expand Down Expand Up @@ -290,7 +288,7 @@ private Map<String, DataSource> createDataSource() {
private DistSQLStatement getDistSQLStatement(final String sql) {
ShardingDistSQLParserFacade facade = new ShardingDistSQLParserFacade();
ParseASTNode parseASTNode = (ParseASTNode) SQLParserFactory.newInstance(sql, facade.getLexerClass(), facade.getParserClass()).parse();
SQLVisitor visitor = TypedSPILoader.getService(DistSQLParserFacade.class, facade.getType()).getVisitorClass().getDeclaredConstructor().newInstance();
SQLVisitor visitor = facade.getVisitorClass().getDeclaredConstructor().newInstance();
return (DistSQLStatement) visitor.visit(parseASTNode.getRootNode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return ShardingDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "sharding";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return AuthorityDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "authority";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return CDCDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "CDC";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return MigrationDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "migration";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return GlobalClockDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "global_clock";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return SingleDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "single";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return SQLFederationDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "sql_federation";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return SQLParserDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "sql_parser";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return SQLTranslatorDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "sql_translator";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return TrafficDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "traffic";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public Class<? extends SQLParser> getParserClass() {
public Class<? extends SQLVisitor<ASTNode>> getVisitorClass() {
return TransactionDistSQLStatementVisitor.class;
}

@Override
public String getType() {
return "transaction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;

/**
* Featured DistSQL statement parser engine.
* DistSQL parser engine.
*/
public final class FeaturedDistSQLStatementParserEngine {
public final class DistSQLParserEngine {

/**
* Parse SQL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.apache.shardingsphere.distsql.parser.core.utility.UtilityDistSQLStatementParserEngine;
import org.apache.shardingsphere.distsql.parser.core.kernel.KernelDistSQLStatementParserEngine;
import org.apache.shardingsphere.distsql.parser.core.featured.FeaturedDistSQLStatementParserEngine;
import org.apache.shardingsphere.distsql.parser.core.featured.DistSQLParserEngine;
import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;

Expand All @@ -40,7 +40,7 @@ public SQLStatement parse(final String sql) {
return new KernelDistSQLStatementParserEngine().parse(sql);
} catch (final ParseCancellationException | SQLParsingException ignored) {
try {
return new FeaturedDistSQLStatementParserEngine().parse(sql);
return new DistSQLParserEngine().parse(sql);
} catch (final SQLParsingException ignoredToo) {
return new UtilityDistSQLStatementParserEngine().parse(sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.shardingsphere.distsql.parser.engine.spi;

import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
Expand All @@ -28,7 +27,7 @@
* DistSQL parser facade.
*/
@SingletonSPI
public interface DistSQLParserFacade extends TypedSPI {
public interface DistSQLParserFacade {

/**
* Get SQL lexer class type.
Expand All @@ -50,7 +49,4 @@ public interface DistSQLParserFacade extends TypedSPI {
* @return visitor class
*/
Class<? extends SQLVisitor<ASTNode>> getVisitorClass();

@Override
String getType();
}

0 comments on commit 1b8303c

Please sign in to comment.