From 77dd48cfc349c0b6ad40d13734562430d9e02fa7 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 19 Oct 2023 17:22:31 +0800 Subject: [PATCH] Remove useless SQLSegmentConverter and refactor SQLNodeConverterEngine logic --- .../converter/SQLNodeConverterEngine.java | 57 +++++++++++++----- .../segment/SQLSegmentConverter.java | 40 ------------- .../expression/ExpressionConverter.java | 58 +++++++++++-------- .../impl/BetweenExpressionConverter.java | 22 ++++--- .../BinaryOperationExpressionConverter.java | 23 +++++--- .../impl/CaseWhenExpressionConverter.java | 31 ++++++---- .../impl/CollateExpressionConverter.java | 19 ++++-- .../expression/impl/ColumnConverter.java | 17 ++++-- .../ExistsSubqueryExpressionConverter.java | 15 +++-- .../impl/ExtractArgExpressionConverter.java | 15 +++-- .../expression/impl/FunctionConverter.java | 24 +++++--- .../impl/InExpressionConverter.java | 20 ++++--- .../impl/ListExpressionConverter.java | 19 ++++-- .../impl/LiteralExpressionConverter.java | 15 +++-- .../impl/MatchExpressionConverter.java | 19 ++++-- .../impl/NotExpressionConverter.java | 17 ++++-- .../ParameterMarkerExpressionConverter.java | 15 +++-- .../impl/RowExpressionConverter.java | 18 ++++-- .../impl/SubqueryExpressionConverter.java | 17 ++++-- .../impl/TrimFunctionConverter.java | 18 ++++-- .../impl/TypeCastExpressionConverter.java | 17 ++++-- .../UnaryOperationExpressionConverter.java | 21 ++++--- .../impl/VariableSegmentConverter.java | 15 +++-- .../impl/WindowFunctionConverter.java | 18 ++++-- .../segment/from/TableConverter.java | 24 +++++--- .../from/impl/DeleteMultiTableConverter.java | 17 ++++-- .../segment/from/impl/JoinTableConverter.java | 28 +++++---- .../from/impl/SimpleTableConverter.java | 17 ++++-- .../from/impl/SubqueryTableConverter.java | 17 ++++-- .../segment/groupby/GroupByConverter.java | 15 +++-- .../segment/groupby/HavingConverter.java | 17 ++++-- .../limit/PaginationValueSQLConverter.java | 21 ++++--- .../segment/orderby/OrderByConverter.java | 15 +++-- .../item/ColumnOrderByItemConverter.java | 17 ++++-- .../item/ExpressionOrderByItemConverter.java | 17 ++++-- .../item/IndexOrderByItemConverter.java | 15 +++-- .../item/OrderByItemConverterUtils.java | 6 +- .../segment/projection/DistinctConverter.java | 15 +++-- .../projection/ProjectionsConverter.java | 27 +++++---- .../impl/AggregationProjectionConverter.java | 22 ++++--- .../impl/ColumnProjectionConverter.java | 19 ++++-- .../projection/impl/DataTypeConverter.java | 17 ++++-- .../impl/ExpressionProjectionConverter.java | 19 ++++-- .../impl/ShorthandProjectionConverter.java | 17 ++++-- .../impl/SubqueryProjectionConverter.java | 17 ++++-- .../segment/where/WhereConverter.java | 17 ++++-- .../segment/window/WindowConverter.java | 17 ++++-- .../converter/segment/with/WithConverter.java | 16 ++--- .../delete/DeleteStatementConverter.java | 12 ++-- .../insert/InsertStatementConverter.java | 6 +- .../merge/MergeStatementConverter.java | 14 ++--- .../select/SelectStatementConverter.java | 20 +++---- .../update/UpdateStatementConverter.java | 14 ++--- 53 files changed, 668 insertions(+), 377 deletions(-) delete mode 100644 kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/SQLSegmentConverter.java diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/SQLNodeConverterEngine.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/SQLNodeConverterEngine.java index 43c50f0da3df0..0538c2618e8ad 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/SQLNodeConverterEngine.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/SQLNodeConverterEngine.java @@ -21,7 +21,10 @@ import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.MergeStatement; @@ -35,6 +38,8 @@ import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.update.UpdateStatementConverter; import org.apache.shardingsphere.sqlfederation.optimizer.exception.OptimizationSQLNodeConvertException; +import java.util.Optional; + /** * SQL node converter engine. */ @@ -42,31 +47,51 @@ public final class SQLNodeConverterEngine { /** - * Convert SQL statement to SQL node. + * Convert SQL sql statement to SQL node. * - * @param statement SQL statement to be converted + * @param sqlStatement SQL sqlStatement to be converted * @return sqlNode converted SQL node * @throws OptimizationSQLNodeConvertException optimization SQL node convert exception */ - public static SqlNode convert(final SQLStatement statement) { - if (statement instanceof SelectStatement) { - return new SelectStatementConverter().convert((SelectStatement) statement); + public static SqlNode convert(final SQLStatement sqlStatement) { + Optional result = Optional.empty(); + if (sqlStatement instanceof DMLStatement) { + result = convert((DMLStatement) sqlStatement); + } else if (sqlStatement instanceof DDLStatement) { + result = convert((DDLStatement) sqlStatement); + } else if (sqlStatement instanceof DALStatement) { + result = convert((DALStatement) sqlStatement); + } + return result.orElseThrow(() -> new OptimizationSQLNodeConvertException(sqlStatement)); + } + + private static Optional convert(final DMLStatement sqlStatement) { + if (sqlStatement instanceof SelectStatement) { + return Optional.of(new SelectStatementConverter().convert((SelectStatement) sqlStatement)); } - if (statement instanceof DeleteStatement) { - return new DeleteStatementConverter().convert((DeleteStatement) statement); + if (sqlStatement instanceof DeleteStatement) { + return Optional.of(new DeleteStatementConverter().convert((DeleteStatement) sqlStatement)); } - if (statement instanceof ExplainStatement) { - return new ExplainStatementConverter().convert((ExplainStatement) statement); + return Optional.empty(); + } + + private static Optional convert(final DDLStatement sqlStatement) { + if (sqlStatement instanceof UpdateStatement) { + return Optional.of(new UpdateStatementConverter().convert((UpdateStatement) sqlStatement)); } - if (statement instanceof UpdateStatement) { - return new UpdateStatementConverter().convert((UpdateStatement) statement); + if (sqlStatement instanceof InsertStatement) { + return Optional.of(new InsertStatementConverter().convert((InsertStatement) sqlStatement)); } - if (statement instanceof InsertStatement) { - return new InsertStatementConverter().convert((InsertStatement) statement); + if (sqlStatement instanceof MergeStatement) { + return Optional.of(new MergeStatementConverter().convert((MergeStatement) sqlStatement)); } - if (statement instanceof MergeStatement) { - return new MergeStatementConverter().convert((MergeStatement) statement); + return Optional.empty(); + } + + private static Optional convert(final DALStatement sqlStatement) { + if (sqlStatement instanceof ExplainStatement) { + return Optional.of(new ExplainStatementConverter().convert((ExplainStatement) sqlStatement)); } - throw new OptimizationSQLNodeConvertException(statement); + return Optional.empty(); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/SQLSegmentConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/SQLSegmentConverter.java deleted file mode 100644 index b8ffef39e5d5b..0000000000000 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/SQLSegmentConverter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment; - -import org.apache.calcite.sql.SqlNode; -import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment; - -import java.util.Optional; - -/** - * SQL segment converter. - * - * @param type of SQL segment - * @param type of SQL node - */ -public interface SQLSegmentConverter { - - /** - * Convert. - * - * @param segment SQL segment be to converted - * @return converted SQL node - */ - Optional convert(S segment); -} diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/ExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/ExpressionConverter.java index add0102955f7b..883bc1aad84f0 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/ExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/ExpressionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment; @@ -42,7 +44,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl.BetweenExpressionConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl.BinaryOperationExpressionConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl.CaseWhenExpressionConverter; @@ -70,79 +71,86 @@ /** * Expression converter. */ -public final class ExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ExpressionConverter { - @Override - public Optional convert(final ExpressionSegment segment) { + /** + * Convert expression segment to sql node. + * + * @param segment expression segment + * @return sql node + * @throws UnsupportedSQLOperationException unsupported SQL operation exception + */ + public static Optional convert(final ExpressionSegment segment) { if (null == segment) { return Optional.empty(); } if (segment instanceof LiteralExpressionSegment) { - return new LiteralExpressionConverter().convert((LiteralExpressionSegment) segment); + return LiteralExpressionConverter.convert((LiteralExpressionSegment) segment); } if (segment instanceof CommonExpressionSegment) { // TODO throw new UnsupportedSQLOperationException("unsupported CommonExpressionSegment"); } if (segment instanceof ListExpression) { - return new ListExpressionConverter().convert((ListExpression) segment); + return ListExpressionConverter.convert((ListExpression) segment); } if (segment instanceof BinaryOperationExpression) { - return new BinaryOperationExpressionConverter().convert((BinaryOperationExpression) segment); + return BinaryOperationExpressionConverter.convert((BinaryOperationExpression) segment); } if (segment instanceof ColumnSegment) { - return new ColumnConverter().convert((ColumnSegment) segment); + return ColumnConverter.convert((ColumnSegment) segment); } if (segment instanceof ExistsSubqueryExpression) { - return new ExistsSubqueryExpressionConverter().convert((ExistsSubqueryExpression) segment); + return ExistsSubqueryExpressionConverter.convert((ExistsSubqueryExpression) segment); } if (segment instanceof SubqueryExpressionSegment) { - return new SubqueryExpressionConverter().convert((SubqueryExpressionSegment) segment); + return SubqueryExpressionConverter.convert((SubqueryExpressionSegment) segment); } if (segment instanceof InExpression) { - return new InExpressionConverter().convert((InExpression) segment); + return InExpressionConverter.convert((InExpression) segment); } if (segment instanceof BetweenExpression) { - return new BetweenExpressionConverter().convert((BetweenExpression) segment); + return BetweenExpressionConverter.convert((BetweenExpression) segment); } if (segment instanceof ParameterMarkerExpressionSegment) { - return new ParameterMarkerExpressionConverter().convert((ParameterMarkerExpressionSegment) segment); + return ParameterMarkerExpressionConverter.convert((ParameterMarkerExpressionSegment) segment); } if (segment instanceof FunctionSegment) { - return new FunctionConverter().convert((FunctionSegment) segment); + return FunctionConverter.convert((FunctionSegment) segment); } if (segment instanceof AggregationProjectionSegment) { - return new AggregationProjectionConverter().convert((AggregationProjectionSegment) segment); + return AggregationProjectionConverter.convert((AggregationProjectionSegment) segment); } if (segment instanceof DataTypeSegment) { - return new DataTypeConverter().convert((DataTypeSegment) segment); + return DataTypeConverter.convert((DataTypeSegment) segment); } if (segment instanceof CaseWhenExpression) { - return new CaseWhenExpressionConverter().convert((CaseWhenExpression) segment); + return CaseWhenExpressionConverter.convert((CaseWhenExpression) segment); } if (segment instanceof NotExpression) { - return new NotExpressionConverter().convert((NotExpression) segment); + return NotExpressionConverter.convert((NotExpression) segment); } if (segment instanceof TypeCastExpression) { - return new TypeCastExpressionConverter().convert((TypeCastExpression) segment); + return TypeCastExpressionConverter.convert((TypeCastExpression) segment); } if (segment instanceof ExtractArgExpression) { - return new ExtractArgExpressionConverter().convert((ExtractArgExpression) segment); + return ExtractArgExpressionConverter.convert((ExtractArgExpression) segment); } if (segment instanceof MatchAgainstExpression) { - return new MatchExpressionConverter().convert((MatchAgainstExpression) segment); + return MatchExpressionConverter.convert((MatchAgainstExpression) segment); } if (segment instanceof CollateExpression) { - return new CollateExpressionConverter().convert((CollateExpression) segment); + return CollateExpressionConverter.convert((CollateExpression) segment); } if (segment instanceof RowExpression) { - return new RowExpressionConverter().convert((RowExpression) segment); + return RowExpressionConverter.convert((RowExpression) segment); } if (segment instanceof VariableSegment) { - return new VariableSegmentConverter().convert((VariableSegment) segment); + return VariableSegmentConverter.convert((VariableSegment) segment); } if (segment instanceof UnaryOperationExpression) { - return new UnaryOperationExpressionConverter().convert((UnaryOperationExpression) segment); + return UnaryOperationExpressionConverter.convert((UnaryOperationExpression) segment); } throw new UnsupportedSQLOperationException("unsupported TableSegment type: " + segment.getClass()); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BetweenExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BetweenExpressionConverter.java index 7cf5a3bf1f8b5..432d6a53dc448 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BetweenExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BetweenExpressionConverter.java @@ -17,12 +17,13 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.ArrayList; @@ -33,18 +34,23 @@ /** * Between expression converter. */ -public final class BetweenExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class BetweenExpressionConverter { - @Override - public Optional convert(final BetweenExpression expression) { + /** + * Convert between expression to sql node. + * + * @param expression between expression + * @return sql node + */ + public static Optional convert(final BetweenExpression expression) { if (null == expression) { return Optional.empty(); } Collection sqlNodes = new LinkedList<>(); - ExpressionConverter expressionConverter = new ExpressionConverter(); - expressionConverter.convert(expression.getLeft()).ifPresent(sqlNodes::add); - expressionConverter.convert(expression.getBetweenExpr()).ifPresent(sqlNodes::add); - expressionConverter.convert(expression.getAndExpr()).ifPresent(sqlNodes::add); + ExpressionConverter.convert(expression.getLeft()).ifPresent(sqlNodes::add); + ExpressionConverter.convert(expression.getBetweenExpr()).ifPresent(sqlNodes::add); + ExpressionConverter.convert(expression.getAndExpr()).ifPresent(sqlNodes::add); return Optional.of(expression.isNot() ? new SqlBasicCall(SqlStdOperatorTable.NOT_BETWEEN, new ArrayList<>(sqlNodes), SqlParserPos.ZERO) : new SqlBasicCall(SqlStdOperatorTable.BETWEEN, new ArrayList<>(sqlNodes), SqlParserPos.ZERO)); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java index da3590739a1f4..0bd603693b075 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; import com.google.common.base.Preconditions; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; @@ -28,7 +30,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql.SQLExtensionOperatorTable; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Collections; @@ -40,7 +41,8 @@ /** * Binary operation expression converter. */ -public final class BinaryOperationExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class BinaryOperationExpressionConverter { private static final Map REGISTRY = new CaseInsensitiveMap<>(); @@ -99,14 +101,19 @@ private static void registerAlias() { REGISTRY.put("!~*", SqlStdOperatorTable.NEGATED_POSIX_REGEX_CASE_INSENSITIVE); } - @Override - public Optional convert(final BinaryOperationExpression segment) { + /** + * Convert binary operation expression to sql node. + * + * @param segment binary operation expression + * @return sql node + */ + public static Optional convert(final BinaryOperationExpression segment) { SqlOperator operator = convertOperator(segment); List sqlNodes = convertSqlNodes(segment, operator); return Optional.of(new SqlBasicCall(operator, sqlNodes, SqlParserPos.ZERO)); } - private SqlOperator convertOperator(final BinaryOperationExpression segment) { + private static SqlOperator convertOperator(final BinaryOperationExpression segment) { String operator = segment.getOperator(); if ("IS".equalsIgnoreCase(operator)) { String literals = String.valueOf(((LiteralExpressionSegment) segment.getRight()).getLiterals()); @@ -124,13 +131,13 @@ private SqlOperator convertOperator(final BinaryOperationExpression segment) { return REGISTRY.get(operator); } - private List convertSqlNodes(final BinaryOperationExpression segment, final SqlOperator operator) { - SqlNode left = new ExpressionConverter().convert(segment.getLeft()).orElseThrow(IllegalStateException::new); + private static List convertSqlNodes(final BinaryOperationExpression segment, final SqlOperator operator) { + SqlNode left = ExpressionConverter.convert(segment.getLeft()).orElseThrow(IllegalStateException::new); List result = new LinkedList<>(); result.add(left); if (!SqlStdOperatorTable.IS_NULL.equals(operator) && !SqlStdOperatorTable.IS_NOT_NULL.equals(operator) && !SqlStdOperatorTable.IS_FALSE.equals(operator) && !SqlStdOperatorTable.IS_NOT_FALSE.equals(operator)) { - SqlNode right = new ExpressionConverter().convert(segment.getRight()).orElseThrow(IllegalStateException::new); + SqlNode right = ExpressionConverter.convert(segment.getRight()).orElseThrow(IllegalStateException::new); result.addAll(right instanceof SqlNodeList ? ((SqlNodeList) right).getList() : Collections.singletonList(right)); } return result; diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CaseWhenExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CaseWhenExpressionConverter.java index 2c694d96295c6..6f7b36bfddef4 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CaseWhenExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CaseWhenExpressionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlLiteral; import org.apache.calcite.sql.SqlNode; @@ -26,7 +28,6 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CaseWhenExpression; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Arrays; @@ -37,35 +38,41 @@ /** * Case when expression converter. */ -public final class CaseWhenExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class CaseWhenExpressionConverter { - @Override - public Optional convert(final CaseWhenExpression segment) { + /** + * Convert case when expression to sql node. + * + * @param segment case when expression + * @return sql node + */ + public static Optional convert(final CaseWhenExpression segment) { Collection whenExprs = convertWhenExprs(segment.getCaseExpr(), segment.getWhenExprs()); Collection thenExprs = new LinkedList<>(); - segment.getThenExprs().forEach(each -> new ExpressionConverter().convert(each).ifPresent(thenExprs::add)); - Optional elseExpr = new ExpressionConverter().convert(segment.getElseExpr()); + segment.getThenExprs().forEach(each -> ExpressionConverter.convert(each).ifPresent(thenExprs::add)); + Optional elseExpr = ExpressionConverter.convert(segment.getElseExpr()); return Optional.of(new SqlCase(SqlParserPos.ZERO, null, new SqlNodeList(whenExprs, SqlParserPos.ZERO), new SqlNodeList(thenExprs, SqlParserPos.ZERO), elseExpr.orElseGet(() -> SqlLiteral.createCharString("NULL", SqlParserPos.ZERO)))); } - private Collection convertWhenExprs(final ExpressionSegment caseExpr, final Collection whenExprs) { + private static Collection convertWhenExprs(final ExpressionSegment caseExpr, final Collection whenExprs) { Collection result = new LinkedList<>(); for (ExpressionSegment each : whenExprs) { if (null != caseExpr) { convertCaseExpr(caseExpr, each).ifPresent(result::add); } else { - new ExpressionConverter().convert(each).ifPresent(result::add); + ExpressionConverter.convert(each).ifPresent(result::add); } } return result; } - private Optional convertCaseExpr(final ExpressionSegment caseExpr, final ExpressionSegment whenExpr) { - Optional leftExpr = new ExpressionConverter().convert(caseExpr); - Optional rightExpr = new ExpressionConverter().convert(whenExpr); + private static Optional convertCaseExpr(final ExpressionSegment caseExpr, final ExpressionSegment whenExpr) { + Optional leftExpr = ExpressionConverter.convert(caseExpr); + Optional rightExpr = ExpressionConverter.convert(whenExpr); if (leftExpr.isPresent() && rightExpr.isPresent()) { - return new ExpressionConverter().convert(whenExpr).map(optional -> new SqlBasicCall(SqlStdOperatorTable.EQUALS, Arrays.asList(leftExpr.get(), rightExpr.get()), SqlParserPos.ZERO)); + return ExpressionConverter.convert(whenExpr).map(optional -> new SqlBasicCall(SqlStdOperatorTable.EQUALS, Arrays.asList(leftExpr.get(), rightExpr.get()), SqlParserPos.ZERO)); } return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CollateExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CollateExpressionConverter.java index ec584d92abc36..e53b0dde51637 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CollateExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/CollateExpressionConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CollateExpression; import org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql.SQLExtensionOperatorTable; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.LinkedList; @@ -33,13 +34,19 @@ /** * Collate expression converter. */ -public final class CollateExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class CollateExpressionConverter { - @Override - public Optional convert(final CollateExpression segment) { + /** + * Convert collate expression to sql node. + * + * @param segment collate expression + * @return sql node + */ + public static Optional convert(final CollateExpression segment) { List sqlNodes = new LinkedList<>(); - sqlNodes.add(segment.getExpr().flatMap(optional -> new ExpressionConverter().convert(optional)).orElse(SqlNodeList.EMPTY)); - sqlNodes.add(new ExpressionConverter().convert(segment.getCollateName()).orElse(SqlNodeList.EMPTY)); + sqlNodes.add(segment.getExpr().flatMap(ExpressionConverter::convert).orElse(SqlNodeList.EMPTY)); + sqlNodes.add(ExpressionConverter.convert(segment.getCollateName()).orElse(SqlNodeList.EMPTY)); return Optional.of(new SqlBasicCall(SQLExtensionOperatorTable.COLLATE, sqlNodes, SqlParserPos.ZERO)); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ColumnConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ColumnConverter.java index f69be7700c07d..5f930060b34db 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ColumnConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ColumnConverter.java @@ -17,12 +17,13 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.ArrayList; import java.util.List; @@ -31,17 +32,23 @@ /** * Column converter. */ -public final class ColumnConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ColumnConverter { - @Override - public Optional convert(final ColumnSegment segment) { + /** + * Convert column segment to sql node. + * + * @param segment column segment + * @return sql node + */ + public static Optional convert(final ColumnSegment segment) { List names = new ArrayList<>(); segment.getOwner().ifPresent(optional -> addOwnerNames(names, optional)); names.add(segment.getIdentifier().getValue()); return Optional.of(new SqlIdentifier(names, SqlParserPos.ZERO)); } - private void addOwnerNames(final List names, final OwnerSegment owner) { + private static void addOwnerNames(final List names, final OwnerSegment owner) { owner.getOwner().ifPresent(optional -> addOwnerNames(names, optional)); names.add(owner.getIdentifier().getValue()); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExistsSubqueryExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExistsSubqueryExpressionConverter.java index cfd128ebc5556..710c551fa59d5 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExistsSubqueryExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExistsSubqueryExpressionConverter.java @@ -17,12 +17,13 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExistsSubqueryExpression; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.select.SelectStatementConverter; import java.util.Collections; @@ -31,10 +32,16 @@ /** * Exists subquery expression converter. */ -public final class ExistsSubqueryExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ExistsSubqueryExpressionConverter { - @Override - public Optional convert(final ExistsSubqueryExpression expression) { + /** + * Convert exists subquery expression to sql node. + * + * @param expression exists subquery expression + * @return sql node + */ + public static Optional convert(final ExistsSubqueryExpression expression) { if (null == expression) { return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExtractArgExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExtractArgExpressionConverter.java index a2beaaa190e84..d5cc2773dd480 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExtractArgExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ExtractArgExpressionConverter.java @@ -17,21 +17,28 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExtractArgExpression; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.Optional; /** * Extract arg expression converter. */ -public final class ExtractArgExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ExtractArgExpressionConverter { - @Override - public Optional convert(final ExtractArgExpression expression) { + /** + * Convert extract arg expression to sql node. + * + * @param expression extract arg expression + * @return sql node + */ + public static Optional convert(final ExtractArgExpression expression) { if (null == expression) { return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/FunctionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/FunctionConverter.java index 70990573bcaac..06e78c2cb4248 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/FunctionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/FunctionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlIdentifier; @@ -30,7 +32,6 @@ import org.apache.calcite.sql.validate.SqlNameMatchers; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Collection; @@ -42,20 +43,26 @@ /** * Function converter. */ -public class FunctionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class FunctionConverter { - @Override - public Optional convert(final FunctionSegment segment) { + /** + * Convert function segment to sql node. + * + * @param segment function segment + * @return sql node + */ + public static Optional convert(final FunctionSegment segment) { SqlIdentifier functionName = new SqlIdentifier(segment.getFunctionName(), SqlParserPos.ZERO); // TODO optimize sql parse logic for select current_user. if ("CURRENT_USER".equalsIgnoreCase(functionName.getSimple())) { return Optional.of(functionName); } if ("TRIM".equalsIgnoreCase(functionName.getSimple())) { - return new TrimFunctionConverter().convert(segment); + return TrimFunctionConverter.convert(segment); } if ("OVER".equalsIgnoreCase(functionName.getSimple())) { - return new WindowFunctionConverter().convert(segment); + return WindowFunctionConverter.convert(segment); } List functions = new LinkedList<>(); SqlStdOperatorTable.instance().lookupOperatorOverloads(functionName, null, SqlSyntax.FUNCTION, functions, SqlNameMatchers.withCaseSensitive(false)); @@ -65,11 +72,10 @@ public Optional convert(final FunctionSegment segment) { : new SqlBasicCall(functions.iterator().next(), getFunctionParameters(segment.getParameters()), SqlParserPos.ZERO)); } - private List getFunctionParameters(final Collection sqlSegments) { + private static List getFunctionParameters(final Collection sqlSegments) { List result = new LinkedList<>(); - ExpressionConverter expressionConverter = new ExpressionConverter(); for (ExpressionSegment each : sqlSegments) { - expressionConverter.convert(each).ifPresent(optional -> result.addAll(optional instanceof SqlNodeList ? ((SqlNodeList) optional).getList() : Collections.singleton(optional))); + ExpressionConverter.convert(each).ifPresent(optional -> result.addAll(optional instanceof SqlNodeList ? ((SqlNodeList) optional).getList() : Collections.singleton(optional))); } return result; } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/InExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/InExpressionConverter.java index e3f30ba3b9b64..056a73f08b5c6 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/InExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/InExpressionConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.ArrayList; @@ -34,17 +35,22 @@ /** * In expression converter. */ -public final class InExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class InExpressionConverter { - @Override - public Optional convert(final InExpression expression) { + /** + * Convert in expression to sql node. + * + * @param expression in expression + * @return sql node + */ + public static Optional convert(final InExpression expression) { if (null == expression) { return Optional.empty(); } Collection sqlNodes = new LinkedList<>(); - ExpressionConverter expressionConverter = new ExpressionConverter(); - expressionConverter.convert(expression.getLeft()).ifPresent(sqlNodes::add); - expressionConverter.convert(expression.getRight()) + ExpressionConverter.convert(expression.getLeft()).ifPresent(sqlNodes::add); + ExpressionConverter.convert(expression.getRight()) .ifPresent(optional -> sqlNodes.add(optional instanceof SqlBasicCall ? new SqlNodeList(((SqlBasicCall) optional).getOperandList(), SqlParserPos.ZERO) : optional)); return Optional.of(new SqlBasicCall(expression.isNot() ? SqlStdOperatorTable.NOT_IN : SqlStdOperatorTable.IN, new ArrayList<>(sqlNodes), SqlParserPos.ZERO)); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ListExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ListExpressionConverter.java index 65d649ed558f7..40f93891f4907 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ListExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ListExpressionConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.parser.SqlParserPos; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression; +import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Collection; import java.util.LinkedList; @@ -32,13 +33,19 @@ /** * List expression converter. */ -public final class ListExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ListExpressionConverter { - @Override - public Optional convert(final ListExpression segment) { + /** + * Convert list expression to sql node. + * + * @param segment list expression + * @return sql node + */ + public static Optional convert(final ListExpression segment) { Collection sqlNodes = new LinkedList<>(); for (ExpressionSegment each : segment.getItems()) { - Optional sqlNode = new ExpressionConverter().convert(each); + Optional sqlNode = ExpressionConverter.convert(each); sqlNode.ifPresent(sqlNodes::add); } return sqlNodes.isEmpty() ? Optional.empty() : Optional.of(new SqlNodeList(sqlNodes, SqlParserPos.ZERO)); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/LiteralExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/LiteralExpressionConverter.java index 1c5ac07902cf5..26a74e5904182 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/LiteralExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/LiteralExpressionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.avatica.util.TimeUnit; import org.apache.calcite.sql.SqlIntervalQualifier; import org.apache.calcite.sql.SqlLiteral; @@ -24,7 +26,6 @@ import org.apache.calcite.sql.fun.SqlTrimFunction.Flag; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.math.BigDecimal; import java.util.Collection; @@ -34,7 +35,8 @@ /** * Literal expression converter. */ -public final class LiteralExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class LiteralExpressionConverter { private static final Collection TRIM_FUNCTION_FLAGS = new HashSet<>(3, 1F); @@ -52,8 +54,13 @@ public final class LiteralExpressionConverter implements SQLSegmentConverter convert(final LiteralExpressionSegment segment) { + /** + * Convert literal expression segment to sql node. + * + * @param segment literal expression segment + * @return sql node + */ + public static Optional convert(final LiteralExpressionSegment segment) { if (null == segment.getLiterals()) { return Optional.of(SqlLiteral.createNull(SqlParserPos.ZERO)); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/MatchExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/MatchExpressionConverter.java index 6804c80efee9f..a01197c258839 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/MatchExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/MatchExpressionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlLiteral; @@ -25,7 +27,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.MatchAgainstExpression; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment; import org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql.SQLExtensionOperatorTable; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.ArrayList; @@ -36,10 +37,16 @@ /** * Match expression converter. */ -public final class MatchExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class MatchExpressionConverter { - @Override - public Optional convert(final MatchAgainstExpression segment) { + /** + * Convert match against expression to sql node. + * + * @param segment match against expression + * @return sql node + */ + public static Optional convert(final MatchAgainstExpression segment) { List sqlNodes = new LinkedList<>(); List names = new ArrayList<>(); if (segment.getColumnName().getOwner().isPresent()) { @@ -47,13 +54,13 @@ public Optional convert(final MatchAgainstExpression segment) { } names.add(segment.getColumnName().getIdentifier().getValue()); sqlNodes.add(new SqlIdentifier(names, SqlParserPos.ZERO)); - new ExpressionConverter().convert(segment.getExpr()).ifPresent(sqlNodes::add); + ExpressionConverter.convert(segment.getExpr()).ifPresent(sqlNodes::add); SqlNode searchModifier = SqlLiteral.createCharString(segment.getSearchModifier(), SqlParserPos.ZERO); sqlNodes.add(searchModifier); return Optional.of(new SqlBasicCall(SQLExtensionOperatorTable.MATCH_AGAINST, sqlNodes, SqlParserPos.ZERO)); } - private void addOwnerNames(final List names, final OwnerSegment owner) { + private static void addOwnerNames(final List names, final OwnerSegment owner) { if (null != owner) { addOwnerNames(names, owner.getOwner().orElse(null)); names.add(owner.getIdentifier().getValue()); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/NotExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/NotExpressionConverter.java index eb171aa650d96..b7d46c4bf55f6 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/NotExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/NotExpressionConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.NotExpression; import org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql.SQLExtensionOperatorTable; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.LinkedList; @@ -33,11 +34,17 @@ /** * Not expression converter. */ -public final class NotExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class NotExpressionConverter { - @Override - public Optional convert(final NotExpression segment) { - SqlNode expression = new ExpressionConverter().convert(segment.getExpression()).orElseThrow(IllegalStateException::new); + /** + * Convert not expression to sql node. + * + * @param segment not expression + * @return sql node + */ + public static Optional convert(final NotExpression segment) { + SqlNode expression = ExpressionConverter.convert(segment.getExpression()).orElseThrow(IllegalStateException::new); List sqlNodes = new LinkedList<>(); sqlNodes.add(expression); if (segment.getNotSign().equals(true)) { diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ParameterMarkerExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ParameterMarkerExpressionConverter.java index a3fdc937d313d..2a4e668a63dbc 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ParameterMarkerExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/ParameterMarkerExpressionConverter.java @@ -17,10 +17,11 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlDynamicParam; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParserPos; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment; import java.util.Optional; @@ -28,10 +29,16 @@ /** * Parameter marker expression converter. */ -public final class ParameterMarkerExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ParameterMarkerExpressionConverter { - @Override - public Optional convert(final ParameterMarkerExpressionSegment segment) { + /** + * Convert parameter marker expression segment to sql node. + * + * @param segment parameter marker expression segment + * @return sql node + */ + public static Optional convert(final ParameterMarkerExpressionSegment segment) { return Optional.of(new SqlDynamicParam(segment.getParameterMarkerIndex(), SqlParserPos.ZERO)); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/RowExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/RowExpressionConverter.java index dbee3c0cf58da..b2859fb320170 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/RowExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/RowExpressionConverter.java @@ -17,12 +17,13 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.RowExpression; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.ArrayList; @@ -32,14 +33,19 @@ /** * Row expression converter. */ -public final class RowExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class RowExpressionConverter { - @Override - public Optional convert(final RowExpression segment) { + /** + * Convert row expression to sql node. + * + * @param segment row expression + * @return sql node + */ + public static Optional convert(final RowExpression segment) { List sqlNodes = new ArrayList<>(); - ExpressionConverter expressionConverter = new ExpressionConverter(); for (ExpressionSegment each : segment.getItems()) { - expressionConverter.convert(each).ifPresent(sqlNodes::add); + ExpressionConverter.convert(each).ifPresent(sqlNodes::add); } return Optional.of(SqlStdOperatorTable.ROW.createCall(SqlParserPos.ZERO, sqlNodes)); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SubqueryExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SubqueryExpressionConverter.java index f4c735d83365c..e5cdb77ab6ba4 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SubqueryExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/SubqueryExpressionConverter.java @@ -17,20 +17,27 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.select.SelectStatementConverter; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment; +import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.select.SelectStatementConverter; import java.util.Optional; /** * Subquery expression converter. */ -public final class SubqueryExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SubqueryExpressionConverter { - @Override - public Optional convert(final SubqueryExpressionSegment expression) { + /** + * Convert subquery expression segment to sql node. + * + * @param expression subquery expression segment + * @return sql node + */ + public static Optional convert(final SubqueryExpressionSegment expression) { return null == expression ? Optional.empty() : Optional.of(new SelectStatementConverter().convert(expression.getSubquery().getSelect())); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/TrimFunctionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/TrimFunctionConverter.java index 5cb9d30e831db..25acb57823100 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/TrimFunctionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/TrimFunctionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlLiteral; @@ -39,17 +41,23 @@ /** * Trim function converter. */ -public final class TrimFunctionConverter extends FunctionConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class TrimFunctionConverter { - @Override - public Optional convert(final FunctionSegment segment) { + /** + * Convert function segment to sql node. + * + * @param segment function segment + * @return sql node + */ + public static Optional convert(final FunctionSegment segment) { SqlIdentifier functionName = new SqlIdentifier(segment.getFunctionName(), SqlParserPos.ZERO); List functions = new LinkedList<>(); SqlStdOperatorTable.instance().lookupOperatorOverloads(functionName, null, SqlSyntax.FUNCTION, functions, SqlNameMatchers.withCaseSensitive(false)); return Optional.of(new SqlBasicCall(functions.iterator().next(), getTrimFunctionParameters(segment.getParameters()), SqlParserPos.ZERO)); } - private List getTrimFunctionParameters(final Collection sqlSegments) { + private static List getTrimFunctionParameters(final Collection sqlSegments) { List result = new LinkedList<>(); if (1 == sqlSegments.size()) { result.add(Flag.BOTH.symbol(SqlParserPos.ZERO)); @@ -59,7 +67,7 @@ private List getTrimFunctionParameters(final Collection { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class TypeCastExpressionConverter { - @Override - public Optional convert(final TypeCastExpression segment) { - Optional expression = new ExpressionConverter().convert(segment.getExpression()); + /** + * Convert type cast expression to sql node. + * + * @param segment type cast expression + * @return sql node + */ + public static Optional convert(final TypeCastExpression segment) { + Optional expression = ExpressionConverter.convert(segment.getExpression()); if (!expression.isPresent()) { return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/UnaryOperationExpressionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/UnaryOperationExpressionConverter.java index e63946a998c05..93035e7f218f5 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/UnaryOperationExpressionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/UnaryOperationExpressionConverter.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; import com.google.common.base.Preconditions; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlOperator; @@ -26,7 +28,6 @@ import org.apache.commons.collections4.map.CaseInsensitiveMap; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.UnaryOperationExpression; import org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql.SQLExtensionOperatorTable; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.LinkedList; @@ -37,7 +38,8 @@ /** * Unary operation expression converter. */ -public final class UnaryOperationExpressionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class UnaryOperationExpressionConverter { private static final Map REGISTRY = new CaseInsensitiveMap<>(); @@ -55,21 +57,26 @@ private static void register(final SqlOperator sqlOperator) { REGISTRY.put(sqlOperator.getName(), sqlOperator); } - @Override - public Optional convert(final UnaryOperationExpression segment) { + /** + * Convert unary operation expression to sql node. + * + * @param segment unary operation expression + * @return sql node + */ + public static Optional convert(final UnaryOperationExpression segment) { SqlOperator operator = convertOperator(segment); List sqlNodes = convertSqlNodes(segment); return Optional.of(new SqlBasicCall(operator, sqlNodes, SqlParserPos.ZERO)); } - private SqlOperator convertOperator(final UnaryOperationExpression segment) { + private static SqlOperator convertOperator(final UnaryOperationExpression segment) { String operator = segment.getOperator(); Preconditions.checkState(REGISTRY.containsKey(operator), "Unsupported SQL operator: %s", operator); return REGISTRY.get(operator); } - private List convertSqlNodes(final UnaryOperationExpression segment) { - SqlNode expression = new ExpressionConverter().convert(segment.getExpression()).orElseThrow(IllegalStateException::new); + private static List convertSqlNodes(final UnaryOperationExpression segment) { + SqlNode expression = ExpressionConverter.convert(segment.getExpression()).orElseThrow(IllegalStateException::new); List result = new LinkedList<>(); result.add(expression); return result; diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/VariableSegmentConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/VariableSegmentConverter.java index 79bde9d68a5c8..018867e4629b8 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/VariableSegmentConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/VariableSegmentConverter.java @@ -17,21 +17,28 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.Optional; /** * Variable segment converter. */ -public final class VariableSegmentConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class VariableSegmentConverter { - @Override - public Optional convert(final VariableSegment segment) { + /** + * Convert variable segment to sql node. + * + * @param segment variable segment + * @return sql node + */ + public static Optional convert(final VariableSegment segment) { return Optional.of(new SqlIdentifier(segment.getText(), SqlParserPos.ZERO)); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/WindowFunctionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/WindowFunctionConverter.java index 66afe044d1c6d..d379c858ce16e 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/WindowFunctionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/expression/impl/WindowFunctionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlLiteral; @@ -40,20 +42,26 @@ /** * Window function converter. */ -public final class WindowFunctionConverter extends FunctionConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class WindowFunctionConverter { - @Override - public Optional convert(final FunctionSegment segment) { + /** + * Convert function segment to sql node. + * + * @param segment function segment + * @return sql node + */ + public static Optional convert(final FunctionSegment segment) { SqlIdentifier functionName = new SqlIdentifier(segment.getFunctionName(), SqlParserPos.ZERO); List functions = new LinkedList<>(); SqlStdOperatorTable.instance().lookupOperatorOverloads(functionName, null, SqlSyntax.BINARY, functions, SqlNameMatchers.withCaseSensitive(false)); return Optional.of(new SqlBasicCall(functions.iterator().next(), getWindowFunctionParameters(segment.getParameters()), SqlParserPos.ZERO)); } - private List getWindowFunctionParameters(final Collection sqlSegments) { + private static List getWindowFunctionParameters(final Collection sqlSegments) { List result = new LinkedList<>(); for (ExpressionSegment each : sqlSegments) { - new ExpressionConverter().convert(each).ifPresent(result::add); + ExpressionConverter.convert(each).ifPresent(result::add); } if (1 == result.size()) { result.add(new SqlWindow(SqlParserPos.ZERO, null, null, new SqlNodeList(SqlParserPos.ZERO), new SqlNodeList(SqlParserPos.ZERO), SqlLiteral.createBoolean(false, SqlParserPos.ZERO), null, diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/TableConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/TableConverter.java index 30b98a4069615..e694d8d4ce9a3 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/TableConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/TableConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.DeleteMultiTableSegment; @@ -24,7 +26,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl.DeleteMultiTableConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl.JoinTableConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl.SimpleTableConverter; @@ -35,24 +36,31 @@ /** * Table converter. */ -public final class TableConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class TableConverter { - @Override - public Optional convert(final TableSegment segment) { + /** + * Convert table segment to sql node. + * + * @param segment table segment + * @return sql node + * @throws UnsupportedSQLOperationException unsupported SQL operation exception + */ + public static Optional convert(final TableSegment segment) { if (null == segment) { return Optional.empty(); } if (segment instanceof SimpleTableSegment) { - return new SimpleTableConverter().convert((SimpleTableSegment) segment); + return SimpleTableConverter.convert((SimpleTableSegment) segment); } if (segment instanceof JoinTableSegment) { - return new JoinTableConverter().convert((JoinTableSegment) segment); + return JoinTableConverter.convert((JoinTableSegment) segment); } if (segment instanceof SubqueryTableSegment) { - return new SubqueryTableConverter().convert((SubqueryTableSegment) segment); + return SubqueryTableConverter.convert((SubqueryTableSegment) segment); } if (segment instanceof DeleteMultiTableSegment) { - return new DeleteMultiTableConverter().convert((DeleteMultiTableSegment) segment); + return DeleteMultiTableConverter.convert((DeleteMultiTableSegment) segment); } throw new UnsupportedSQLOperationException("Unsupported segment type: " + segment.getClass()); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/DeleteMultiTableConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/DeleteMultiTableConverter.java index ca977b74c6549..bb2db09e986d8 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/DeleteMultiTableConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/DeleteMultiTableConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.DeleteMultiTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.TableConverter; import java.util.Collection; @@ -34,15 +35,21 @@ /** * Delete multi table converter. */ -public final class DeleteMultiTableConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DeleteMultiTableConverter { - @Override - public Optional convert(final DeleteMultiTableSegment segment) { + /** + * Convert delete multi table segment to sql node. + * + * @param segment delete multi table segment + * @return sql node + */ + public static Optional convert(final DeleteMultiTableSegment segment) { if (null == segment) { return Optional.empty(); } Collection sqlNodes = new LinkedList<>(); - new TableConverter().convert(segment.getRelationTable()).ifPresent(sqlNodes::add); + TableConverter.convert(segment.getRelationTable()).ifPresent(sqlNodes::add); List tableNames = new LinkedList<>(); for (SimpleTableSegment each : segment.getActualDeleteTables()) { tableNames.add(each.getTableName().getIdentifier().getValue()); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/JoinTableConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/JoinTableConverter.java index 623665f5741e0..1abb4113cc835 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/JoinTableConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/JoinTableConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.JoinConditionType; import org.apache.calcite.sql.JoinType; import org.apache.calcite.sql.SqlJoin; @@ -26,7 +28,6 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl.ColumnConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.TableConverter; @@ -38,12 +39,18 @@ /** * Join converter. */ -public final class JoinTableConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class JoinTableConverter { - @Override - public Optional convert(final JoinTableSegment segment) { - SqlNode left = new TableConverter().convert(segment.getLeft()).orElseThrow(IllegalStateException::new); - SqlNode right = new TableConverter().convert(segment.getRight()).orElseThrow(IllegalStateException::new); + /** + * Convert join table segment to sql node. + * + * @param segment join table segment + * @return sql node + */ + public static Optional convert(final JoinTableSegment segment) { + SqlNode left = TableConverter.convert(segment.getLeft()).orElseThrow(IllegalStateException::new); + SqlNode right = TableConverter.convert(segment.getRight()).orElseThrow(IllegalStateException::new); Optional condition = convertJoinCondition(segment); SqlLiteral conditionType = convertConditionType(segment); SqlLiteral joinType = convertJoinType(segment); @@ -57,24 +64,23 @@ private static SqlLiteral convertJoinType(final JoinTableSegment segment) { return JoinType.valueOf(segment.getJoinType()).symbol(SqlParserPos.ZERO); } - private SqlLiteral convertConditionType(final JoinTableSegment segment) { + private static SqlLiteral convertConditionType(final JoinTableSegment segment) { if (!segment.getUsing().isEmpty()) { return JoinConditionType.USING.symbol(SqlParserPos.ZERO); } return null == segment.getCondition() ? JoinConditionType.NONE.symbol(SqlParserPos.ZERO) : JoinConditionType.ON.symbol(SqlParserPos.ZERO); } - private Optional convertJoinCondition(final JoinTableSegment segment) { + private static Optional convertJoinCondition(final JoinTableSegment segment) { if (null != segment.getCondition()) { - return new ExpressionConverter().convert(segment.getCondition()); + return ExpressionConverter.convert(segment.getCondition()); } if (segment.getUsing().isEmpty()) { return Optional.empty(); } Collection sqlNodes = new LinkedList<>(); - ColumnConverter columnConverter = new ColumnConverter(); for (ColumnSegment each : segment.getUsing()) { - columnConverter.convert(each).ifPresent(sqlNodes::add); + ColumnConverter.convert(each).ifPresent(sqlNodes::add); } return Optional.of(new SqlNodeList(sqlNodes, SqlParserPos.ZERO)); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SimpleTableConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SimpleTableConverter.java index f5c0f64789a04..0b8d7f242f307 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SimpleTableConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SimpleTableConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; @@ -25,7 +27,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.ArrayList; import java.util.Arrays; @@ -35,10 +36,16 @@ /** * Simple table converter. */ -public final class SimpleTableConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SimpleTableConverter { - @Override - public Optional convert(final SimpleTableSegment segment) { + /** + * Convert simple table segment to sql node. + * + * @param segment simple table segment + * @return sql node + */ + public static Optional convert(final SimpleTableSegment segment) { TableNameSegment tableName = segment.getTableName(); List names = new ArrayList<>(); if (segment.getOwner().isPresent()) { @@ -53,7 +60,7 @@ public Optional convert(final SimpleTableSegment segment) { return Optional.of(tableNameSQLNode); } - private void addOwnerNames(final List names, final OwnerSegment owner) { + private static void addOwnerNames(final List names, final OwnerSegment owner) { if (null != owner) { addOwnerNames(names, owner.getOwner().orElse(null)); names.add(owner.getIdentifier().getValue()); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SubqueryTableConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SubqueryTableConverter.java index 5fbecb06442e5..92b73d0687f66 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SubqueryTableConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/from/impl/SubqueryTableConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.TableConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.select.SelectStatementConverter; @@ -37,16 +38,22 @@ /** * Subquery table converter. */ -public final class SubqueryTableConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SubqueryTableConverter { - @Override - public Optional convert(final SubqueryTableSegment segment) { + /** + * Convert subquery table segment to sql node. + * + * @param segment subquery table segment + * @return sql node + */ + public static Optional convert(final SubqueryTableSegment segment) { if (null == segment) { return Optional.empty(); } Collection sqlNodes = new LinkedList<>(); if (null == segment.getSubquery().getSelect().getProjections()) { - List tables = new TableConverter().convert(segment.getSubquery().getSelect().getFrom()).map(Collections::singletonList).orElseGet(Collections::emptyList); + List tables = TableConverter.convert(segment.getSubquery().getSelect().getFrom()).map(Collections::singletonList).orElseGet(Collections::emptyList); sqlNodes.add(new SqlBasicCall(SqlStdOperatorTable.EXPLICIT_TABLE, tables, SqlParserPos.ZERO)); } else { sqlNodes.add(new SelectStatementConverter().convert(segment.getSubquery().getSelect())); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/GroupByConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/GroupByConverter.java index aff400e43ca86..f0545635e9244 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/GroupByConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/GroupByConverter.java @@ -17,10 +17,11 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.groupby; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.orderby.item.OrderByItemConverterUtils; import java.util.Optional; @@ -28,10 +29,16 @@ /** * Group by converter. */ -public final class GroupByConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class GroupByConverter { - @Override - public Optional convert(final GroupBySegment segment) { + /** + * Convert group by segment to sql node list. + * + * @param segment group by segment + * @return sql node list + */ + public static Optional convert(final GroupBySegment segment) { return null == segment || segment.getGroupByItems().isEmpty() ? Optional.empty() : Optional.of(new SqlNodeList(OrderByItemConverterUtils.convert(segment.getGroupByItems()), SqlParserPos.ZERO)); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/HavingConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/HavingConverter.java index a762bd450ae62..ef4ee475e05b8 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/HavingConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/groupby/HavingConverter.java @@ -17,9 +17,10 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.groupby; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.HavingSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Optional; @@ -27,10 +28,16 @@ /** * Having converter. */ -public final class HavingConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class HavingConverter { - @Override - public Optional convert(final HavingSegment segment) { - return null == segment ? Optional.empty() : new ExpressionConverter().convert(segment.getExpr()); + /** + * Convert having segment to sql node. + * + * @param segment having segment + * @return sql node + */ + public static Optional convert(final HavingSegment segment) { + return null == segment ? Optional.empty() : ExpressionConverter.convert(segment.getExpr()); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/limit/PaginationValueSQLConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/limit/PaginationValueSQLConverter.java index 8bc54e6de0591..24b04a5942e29 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/limit/PaginationValueSQLConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/limit/PaginationValueSQLConverter.java @@ -17,7 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.limit; -import lombok.RequiredArgsConstructor; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlDynamicParam; import org.apache.calcite.sql.SqlLiteral; import org.apache.calcite.sql.SqlNode; @@ -25,28 +26,32 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.NumberLiteralPaginationValueSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.PaginationValueSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.Optional; /** * Pagination value converter. */ -@RequiredArgsConstructor -public final class PaginationValueSQLConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class PaginationValueSQLConverter { - @Override - public Optional convert(final PaginationValueSegment segment) { + /** + * Convert pagination value segment to sql node. + * + * @param segment pagination value segment + * @return sql node + */ + public static Optional convert(final PaginationValueSegment segment) { return Optional.of(segment instanceof NumberLiteralPaginationValueSegment ? getLiteralSQLNode((NumberLiteralPaginationValueSegment) segment) : getParameterMarkerSQLNode((ParameterMarkerLimitValueSegment) segment)); } - private SqlNode getLiteralSQLNode(final NumberLiteralPaginationValueSegment segment) { + private static SqlNode getLiteralSQLNode(final NumberLiteralPaginationValueSegment segment) { return SqlLiteral.createExactNumeric(String.valueOf(segment.getValue()), SqlParserPos.ZERO); } - private SqlNode getParameterMarkerSQLNode(final ParameterMarkerLimitValueSegment segment) { + private static SqlNode getParameterMarkerSQLNode(final ParameterMarkerLimitValueSegment segment) { return new SqlDynamicParam(segment.getParameterIndex(), SqlParserPos.ZERO); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/OrderByConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/OrderByConverter.java index 8f0a2425d2799..a8bf20430e68f 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/OrderByConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/OrderByConverter.java @@ -17,10 +17,11 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.orderby; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.OrderBySegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.orderby.item.OrderByItemConverterUtils; import java.util.Optional; @@ -28,10 +29,16 @@ /** * Order by converter. */ -public final class OrderByConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class OrderByConverter { - @Override - public Optional convert(final OrderBySegment segment) { + /** + * Convert order by segment to sql node. + * + * @param segment order by segment + * @return sql node + */ + public static Optional convert(final OrderBySegment segment) { return null == segment ? Optional.empty() : Optional.of(new SqlNodeList(OrderByItemConverterUtils.convert(segment.getOrderByItems()), SqlParserPos.ZERO)); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ColumnOrderByItemConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ColumnOrderByItemConverter.java index 090df09d34804..b63191fdbbf85 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ColumnOrderByItemConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ColumnOrderByItemConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.orderby.item; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlPostfixOperator; @@ -25,7 +27,6 @@ import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl.ColumnConverter; import java.util.Collections; @@ -34,11 +35,17 @@ /** * Column of order by item converter. */ -public final class ColumnOrderByItemConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ColumnOrderByItemConverter { - @Override - public Optional convert(final ColumnOrderByItemSegment segment) { - Optional result = new ColumnConverter().convert(segment.getColumn()); + /** + * Convert column order by item segment to sql node. + * + * @param segment column order by item segment + * @return sql node + */ + public static Optional convert(final ColumnOrderByItemSegment segment) { + Optional result = ColumnConverter.convert(segment.getColumn()); if (!result.isPresent()) { return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ExpressionOrderByItemConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ExpressionOrderByItemConverter.java index 97d0703c47d1a..b5708723ac422 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ExpressionOrderByItemConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/ExpressionOrderByItemConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.orderby.item; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlPostfixOperator; @@ -24,7 +26,6 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ExpressionOrderByItemSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Collections; @@ -33,11 +34,17 @@ /** * Expression of order by item converter. */ -public final class ExpressionOrderByItemConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ExpressionOrderByItemConverter { - @Override - public Optional convert(final ExpressionOrderByItemSegment segment) { - Optional result = null == segment ? Optional.empty() : new ExpressionConverter().convert(segment.getExpr()); + /** + * Convert expression order by item segment to sql node. + * + * @param segment expression order by item segment + * @return sql node + */ + public static Optional convert(final ExpressionOrderByItemSegment segment) { + Optional result = null == segment ? Optional.empty() : ExpressionConverter.convert(segment.getExpr()); if (!result.isPresent()) { return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/IndexOrderByItemConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/IndexOrderByItemConverter.java index fea56775e641c..937ca4edbc523 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/IndexOrderByItemConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/IndexOrderByItemConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.orderby.item; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlLiteral; import org.apache.calcite.sql.SqlNode; @@ -26,7 +28,6 @@ import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.Collections; import java.util.Optional; @@ -34,10 +35,16 @@ /** * Index order by item converter. */ -public final class IndexOrderByItemConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class IndexOrderByItemConverter { - @Override - public Optional convert(final IndexOrderByItemSegment segment) { + /** + * Convert index order by item segment to sql node. + * + * @param segment index order by item segment + * @return sql node + */ + public static Optional convert(final IndexOrderByItemSegment segment) { SqlNode result = SqlLiteral.createExactNumeric(String.valueOf(segment.getColumnIndex()), SqlParserPos.ZERO); if (OrderDirection.DESC == segment.getOrderDirection()) { result = new SqlBasicCall(SqlStdOperatorTable.DESC, Collections.singletonList(result), SqlParserPos.ZERO); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/OrderByItemConverterUtils.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/OrderByItemConverterUtils.java index 7b8415b0f82c7..e4244794702fb 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/OrderByItemConverterUtils.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/orderby/item/OrderByItemConverterUtils.java @@ -47,11 +47,11 @@ public static Collection convert(final Collection o Collection result = new LinkedList<>(); for (OrderByItemSegment each : orderByItems) { if (each instanceof ColumnOrderByItemSegment) { - new ColumnOrderByItemConverter().convert((ColumnOrderByItemSegment) each).ifPresent(result::add); + ColumnOrderByItemConverter.convert((ColumnOrderByItemSegment) each).ifPresent(result::add); } else if (each instanceof ExpressionOrderByItemSegment) { - new ExpressionOrderByItemConverter().convert((ExpressionOrderByItemSegment) each).ifPresent(result::add); + ExpressionOrderByItemConverter.convert((ExpressionOrderByItemSegment) each).ifPresent(result::add); } else if (each instanceof IndexOrderByItemSegment) { - new IndexOrderByItemConverter().convert((IndexOrderByItemSegment) each).ifPresent(result::add); + IndexOrderByItemConverter.convert((IndexOrderByItemSegment) each).ifPresent(result::add); } else if (each instanceof TextOrderByItemSegment) { throw new UnsupportedSQLOperationException("unsupported TextOrderByItemSegment"); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/DistinctConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/DistinctConverter.java index 633a845c6442c..65fc62edcec95 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/DistinctConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/DistinctConverter.java @@ -17,11 +17,12 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.SqlSelectKeyword; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.Collections; import java.util.Optional; @@ -29,10 +30,16 @@ /** * Distinct converter. */ -public final class DistinctConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DistinctConverter { - @Override - public Optional convert(final ProjectionsSegment segment) { + /** + * Convert projections segment to sql node list. + * + * @param segment projections segment + * @return sql node list + */ + public static Optional convert(final ProjectionsSegment segment) { return segment.isDistinctRow() ? Optional.of(new SqlNodeList(Collections.singletonList(SqlSelectKeyword.DISTINCT.symbol(SqlParserPos.ZERO)), SqlParserPos.ZERO)) : Optional.empty(); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/ProjectionsConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/ProjectionsConverter.java index bf3b633c9343b..250436f23924b 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/ProjectionsConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/ProjectionsConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.parser.SqlParserPos; @@ -27,7 +29,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl.AggregationProjectionConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl.ColumnProjectionConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl.ExpressionProjectionConverter; @@ -41,10 +42,16 @@ /** * Projection converter. */ -public final class ProjectionsConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ProjectionsConverter { - @Override - public Optional convert(final ProjectionsSegment segment) { + /** + * Convert projections segment to sql node list. + * + * @param segment projections segment + * @return sql node list + */ + public static Optional convert(final ProjectionsSegment segment) { Collection projectionSQLNodes = new LinkedList<>(); for (ProjectionSegment each : segment.getProjections()) { getProjectionSQLNode(each).ifPresent(projectionSQLNodes::add); @@ -52,21 +59,21 @@ public Optional convert(final ProjectionsSegment segment) { return Optional.of(new SqlNodeList(projectionSQLNodes, SqlParserPos.ZERO)); } - private Optional getProjectionSQLNode(final ProjectionSegment segment) { + private static Optional getProjectionSQLNode(final ProjectionSegment segment) { if (segment instanceof ColumnProjectionSegment) { - return new ColumnProjectionConverter().convert((ColumnProjectionSegment) segment); + return ColumnProjectionConverter.convert((ColumnProjectionSegment) segment); } if (segment instanceof ExpressionProjectionSegment) { - return new ExpressionProjectionConverter().convert((ExpressionProjectionSegment) segment); + return ExpressionProjectionConverter.convert((ExpressionProjectionSegment) segment); } if (segment instanceof ShorthandProjectionSegment) { - return new ShorthandProjectionConverter().convert((ShorthandProjectionSegment) segment); + return ShorthandProjectionConverter.convert((ShorthandProjectionSegment) segment); } if (segment instanceof SubqueryProjectionSegment) { - return new SubqueryProjectionConverter().convert((SubqueryProjectionSegment) segment); + return SubqueryProjectionConverter.convert((SubqueryProjectionSegment) segment); } if (segment instanceof AggregationProjectionSegment) { - return new AggregationProjectionConverter().convert((AggregationProjectionSegment) segment); + return AggregationProjectionConverter.convert((AggregationProjectionSegment) segment); } // TODO process other projection return Optional.empty(); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/AggregationProjectionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/AggregationProjectionConverter.java index ed64a99dbcdcd..8cbda108e787b 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/AggregationProjectionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/AggregationProjectionConverter.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl; import com.google.common.base.Preconditions; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlAggFunction; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; @@ -30,7 +32,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationDistinctProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Arrays; @@ -44,7 +45,8 @@ /** * Aggregation projection converter. */ -public final class AggregationProjectionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class AggregationProjectionConverter { private static final Map REGISTRY = new CaseInsensitiveMap<>(); @@ -61,8 +63,13 @@ private static void register(final SqlAggFunction sqlAggFunction) { REGISTRY.put(sqlAggFunction.getName(), sqlAggFunction); } - @Override - public Optional convert(final AggregationProjectionSegment segment) { + /** + * Convert aggregation projection segment to sql node. + * + * @param segment aggregation projection segment + * @return sql node + */ + public static Optional convert(final AggregationProjectionSegment segment) { if (null == segment) { return Optional.empty(); } @@ -77,19 +84,18 @@ public Optional convert(final AggregationProjectionSegment segment) { return Optional.of(sqlBasicCall); } - private SqlAggFunction convertOperator(final String operator) { + private static SqlAggFunction convertOperator(final String operator) { Preconditions.checkState(REGISTRY.containsKey(operator), "Unsupported SQL operator: `%s`", operator); return REGISTRY.get(operator); } - private List convertParameters(final Collection params, final String expression) { + private static List convertParameters(final Collection params, final String expression) { if (expression.contains("*")) { return Collections.singletonList(SqlIdentifier.star(SqlParserPos.ZERO)); } List result = new LinkedList<>(); - ExpressionConverter expressionConverter = new ExpressionConverter(); for (ExpressionSegment each : params) { - expressionConverter.convert(each).ifPresent(result::add); + ExpressionConverter.convert(each).ifPresent(result::add); } return result; } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ColumnProjectionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ColumnProjectionConverter.java index c915d6ed03702..00765122c1780 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ColumnProjectionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ColumnProjectionConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlAsOperator; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.impl.ColumnConverter; import java.util.Arrays; @@ -32,15 +33,21 @@ /** * Column projection converter. */ -public final class ColumnProjectionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ColumnProjectionConverter { - @Override - public Optional convert(final ColumnProjectionSegment segment) { + /** + * Convert column projection segment to sql node. + * + * @param segment column projection segment + * @return sql node + */ + public static Optional convert(final ColumnProjectionSegment segment) { if (segment.getAliasName().isPresent()) { - Optional column = new ColumnConverter().convert(segment.getColumn()); + Optional column = ColumnConverter.convert(segment.getColumn()); SqlIdentifier alias = new SqlIdentifier(segment.getAliasName().get(), SqlParserPos.ZERO); return column.map(optional -> new SqlBasicCall(new SqlAsOperator(), Arrays.asList(optional, alias), SqlParserPos.ZERO)); } - return new ColumnConverter().convert(segment.getColumn()); + return ColumnConverter.convert(segment.getColumn()); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/DataTypeConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/DataTypeConverter.java index 1c1d68b1be7e7..9f4e9252a0d30 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/DataTypeConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/DataTypeConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.calcite.sql.SqlBasicTypeNameSpec; import org.apache.calcite.sql.SqlDataTypeSpec; import org.apache.calcite.sql.SqlNode; -import org.apache.calcite.sql.SqlBasicTypeNameSpec; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.Objects; import java.util.Optional; @@ -31,10 +32,16 @@ /** * Data type converter. */ -public final class DataTypeConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DataTypeConverter { - @Override - public Optional convert(final DataTypeSegment segment) { + /** + * Convert data type segment to sql node. + * + * @param segment data type segment + * @return sql node + */ + public static Optional convert(final DataTypeSegment segment) { if (null == segment) { return Optional.empty(); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java index 189d0db4c4edb..f8eaeb818f55d 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java @@ -17,14 +17,15 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParserPos; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment; +import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Arrays; import java.util.Collections; @@ -33,14 +34,20 @@ /** * Expression projection converter. */ -public final class ExpressionProjectionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ExpressionProjectionConverter { - @Override - public Optional convert(final ExpressionProjectionSegment segment) { + /** + * Convert expression projection segment to sql node. + * + * @param segment expression projection segment + * @return sql node + */ + public static Optional convert(final ExpressionProjectionSegment segment) { if (null == segment) { return Optional.empty(); } - Optional result = new ExpressionConverter().convert(segment.getExpr()); + Optional result = ExpressionConverter.convert(segment.getExpr()); if (result.isPresent() && segment.getAliasName().isPresent()) { return Optional.of(new SqlBasicCall(SqlStdOperatorTable.AS, Arrays.asList(result.get(), SqlIdentifier.star(Collections.singletonList(segment.getAliasName().get()), SqlParserPos.ZERO, Collections.singletonList(SqlParserPos.ZERO))), SqlParserPos.ZERO)); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ShorthandProjectionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ShorthandProjectionConverter.java index 2cdfb1ec75b3a..ab335b218d147 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ShorthandProjectionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/ShorthandProjectionConverter.java @@ -18,12 +18,13 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl; import com.google.common.collect.ImmutableList; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import java.util.ArrayList; import java.util.List; @@ -33,10 +34,16 @@ /** * Shorthand projection converter. */ -public final class ShorthandProjectionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ShorthandProjectionConverter { - @Override - public Optional convert(final ShorthandProjectionSegment segment) { + /** + * Convert shorthand projection segment to sql node. + * + * @param segment shorthand projection segment + * @return sql node + */ + public static Optional convert(final ShorthandProjectionSegment segment) { if (null == segment) { return Optional.empty(); } @@ -49,7 +56,7 @@ public Optional convert(final ShorthandProjectionSegment segment) { return Optional.of(SqlIdentifier.star(SqlParserPos.ZERO)); } - private void addOwnerNames(final List names, final OwnerSegment owner) { + private static void addOwnerNames(final List names, final OwnerSegment owner) { owner.getOwner().ifPresent(optional -> addOwnerNames(names, optional)); names.add(owner.getIdentifier().getValue()); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/SubqueryProjectionConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/SubqueryProjectionConverter.java index 4489be4c3eff6..e16383d67f57a 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/SubqueryProjectionConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/projection/impl/SubqueryProjectionConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.projection.impl; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlBasicCall; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; @@ -24,7 +26,6 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.enums.SubqueryType; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.select.SelectStatementConverter; import java.util.ArrayList; @@ -36,10 +37,16 @@ /** * Subquery projection converter. */ -public final class SubqueryProjectionConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SubqueryProjectionConverter { - @Override - public Optional convert(final SubqueryProjectionSegment segment) { + /** + * Convert subquery projection segment to sql node. + * + * @param segment subquery projection segment + * @return sql node + */ + public static Optional convert(final SubqueryProjectionSegment segment) { if (null == segment) { return Optional.empty(); } @@ -52,7 +59,7 @@ public Optional convert(final SubqueryProjectionSegment segment) { : Optional.of(sqlNode); } - private SqlNode convertWithAlias(final SqlNode sqlNode, final String alias) { + private static SqlNode convertWithAlias(final SqlNode sqlNode, final String alias) { Collection sqlNodes = new LinkedList<>(); sqlNodes.add(sqlNode); sqlNodes.add(new SqlIdentifier(alias, SqlParserPos.ZERO)); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/where/WhereConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/where/WhereConverter.java index 5d43061a5eb29..c8a931ed73863 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/where/WhereConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/where/WhereConverter.java @@ -17,9 +17,10 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.where; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlNode; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Optional; @@ -27,10 +28,16 @@ /** * Where converter. */ -public final class WhereConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class WhereConverter { - @Override - public Optional convert(final WhereSegment segment) { - return null == segment ? Optional.empty() : new ExpressionConverter().convert(segment.getExpr()); + /** + * Convert where segment to sql node. + * + * @param segment where segment + * @return sql node + */ + public static Optional convert(final WhereSegment segment) { + return null == segment ? Optional.empty() : ExpressionConverter.convert(segment.getExpr()); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/window/WindowConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/window/WindowConverter.java index d28993fedc1e8..a8a454d3e365f 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/window/WindowConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/window/WindowConverter.java @@ -17,13 +17,14 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.window; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlLiteral; import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.SqlWindow; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.WindowSegment; -import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter; import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter; import java.util.Collections; @@ -32,12 +33,18 @@ /** * Window converter. */ -public final class WindowConverter implements SQLSegmentConverter { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class WindowConverter { - @Override - public Optional convert(final WindowSegment segment) { + /** + * Convert window segment to sql node list. + * + * @param segment window segment + * @return sql node list + */ + public static Optional convert(final WindowSegment segment) { SqlIdentifier sqlIdentifier = new SqlIdentifier(segment.getIdentifierValue().getValue(), SqlParserPos.ZERO); - SqlNodeList partitionList = new SqlNodeList(Collections.singletonList(new ExpressionConverter().convert(segment.getPartitionListSegments().iterator().next()).get()), SqlParserPos.ZERO); + SqlNodeList partitionList = new SqlNodeList(Collections.singletonList(ExpressionConverter.convert(segment.getPartitionListSegments().iterator().next()).get()), SqlParserPos.ZERO); SqlNodeList orderList = new SqlNodeList(SqlParserPos.ZERO); SqlWindow sqlWindow = new SqlWindow(SqlParserPos.ZERO, sqlIdentifier, null, partitionList, orderList, SqlLiteral.createBoolean(false, SqlParserPos.ZERO), null, null, null); SqlNodeList result = new SqlNodeList(Collections.singletonList(sqlWindow), SqlParserPos.ZERO); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/with/WithConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/with/WithConverter.java index 0dbf56b2500f1..c27b9d0949b94 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/with/WithConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/segment/with/WithConverter.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.with; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlNodeList; @@ -35,30 +37,30 @@ /** * With converter. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class WithConverter { /** - * Convert the given WithSegment and query into an SqlNodeList. + * Convert with segment to sql node list. * * @param withSegment with segment - * @param query SqlNode - * @return SqlNodeList + * @param sqlNode sql node + * @return sql node list */ - public Optional convert(final WithSegment withSegment, final SqlNode query) { + public static Optional convert(final WithSegment withSegment, final SqlNode sqlNode) { SqlIdentifier name = new SqlIdentifier(withSegment.getCommonTableExpressions().iterator().next().getIdentifier().getValue(), SqlParserPos.ZERO); SqlNode selectSubquery = new SelectStatementConverter().convert(withSegment.getCommonTableExpressions().iterator().next().getSubquery().getSelect()); - ExpressionConverter converter = new ExpressionConverter(); Collection collectionColumns = withSegment.getCommonTableExpressions().iterator().next().getColumns(); Collection convertedColumns; SqlNodeList columns = null; if (!collectionColumns.isEmpty()) { - convertedColumns = collectionColumns.stream().map(converter::convert).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()); + convertedColumns = collectionColumns.stream().map(ExpressionConverter::convert).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()); columns = new SqlNodeList(convertedColumns, SqlParserPos.ZERO); } SqlWithItem sqlWithItem = new SqlWithItem(SqlParserPos.ZERO, name, columns, selectSubquery); SqlNodeList sqlWithItems = new SqlNodeList(SqlParserPos.ZERO); sqlWithItems.add(sqlWithItem); - SqlWith sqlWith = new SqlWith(SqlParserPos.ZERO, sqlWithItems, query); + SqlWith sqlWith = new SqlWith(SqlParserPos.ZERO, sqlWithItems, sqlNode); SqlNodeList result = new SqlNodeList(SqlParserPos.ZERO); result.add(sqlWith); return Optional.of(result); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/delete/DeleteStatementConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/delete/DeleteStatementConverter.java index c99285f63ba98..fb7864e9d0545 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/delete/DeleteStatementConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/delete/DeleteStatementConverter.java @@ -43,21 +43,21 @@ public final class DeleteStatementConverter implements SQLStatementConverter new OrderByConverter().convert(optional)).orElse(SqlNodeList.EMPTY); + SqlNodeList orderBy = DeleteStatementHandler.getOrderBySegment(deleteStatement).flatMap(OrderByConverter::convert).orElse(SqlNodeList.EMPTY); Optional limit = DeleteStatementHandler.getLimitSegment(deleteStatement); if (limit.isPresent()) { - SqlNode offset = limit.get().getOffset().flatMap(optional -> new PaginationValueSQLConverter().convert(optional)).orElse(null); - SqlNode rowCount = limit.get().getRowCount().flatMap(optional -> new PaginationValueSQLConverter().convert(optional)).orElse(null); + SqlNode offset = limit.get().getOffset().flatMap(PaginationValueSQLConverter::convert).orElse(null); + SqlNode rowCount = limit.get().getRowCount().flatMap(PaginationValueSQLConverter::convert).orElse(null); return new SqlOrderBy(SqlParserPos.ZERO, sqlDelete, orderBy, offset, rowCount); } return orderBy.isEmpty() ? sqlDelete : new SqlOrderBy(SqlParserPos.ZERO, sqlDelete, orderBy, null, null); } private SqlNode convertDelete(final DeleteStatement deleteStatement) { - SqlNode deleteTable = new TableConverter().convert(deleteStatement.getTable()).orElseThrow(IllegalStateException::new); - SqlNode condition = deleteStatement.getWhere().flatMap(optional -> new WhereConverter().convert(optional)).orElse(null); + SqlNode deleteTable = TableConverter.convert(deleteStatement.getTable()).orElseThrow(IllegalStateException::new); + SqlNode condition = deleteStatement.getWhere().flatMap(WhereConverter::convert).orElse(null); SqlIdentifier alias = deleteStatement.getTable().getAliasName().map(optional -> new SqlIdentifier(optional, SqlParserPos.ZERO)).orElse(null); SqlDelete sqlDelete = new SqlDelete(SqlParserPos.ZERO, deleteTable, condition, null, alias); - return DeleteStatementHandler.getWithSegment(deleteStatement).flatMap(optional -> new WithConverter().convert(optional, sqlDelete)).orElse(sqlDelete); + return DeleteStatementHandler.getWithSegment(deleteStatement).flatMap(optional -> WithConverter.convert(optional, sqlDelete)).orElse(sqlDelete); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/insert/InsertStatementConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/insert/InsertStatementConverter.java index 842d360d3b005..86444eb7c96dd 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/insert/InsertStatementConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/insert/InsertStatementConverter.java @@ -51,7 +51,7 @@ public SqlNode convert(final InsertStatement insertStatement) { } private SqlInsert convertInsert(final InsertStatement insertStatement) { - SqlNode table = new TableConverter().convert(insertStatement.getTable()).orElseThrow(IllegalStateException::new); + SqlNode table = TableConverter.convert(insertStatement.getTable()).orElseThrow(IllegalStateException::new); SqlNodeList keywords = new SqlNodeList(SqlParserPos.ZERO); SqlNode source = convertSource(insertStatement); SqlNodeList columnList = convertColumn(insertStatement.getColumns()); @@ -78,11 +78,11 @@ private SqlNode convertValues(final Collection insertValues } private SqlNodeList convertColumn(final Collection columnSegments) { - List columns = columnSegments.stream().map(each -> new ColumnConverter().convert(each).orElseThrow(IllegalStateException::new)).collect(Collectors.toList()); + List columns = columnSegments.stream().map(each -> ColumnConverter.convert(each).orElseThrow(IllegalStateException::new)).collect(Collectors.toList()); return columns.isEmpty() ? null : new SqlNodeList(columns, SqlParserPos.ZERO); } private SqlNode convertExpression(final ExpressionSegment expressionSegment) { - return new ExpressionConverter().convert(expressionSegment).orElseThrow(IllegalStateException::new); + return ExpressionConverter.convert(expressionSegment).orElseThrow(IllegalStateException::new); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/merge/MergeStatementConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/merge/MergeStatementConverter.java index 32c08702481d8..91aa2fadcc658 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/merge/MergeStatementConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/merge/MergeStatementConverter.java @@ -43,9 +43,9 @@ public final class MergeStatementConverter implements SQLStatementConverter new WhereConverter().convert(optional)).orElse(null); + SqlNode table = TableConverter.convert(updateStatement.getTable()).orElse(SqlNodeList.EMPTY); + SqlNode condition = updateStatement.getWhere().flatMap(WhereConverter::convert).orElse(null); SqlNodeList columns = new SqlNodeList(SqlParserPos.ZERO); SqlNodeList expressions = new SqlNodeList(SqlParserPos.ZERO); for (AssignmentSegment each : updateStatement.getAssignmentSegment().orElseThrow(IllegalStateException::new).getAssignments()) { @@ -66,10 +66,10 @@ private SqlUpdate convertUpdate(final UpdateStatement updateStatement) { } private List convertColumn(final List columnSegments) { - return columnSegments.stream().map(each -> new ColumnConverter().convert(each).orElseThrow(IllegalStateException::new)).collect(Collectors.toList()); + return columnSegments.stream().map(each -> ColumnConverter.convert(each).orElseThrow(IllegalStateException::new)).collect(Collectors.toList()); } private SqlNode convertExpression(final ExpressionSegment expressionSegment) { - return new ExpressionConverter().convert(expressionSegment).orElseThrow(IllegalStateException::new); + return ExpressionConverter.convert(expressionSegment).orElseThrow(IllegalStateException::new); } } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/select/SelectStatementConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/select/SelectStatementConverter.java index 148d517cef25e..a96dc7428e83f 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/select/SelectStatementConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/select/SelectStatementConverter.java @@ -51,24 +51,24 @@ public final class SelectStatementConverter implements SQLStatementConverter new OrderByConverter().convert(optional)).orElse(SqlNodeList.EMPTY); + SqlNodeList orderBy = selectStatement.getOrderBy().flatMap(OrderByConverter::convert).orElse(SqlNodeList.EMPTY); Optional limit = SelectStatementHandler.getLimitSegment(selectStatement); if (limit.isPresent()) { - SqlNode offset = limit.get().getOffset().flatMap(optional -> new PaginationValueSQLConverter().convert(optional)).orElse(null); - SqlNode rowCount = limit.get().getRowCount().flatMap(optional -> new PaginationValueSQLConverter().convert(optional)).orElse(null); + SqlNode offset = limit.get().getOffset().flatMap(PaginationValueSQLConverter::convert).orElse(null); + SqlNode rowCount = limit.get().getRowCount().flatMap(PaginationValueSQLConverter::convert).orElse(null); return new SqlOrderBy(SqlParserPos.ZERO, sqlCombine, orderBy, offset, rowCount); } return orderBy.isEmpty() ? sqlCombine : new SqlOrderBy(SqlParserPos.ZERO, sqlCombine, orderBy, null, null); } private SqlSelect convertSelect(final SelectStatement selectStatement) { - SqlNodeList distinct = new DistinctConverter().convert(selectStatement.getProjections()).orElse(null); - SqlNodeList projection = new ProjectionsConverter().convert(selectStatement.getProjections()).orElseThrow(IllegalStateException::new); - SqlNode from = new TableConverter().convert(selectStatement.getFrom()).orElse(null); - SqlNode where = selectStatement.getWhere().flatMap(optional -> new WhereConverter().convert(optional)).orElse(null); - SqlNodeList groupBy = selectStatement.getGroupBy().flatMap(optional -> new GroupByConverter().convert(optional)).orElse(null); - SqlNode having = selectStatement.getHaving().flatMap(optional -> new HavingConverter().convert(optional)).orElse(null); - SqlNodeList window = SelectStatementHandler.getWindowSegment(selectStatement).flatMap(new WindowConverter()::convert).orElse(SqlNodeList.EMPTY); + SqlNodeList distinct = DistinctConverter.convert(selectStatement.getProjections()).orElse(null); + SqlNodeList projection = ProjectionsConverter.convert(selectStatement.getProjections()).orElseThrow(IllegalStateException::new); + SqlNode from = TableConverter.convert(selectStatement.getFrom()).orElse(null); + SqlNode where = selectStatement.getWhere().flatMap(WhereConverter::convert).orElse(null); + SqlNodeList groupBy = selectStatement.getGroupBy().flatMap(GroupByConverter::convert).orElse(null); + SqlNode having = selectStatement.getHaving().flatMap(HavingConverter::convert).orElse(null); + SqlNodeList window = SelectStatementHandler.getWindowSegment(selectStatement).flatMap(WindowConverter::convert).orElse(SqlNodeList.EMPTY); return new SqlSelect(SqlParserPos.ZERO, distinct, projection, from, where, groupBy, having, window, null, null, null, null, SqlNodeList.EMPTY); } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/update/UpdateStatementConverter.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/update/UpdateStatementConverter.java index 675c03d051412..479beaf6bdfe3 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/update/UpdateStatementConverter.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/converter/statement/update/UpdateStatementConverter.java @@ -48,19 +48,19 @@ public final class UpdateStatementConverter implements SQLStatementConverter new OrderByConverter().convert(optional)).orElse(SqlNodeList.EMPTY); + SqlNodeList orderBy = UpdateStatementHandler.getOrderBySegment(updateStatement).flatMap(OrderByConverter::convert).orElse(SqlNodeList.EMPTY); Optional limit = UpdateStatementHandler.getLimitSegment(updateStatement); if (limit.isPresent()) { - SqlNode offset = limit.get().getOffset().flatMap(optional -> new PaginationValueSQLConverter().convert(optional)).orElse(null); - SqlNode rowCount = limit.get().getRowCount().flatMap(optional -> new PaginationValueSQLConverter().convert(optional)).orElse(null); + SqlNode offset = limit.get().getOffset().flatMap(PaginationValueSQLConverter::convert).orElse(null); + SqlNode rowCount = limit.get().getRowCount().flatMap(PaginationValueSQLConverter::convert).orElse(null); return new SqlOrderBy(SqlParserPos.ZERO, sqlUpdate, orderBy, offset, rowCount); } return orderBy.isEmpty() ? sqlUpdate : new SqlOrderBy(SqlParserPos.ZERO, sqlUpdate, orderBy, null, null); } private SqlUpdate convertUpdate(final UpdateStatement updateStatement) { - SqlNode table = new TableConverter().convert(updateStatement.getTable()).orElseThrow(IllegalStateException::new); - SqlNode condition = updateStatement.getWhere().flatMap(optional -> new WhereConverter().convert(optional)).orElse(null); + SqlNode table = TableConverter.convert(updateStatement.getTable()).orElseThrow(IllegalStateException::new); + SqlNode condition = updateStatement.getWhere().flatMap(WhereConverter::convert).orElse(null); SqlNodeList columns = new SqlNodeList(SqlParserPos.ZERO); SqlNodeList expressions = new SqlNodeList(SqlParserPos.ZERO); for (AssignmentSegment each : updateStatement.getAssignmentSegment().orElseThrow(IllegalStateException::new).getAssignments()) { @@ -71,10 +71,10 @@ private SqlUpdate convertUpdate(final UpdateStatement updateStatement) { } private List convertColumn(final List columnSegments) { - return columnSegments.stream().map(each -> new ColumnConverter().convert(each).orElseThrow(IllegalStateException::new)).collect(Collectors.toList()); + return columnSegments.stream().map(each -> ColumnConverter.convert(each).orElseThrow(IllegalStateException::new)).collect(Collectors.toList()); } private SqlNode convertExpression(final ExpressionSegment expressionSegment) { - return new ExpressionConverter().convert(expressionSegment).orElseThrow(IllegalStateException::new); + return ExpressionConverter.convert(expressionSegment).orElseThrow(IllegalStateException::new); } }