Skip to content

Commit

Permalink
Refactor package of sql extension operator table (#28815)
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu authored Oct 20, 2023
1 parent b788fb9 commit 3a97b5e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
* limitations under the License.
*/

package org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql;
package org.apache.shardingsphere.sqlfederation.optimizer.converter.operator.common;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.calcite.sql.SqlBinaryOperator;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlPrefixOperator;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.operator.dialect.mysql.MySQLMatchAgainstOperator;

/**
* SQL extension operator table.
Expand Down Expand Up @@ -53,11 +54,11 @@ public final class SQLExtensionOperatorTable {

public static final SqlBinaryOperator SOUNDS_LIKE = new SqlBinaryOperator("SOUNDS LIKE", SqlKind.OTHER, 30, true, null, null, null);

public static final MySQLMatchAgainstFunction MATCH_AGAINST = new MySQLMatchAgainstFunction();

public static final SqlBinaryOperator COLLATE = new SqlBinaryOperator("COLLATE", SqlKind.OTHER, 30, true, null, null, null);

public static final SqlBinaryOperator ASSIGNMENT = new SqlBinaryOperator(":=", SqlKind.OTHER, 30, true, null, null, null);

public static final SqlPrefixOperator TILDE = new SqlPrefixOperator("~", SqlKind.OTHER, 26, null, null, null);

public static final MySQLMatchAgainstOperator MATCH_AGAINST = new MySQLMatchAgainstOperator();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.sqlfederation.optimizer.converter.function.dialect.mysql;
package org.apache.shardingsphere.sqlfederation.optimizer.converter.operator.dialect.mysql;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlFunction;
Expand All @@ -38,13 +38,13 @@
import java.util.List;

/**
* MySQL match against function.
* MySQL match against operator.
*/
public final class MySQLMatchAgainstFunction extends SqlFunction {
public final class MySQLMatchAgainstOperator extends SqlFunction {

private static final FrameType FRAME_TYPE = FrameTypeEnum.create("MATCH");

public MySQLMatchAgainstFunction() {
public MySQLMatchAgainstOperator() {
super("MATCH_AGAINST", SqlKind.OTHER_FUNCTION, ReturnTypes.DOUBLE, InferTypes.FIRST_KNOWN, OperandTypes.ANY, SqlFunctionCategory.STRING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.commons.collections4.map.CaseInsensitiveMap;
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.operator.common.SQLExtensionOperatorTable;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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.operator.common.SQLExtensionOperatorTable;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter;

import java.util.LinkedList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.shardingsphere.sql.parser.sql.dialect.segment.mysql.match.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.operator.common.SQLExtensionOperatorTable;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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.operator.common.SQLExtensionOperatorTable;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter;

import java.util.LinkedList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.calcite.sql.parser.SqlParserPos;
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.operator.common.SQLExtensionOperatorTable;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.expression.ExpressionConverter;

import java.util.LinkedList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class MergeStatementConverter implements SQLStatementConverter<Merg
@Override
public SqlNode convert(final MergeStatement mergeStatement) {
SqlNode targetTable = TableConverter.convert(mergeStatement.getTarget()).orElseThrow(IllegalStateException::new);
SqlNode condition = ExpressionConverter.convert(mergeStatement.getExpression().getExpr()).get();
SqlNode condition = ExpressionConverter.convert(mergeStatement.getExpression().getExpr()).orElseThrow(IllegalStateException::new);
SqlNode sourceTable = TableConverter.convert(mergeStatement.getSource()).orElseThrow(IllegalStateException::new);
SqlUpdate sqlUpdate = null;
if (null != mergeStatement.getUpdate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
<test-cases sql-case-id="select_natural_right_join" expected-sql="SELECT * FROM &quot;t_order&quot; AS &quot;o&quot; NATURAL RIGHT JOIN &quot;t_order_item&quot; AS &quot;i&quot; WHERE &quot;o&quot;.&quot;order_id&quot; = ?" db-types="PostgreSQL,openGauss" sql-case-types="PLACEHOLDER" />
<test-cases sql-case-id="select_natural_full_join" expected-sql="SELECT * FROM &quot;t_order&quot; AS &quot;o&quot; NATURAL FULL JOIN &quot;t_order_item&quot; AS &quot;i&quot; WHERE &quot;o&quot;.&quot;order_id&quot; = 1" db-types="PostgreSQL,openGauss" sql-case-types="LITERAL" />
<test-cases sql-case-id="select_natural_full_join" expected-sql="SELECT * FROM &quot;t_order&quot; AS &quot;o&quot; NATURAL FULL JOIN &quot;t_order_item&quot; AS &quot;i&quot; WHERE &quot;o&quot;.&quot;order_id&quot; = ?" db-types="PostgreSQL,openGauss" sql-case-types="PLACEHOLDER" />
<test-cases sql-case-id="select_with_join_operator" expected-sql="SELECT * FROM t_order o , t_order_item i WHERE o.order_id(+) = i.order_id" db-types="Oracle" />
<!-- FIXME support this case when calcite support oracle outer join -->
<!--<test-cases sql-case-id="select_with_join_operator" expected-sql="SELECT * FROM t_order o , t_order_item i WHERE o.order_id(+) = i.order_id" db-types="Oracle" />-->
</sql-node-converter-test-cases>

0 comments on commit 3a97b5e

Please sign in to comment.