Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format OracleStatementParser import class #28454

Merged
merged 1 commit into from
Sep 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementBaseVisitor;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AggregationFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AnalyticFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BitExprContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BitValueLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BooleanLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BooleanPrimaryContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CastFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CaseExpressionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CaseWhenContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CharFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnNamesContext;
Expand All @@ -45,6 +46,7 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DatetimeExprContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExtractFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprListContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FeatureFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FirstOrLastValueFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FormatFunctionContext;
Expand All @@ -69,13 +71,16 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.PrivateExprOfDbContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.RegularFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SchemaNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SetFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SimpleExprContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SpecialFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.StringLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SynonymNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableNamesContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ToDateFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TrimFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TranslateFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TypeNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.UnreservedWordContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ViewNameContext;
Expand Down Expand Up @@ -604,11 +609,11 @@ private ASTNode visitRemainSimpleExpr(final SimpleExprContext ctx, final int sta
}

@Override
public ASTNode visitCaseExpression(final OracleStatementParser.CaseExpressionContext ctx) {
public ASTNode visitCaseExpression(final CaseExpressionContext ctx) {
ExpressionSegment caseExpr = null == ctx.simpleExpr() ? null : (ExpressionSegment) visit(ctx.simpleExpr());
Collection<ExpressionSegment> whenExprs = new ArrayList<>(ctx.caseWhen().size());
Collection<ExpressionSegment> thenExprs = new ArrayList<>(ctx.caseWhen().size());
for (OracleStatementParser.CaseWhenContext each : ctx.caseWhen()) {
for (CaseWhenContext each : ctx.caseWhen()) {
whenExprs.add((ExpressionSegment) visit(each.expr(0)));
thenExprs.add((ExpressionSegment) visit(each.expr(1)));
}
Expand Down Expand Up @@ -906,7 +911,7 @@ public ASTNode visitXmlIsSchemaValidFunction(final XmlIsSchemaValidFunctionConte
return result;
}

private Collection<ExpressionSegment> getExpressions(final OracleStatementParser.ExprListContext exprList) {
private Collection<ExpressionSegment> getExpressions(final ExprListContext exprList) {
if (null == exprList) {
return Collections.emptyList();
}
Expand Down Expand Up @@ -980,12 +985,12 @@ public ASTNode visitCursorFunction(final CursorFunctionContext ctx) {
}

@Override
public ASTNode visitToDateFunction(final OracleStatementParser.ToDateFunctionContext ctx) {
public ASTNode visitToDateFunction(final ToDateFunctionContext ctx) {
return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.TO_DATE().getText(), getOriginalText(ctx));
}

@Override
public final ASTNode visitTranslateFunction(final OracleStatementParser.TranslateFunctionContext ctx) {
public final ASTNode visitTranslateFunction(final TranslateFunctionContext ctx) {
FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.TRANSLATE().getText(), getOriginalText(ctx));
result.getParameters().add((ExpressionSegment) visit(ctx.expr()));
TerminalNode charSet = null == ctx.NCHAR_CS() ? ctx.CHAR_CS() : ctx.NCHAR_CS();
Expand All @@ -994,7 +999,7 @@ public final ASTNode visitTranslateFunction(final OracleStatementParser.Translat
}

@Override
public final ASTNode visitSetFunction(final OracleStatementParser.SetFunctionContext ctx) {
public final ASTNode visitSetFunction(final SetFunctionContext ctx) {
FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.SET().getText(), getOriginalText(ctx));
result.getParameters().add((ExpressionSegment) visit(ctx.expr()));
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AddColumnSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AddConstraintSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterAnalyticViewContext;
Expand Down Expand Up @@ -95,7 +94,9 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateSynonymContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTableContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTablespaceContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTypeContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateViewContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeDefinitionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DisassociateStatisticsContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropClusterContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropColumnClauseContext;
Expand Down Expand Up @@ -145,7 +146,11 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyColPropertiesContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyColumnSpecificationContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyConstraintClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.NestedTableTypeSpecContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.NoAuditContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ObjectBaseTypeDefContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ObjectSubTypeDefContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ObjectTypeDefContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OperateColumnClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OutOfLineConstraintContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OutOfLineRefConstraintContext;
Expand All @@ -157,6 +162,7 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TruncateTableContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TypeNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.VarrayTypeSpecContext;
import org.apache.shardingsphere.sql.parser.oracle.visitor.statement.OracleStatementVisitor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.CreateDefinitionSegment;
Expand Down Expand Up @@ -335,12 +341,12 @@ public ASTNode visitCreateTable(final CreateTableContext ctx) {
}

@Override
public ASTNode visitCreateType(final OracleStatementParser.CreateTypeContext ctx) {
public ASTNode visitCreateType(final CreateTypeContext ctx) {
boolean isReplace = null != ctx.REPLACE();
boolean isEditionable = null == ctx.NONEDITIONABLE();
TypeSegment typeSegment = (TypeSegment) visit(ctx.plsqlTypeSource().typeName());
if (null != ctx.plsqlTypeSource().objectSubTypeDef()) {
OracleStatementParser.ObjectSubTypeDefContext objectSubTypeDefContext = ctx.plsqlTypeSource().objectSubTypeDef();
ObjectSubTypeDefContext objectSubTypeDefContext = ctx.plsqlTypeSource().objectSubTypeDef();
return new OracleCreateSubTypeStatement(isReplace, isEditionable,
null == objectSubTypeDefContext.finalClause() || null == objectSubTypeDefContext.finalClause().NOT(),
null == objectSubTypeDefContext.instantiableClause() || null == objectSubTypeDefContext.instantiableClause().NOT(),
Expand All @@ -351,23 +357,23 @@ public ASTNode visitCreateType(final OracleStatementParser.CreateTypeContext ctx
}
}

private ASTNode visitCreateTypeObjectBaseTypeDef(final OracleStatementParser.ObjectBaseTypeDefContext ctx, final boolean isReplace, final boolean isEditionable, final TypeSegment typeSegment) {
private ASTNode visitCreateTypeObjectBaseTypeDef(final ObjectBaseTypeDefContext ctx, final boolean isReplace, final boolean isEditionable, final TypeSegment typeSegment) {
if (null != ctx.objectTypeDef()) {
OracleStatementParser.ObjectTypeDefContext objectTypeDefContext = ctx.objectTypeDef();
ObjectTypeDefContext objectTypeDefContext = ctx.objectTypeDef();
return new OracleCreateObjectTypeStatement(isReplace, isEditionable, null == objectTypeDefContext.finalClause() || null == objectTypeDefContext.finalClause().NOT(),
null == objectTypeDefContext.instantiableClause() || null == objectTypeDefContext.instantiableClause().NOT(),
null == objectTypeDefContext.persistableClause() || null == objectTypeDefContext.persistableClause().NOT(),
typeSegment, objectTypeDefContext.dataTypeDefinition().stream().map(definition -> (TypeDefinitionSegment) visit(definition)).collect(Collectors.toList()));
} else if (null != ctx.varrayTypeSpec()) {
OracleStatementParser.VarrayTypeSpecContext varrayTypeSpecContext = ctx.varrayTypeSpec();
VarrayTypeSpecContext varrayTypeSpecContext = ctx.varrayTypeSpec();
return new OracleCreateVarrayTypeStatement(isReplace, isEditionable,
null == varrayTypeSpecContext.INTEGER_() ? -1 : Integer.parseInt(varrayTypeSpecContext.INTEGER_().getText()),
null != varrayTypeSpecContext.typeSpec().NULL(),
null == varrayTypeSpecContext.typeSpec().persistableClause() || null == varrayTypeSpecContext.typeSpec().persistableClause().NOT(),
typeSegment,
(DataTypeSegment) visit(varrayTypeSpecContext.typeSpec().dataType()));
} else {
OracleStatementParser.NestedTableTypeSpecContext nestedTableTypeSpecContext = ctx.nestedTableTypeSpec();
NestedTableTypeSpecContext nestedTableTypeSpecContext = ctx.nestedTableTypeSpec();
return new OracleCreateNestedTableTypeStatement(isReplace, isEditionable,
null != nestedTableTypeSpecContext.typeSpec().NULL(),
null == nestedTableTypeSpecContext.typeSpec().persistableClause() || null == nestedTableTypeSpecContext.typeSpec().persistableClause().NOT(),
Expand All @@ -377,7 +383,7 @@ private ASTNode visitCreateTypeObjectBaseTypeDef(final OracleStatementParser.Obj
}

@Override
public ASTNode visitDataTypeDefinition(final OracleStatementParser.DataTypeDefinitionContext ctx) {
public ASTNode visitDataTypeDefinition(final DataTypeDefinitionContext ctx) {
return new TypeDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.name().getText(), (DataTypeSegment) visit(ctx.dataType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.antlr.v4.runtime.misc.Interval;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatementVisitor;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AliasContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AssignmentValueContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AssignmentValuesContext;
Expand Down Expand Up @@ -64,6 +63,9 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeAssignmentContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeAssignmentValueContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeColumnValueContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeInsertClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeInsertColumnContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeSetAssignmentsClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeUpdateClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModelClauseContext;
Expand Down Expand Up @@ -1225,7 +1227,7 @@ public ASTNode visitMerge(final MergeContext ctx) {

@SuppressWarnings("unchecked")
@Override
public ASTNode visitMergeInsertClause(final OracleStatementParser.MergeInsertClauseContext ctx) {
public ASTNode visitMergeInsertClause(final MergeInsertClauseContext ctx) {
OracleInsertStatement result = new OracleInsertStatement();
if (null != ctx.mergeInsertColumn()) {
result.setInsertColumns((InsertColumnsSegment) visit(ctx.mergeInsertColumn()));
Expand All @@ -1240,7 +1242,7 @@ public ASTNode visitMergeInsertClause(final OracleStatementParser.MergeInsertCla
}

@Override
public ASTNode visitMergeInsertColumn(final OracleStatementParser.MergeInsertColumnContext ctx) {
public ASTNode visitMergeInsertColumn(final MergeInsertColumnContext ctx) {
Collection<ColumnSegment> columnSegments = new ArrayList<>(ctx.columnName().size());
for (ColumnNameContext each : ctx.columnName()) {
if (null != each.name()) {
Expand All @@ -1251,7 +1253,7 @@ public ASTNode visitMergeInsertColumn(final OracleStatementParser.MergeInsertCol
}

@Override
public ASTNode visitMergeColumnValue(final OracleStatementParser.MergeColumnValueContext ctx) {
public ASTNode visitMergeColumnValue(final MergeColumnValueContext ctx) {
CollectionValue<InsertValuesSegment> result = new CollectionValue<>();
List<ExpressionSegment> segments = new LinkedList<>();
for (ExprContext each : ctx.expr()) {
Expand Down