Skip to content

Commit

Permalink
Extract ShowCreateUserStatement to reduce duplicate logic for MySQL a…
Browse files Browse the repository at this point in the history
…nd doris
  • Loading branch information
strongduanmu committed Jun 19, 2024
1 parent a74a51a commit 8026319
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 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;

/**
* Show create user statement.
*/
@Getter
@Setter
public abstract class ShowCreateUserStatement extends AbstractSQLStatement implements DALStatement {

private String name;
}
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.ShowCreateUserStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.DorisStatement;

/**
* Doris show create user statement.
*/
@Getter
@Setter
public final class DorisShowCreateUserStatement extends AbstractSQLStatement implements DALStatement, DorisStatement {

private String name;
public final class DorisShowCreateUserStatement extends ShowCreateUserStatement 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.ShowCreateUserStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;

/**
* MySQL show create user statement.
*/
@Getter
@Setter
public final class MySQLShowCreateUserStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {

private String name;
public final class MySQLShowCreateUserStatement extends ShowCreateUserStatement implements MySQLStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowColumnsStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowCreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowCreateTriggerStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowCreateUserStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLFlushStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateUserStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowEventsStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowFunctionStatusStatement;
Expand Down Expand Up @@ -212,8 +212,8 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final DALS
ShowCreateTableStatementAssert.assertIs(assertContext, (ShowCreateTableStatement) actual, (ShowCreateTableStatementTestCase) expected);
} else if (actual instanceof ShowCreateTriggerStatement) {
ShowCreateTriggerStatementAssert.assertIs(assertContext, (ShowCreateTriggerStatement) actual, (ShowCreateTriggerStatementTestCase) expected);
} else if (actual instanceof MySQLShowCreateUserStatement) {
ShowCreateUserStatementAssert.assertIs(assertContext, (MySQLShowCreateUserStatement) actual, (ShowCreateUserStatementTestCase) expected);
} else if (actual instanceof ShowCreateUserStatement) {
ShowCreateUserStatementAssert.assertIs(assertContext, (ShowCreateUserStatement) actual, (ShowCreateUserStatementTestCase) expected);
} else if (actual instanceof MySQLShowTableStatusStatement) {
ShowTableStatusStatementAssert.assertIs(assertContext, (MySQLShowTableStatusStatement) actual, (ShowTableStatusStatementTestCase) expected);
} else if (actual instanceof MySQLShowIndexStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateUserStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowCreateUserStatement;
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.ShowCreateUserStatementTestCase;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Show create user statement assert.
Expand All @@ -40,8 +40,8 @@ public final class ShowCreateUserStatementAssert {
* @param actual actual show create user statement
* @param expected expected show create user statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final MySQLShowCreateUserStatement actual, final ShowCreateUserStatementTestCase expected) {
assertNotNull(expected.getUser(), "expected show create user should be not null");
assertThat(actual.getName(), is(expected.getUser().getName()));
public static void assertIs(final SQLCaseAssertContext assertContext, final ShowCreateUserStatement actual, final ShowCreateUserStatementTestCase expected) {
assertNotNull(expected.getUser(), assertContext.getText("expected show create user should be not null"));
assertThat(assertContext.getText("user name does not match: "), actual.getName(), is(expected.getUser().getName()));
}
}

0 comments on commit 8026319

Please sign in to comment.