Skip to content

Commit

Permalink
Extract DelimiterStatement to reduce duplicate logic for MySQL and doris
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu committed Jun 19, 2024
1 parent ceff4b1 commit d769df4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.sql.parser.sql.common.statement.dal;

import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;

/**
* Delimiter statement.
*/
@Getter
@Setter
public abstract class DelimiterStatement extends AbstractSQLStatement implements DALStatement {

private String delimiterName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@

package org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.dal;

import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DelimiterStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.DorisStatement;

/**
* Doris delimiter statement.
*/
@Getter
@Setter
public final class DorisDelimiterStatement extends AbstractSQLStatement implements DALStatement, DorisStatement {

private String delimiterName;
public final class DorisDelimiterStatement extends DelimiterStatement implements DorisStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@

package org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal;

import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DelimiterStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;

/**
* MySQL delimiter statement.
*/
@Getter
@Setter
public final class MySQLDelimiterStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {

private String delimiterName;
public final class MySQLDelimiterStatement extends DelimiterStatement implements MySQLStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.CloneStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.CreateResourceGroupStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DelimiterStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.EmptyStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ResetParameterStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLDelimiterStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLDropResourceGroupStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLFlushStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLInstallComponentStatement;
Expand Down Expand Up @@ -81,6 +81,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.ChecksumTableStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.CloneStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.CreateResourceGroupStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.DelimiterStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.EmptyStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.ExplainStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.FlushStatementAssert;
Expand Down Expand Up @@ -119,7 +120,6 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.SpoolStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.UninstallComponentStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.UninstallPluginStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.mysql.MySQLDelimiterStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.mysql.MySQLDropResourceGroupStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.mysql.MySQLOptimizeTableStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.mysql.MySQLRepairTableStatementAssert;
Expand Down Expand Up @@ -296,8 +296,8 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final DALS
ShowCollationStatementAssert.assertIs(assertContext, (MySQLShowCollationStatement) actual, (ShowCollationStatementTestCase) expected);
} else if (actual instanceof MySQLShowVariablesStatement) {
ShowVariablesStatementAssert.assertIs(assertContext, (MySQLShowVariablesStatement) actual, (ShowVariablesStatementTestCase) expected);
} else if (actual instanceof MySQLDelimiterStatement) {
MySQLDelimiterStatementAssert.assertIs(assertContext, (MySQLDelimiterStatement) actual, (DelimiterStatementTestCase) expected);
} else if (actual instanceof DelimiterStatement) {
DelimiterStatementAssert.assertIs(assertContext, (DelimiterStatement) actual, (DelimiterStatementTestCase) expected);
} else if (actual instanceof MySQLShowBinlogEventsStatement) {
ShowBinlogEventsStatementAssert.assertIs(assertContext, (MySQLShowBinlogEventsStatement) actual, (ShowBinlogEventsStatementTestCase) expected);
} else if (actual instanceof OracleSpoolStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
* limitations under the License.
*/

package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl.mysql;
package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.impl;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLDelimiterStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DelimiterStatement;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.DelimiterStatementTestCase;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

/**
* delimiter statement assert.
* Delimiter statement assert.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MySQLDelimiterStatementAssert {
public final class DelimiterStatementAssert {

/**
* Assert delimiter index statement is correct with expected parser result.
Expand All @@ -39,7 +39,7 @@ public final class MySQLDelimiterStatementAssert {
* @param actual actual delimiter statement
* @param expected expected delimiter statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final MySQLDelimiterStatement actual, final DelimiterStatementTestCase expected) {
public static void assertIs(final SQLCaseAssertContext assertContext, final DelimiterStatement actual, final DelimiterStatementTestCase expected) {
assertThat(assertContext.getText("delimiter name assertion error: "), actual.getDelimiterName(), is(expected.getDelimiterName()));
}
}

0 comments on commit d769df4

Please sign in to comment.