Skip to content

Commit

Permalink
Optimize empty filter when use splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
RaigorJiang committed Oct 27, 2023
1 parent e038a06 commit f25f4ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
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 @@ -39,7 +39,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(String each) {
Assertions.assertNotNull(sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL")).parse(each, false));
}

@SneakyThrows(IOException.class)
Expand Down

0 comments on commit f25f4ff

Please sign in to comment.