Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix empty sql in SQL E2E #28877

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.stream.Collectors;

/**
* Result set for show sharding table nodes.
* Show sharding table nodes executor.
*/
public final class ShowShardingTableNodesExecutor implements RQLExecutor<ShowShardingTableNodesStatement> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public interface RQLExecutor<T extends RQLStatement> extends TypedSPI {
/**
* Get query result rows.
*
* @param shardingSphereDatabase ShardingSphere database
* @param database database
* @param sqlStatement SQL statement
* @return query result rows
*/
Collection<LocalDataQueryResultRow> getRows(ShardingSphereDatabase shardingSphereDatabase, T sqlStatement);
Collection<LocalDataQueryResultRow> getRows(ShardingSphereDatabase database, T sqlStatement);

@Override
Class<T> getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.common.base.Splitter;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.shaded.com.google.common.base.Strings;
import org.apache.shardingsphere.data.pipeline.common.config.CreateTableConfiguration.CreateTableEntry;
import org.apache.shardingsphere.data.pipeline.common.datasource.PipelineDataSourceManager;
import org.apache.shardingsphere.data.pipeline.core.preparer.datasource.AbstractDataSourcePreparer;
Expand All @@ -28,7 +27,6 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.util.stream.Collectors;

/**
* Data source preparer for openGauss.
Expand All @@ -55,7 +53,7 @@ public void prepareTargetTables(final PrepareTargetTablesParameter param) throws
for (CreateTableEntry each : param.getCreateTableConfig().getCreateTableEntries()) {
String createTargetTableSQL = getCreateTargetTableSQL(each, dataSourceManager, param.getSqlParserEngine());
try (Connection targetConnection = getCachedDataSource(dataSourceManager, each.getTargetDataSourceConfig()).getConnection()) {
for (String sql : Splitter.on(";").trimResults().splitToList(createTargetTableSQL).stream().filter(cs -> !Strings.isNullOrEmpty(cs)).collect(Collectors.toList())) {
for (String sql : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(createTargetTableSQL)) {
executeTargetTableSQL(targetConnection, addIfNotExistsForCreateTableSQL(sql));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
package org.apache.shardingsphere.data.pipeline.postgresql.prepare.datasource;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import org.apache.shardingsphere.data.pipeline.common.config.CreateTableConfiguration.CreateTableEntry;
import org.apache.shardingsphere.data.pipeline.common.datasource.PipelineDataSourceManager;
import org.apache.shardingsphere.data.pipeline.core.preparer.datasource.AbstractDataSourcePreparer;
import org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.stream.Collectors;

/**
* Data source preparer for PostgreSQL.
Expand All @@ -39,7 +37,7 @@ public void prepareTargetTables(final PrepareTargetTablesParameter param) throws
for (CreateTableEntry each : param.getCreateTableConfig().getCreateTableEntries()) {
String createTargetTableSQL = getCreateTargetTableSQL(each, dataSourceManager, param.getSqlParserEngine());
try (Connection targetConnection = getCachedDataSource(dataSourceManager, each.getTargetDataSourceConfig()).getConnection()) {
for (String sql : Splitter.on(";").trimResults().splitToList(createTargetTableSQL).stream().filter(cs -> !Strings.isNullOrEmpty(cs)).collect(Collectors.toList())) {
for (String sql : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(createTargetTableSQL)) {
executeTargetTableSQL(targetConnection, sql);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
import org.apache.shardingsphere.distsql.statement.ral.queryable.ConvertYamlConfigurationStatement;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
Expand All @@ -37,7 +37,6 @@

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

class ConvertYamlConfigurationExecutorTest {

Expand Down Expand Up @@ -97,11 +96,11 @@ private void assertRowData(final Collection<LocalDataQueryResultRow> data, final
}

private void assertParseSQL(final String actual) {
Splitter.on(";").trimResults().splitToList(actual).forEach(each -> {
if (!Strings.isNullOrEmpty(each)) {
assertNotNull(sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL")).parse(each, false));
}
});
Splitter.on(";").trimResults().omitEmptyStrings().splitToList(actual).forEach(this::assertNotNull);
}

private void assertNotNull(final String sql) {
Assertions.assertNotNull(sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL")).parse(sql, false));
}

@SneakyThrows(IOException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void executeInitSQLs(final SingleE2EContainerComposer containerComposer,
if (null == containerComposer.getAssertion().getInitialSQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) {
for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) {
try (PreparedStatement preparedStatement = connection.prepareStatement(each)) {
preparedStatement.executeUpdate();
}
Expand All @@ -159,7 +159,7 @@ private void executeDestroySQLs(final SingleE2EContainerComposer containerCompos
if (null == containerComposer.getAssertion().getDestroySQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) {
for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) {
try (PreparedStatement preparedStatement = connection.prepareStatement(each)) {
preparedStatement.executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void executeInitSQLs(final SingleE2EContainerComposer containerComposer,
if (null == containerComposer.getAssertion().getInitialSQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) {
for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) {
try (PreparedStatement preparedStatement = connection.prepareStatement(each)) {
preparedStatement.executeUpdate();
}
Expand All @@ -105,7 +105,7 @@ private void executeDestroySQLs(final SingleE2EContainerComposer containerCompos
if (null == containerComposer.getAssertion().getDestroySQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) {
for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) {
try (PreparedStatement preparedStatement = connection.prepareStatement(each)) {
preparedStatement.executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void executeInitSQLs(final SingleE2EContainerComposer containerComposer,
if (null == containerComposer.getAssertion().getInitialSQL() || null == containerComposer.getAssertion().getInitialSQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) {
for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) {
try (PreparedStatement preparedStatement = connection.prepareStatement(each)) {
preparedStatement.executeUpdate();
Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true);
Expand All @@ -111,7 +111,7 @@ private void executeDestroySQLs(final SingleE2EContainerComposer containerCompos
if (null == containerComposer.getAssertion().getDestroySQL().getSql()) {
return;
}
for (String each : Splitter.on(";").trimResults().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) {
for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) {
try (PreparedStatement preparedStatement = connection.prepareStatement(each)) {
preparedStatement.executeUpdate();
Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true);
Expand Down