未验证 提交 461c1c74 编写于 作者: L Liang Zhang 提交者: GitHub

generic sharding for optimized module (#3110)

* move sharding segment to common segment

* remove sharding package

* rename org.apache.shardingsphere.core.optimize.api to org.apache.shardingsphere.core.optimize

* move XXXOptimizedStatement to impl package

* refactor groupby and orderby

* remove useless resources

* refactor OptimizedStatement

* refactor SelectOptimizedStatement.containsSubquery()

* add test case for SelectOptimizedStatement.isSameGroupByAndOrderByItems()

* remove SelectItems.tableMetas

* remove SelectItems.tables

* move XXXSelectItem to impl package

* move Column to route module

* refactor package name of segment

* add todo
上级 23610f4e
......@@ -22,7 +22,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.api.hint.HintManager;
import org.apache.shardingsphere.core.constant.properties.ShardingProperties;
import org.apache.shardingsphere.core.constant.properties.ShardingPropertiesConstant;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.core.route.RouteUnit;
import org.apache.shardingsphere.core.route.SQLRouteResult;
......
......@@ -19,8 +19,8 @@ package org.apache.shardingsphere.core.execute.sql.execute.result;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import java.util.Collection;
......
......@@ -21,7 +21,7 @@ import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.core.execute.sql.execute.row.QueryRow;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import java.io.InputStream;
......
......@@ -20,8 +20,8 @@ package org.apache.shardingsphere.core.execute.sql.execute.result;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.junit.Before;
import org.junit.Test;
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.core.execute.sql.execute.result;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.junit.Before;
import org.junit.Test;
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.dal.DALMergeEngine;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.rule.ShardingRule;
......@@ -55,7 +55,7 @@ public final class MergeEngineFactory {
public static MergeEngine newInstance(final DatabaseType databaseType, final ShardingRule shardingRule,
final SQLRouteResult routeResult, final TableMetas tableMetas, final List<QueryResult> queryResults) throws SQLException {
if (routeResult.getShardingStatement() instanceof SelectOptimizedStatement) {
return new DQLMergeEngine(databaseType, routeResult, queryResults);
return new DQLMergeEngine(databaseType, tableMetas, routeResult, queryResults);
}
if (routeResult.getShardingStatement().getSqlStatement() instanceof DALStatement) {
return new DALMergeEngine(shardingRule, queryResults, routeResult.getShardingStatement(), tableMetas);
......
......@@ -29,7 +29,7 @@ import org.apache.shardingsphere.core.merge.dal.show.ShowOtherMergedResult;
import org.apache.shardingsphere.core.merge.dal.show.ShowTableStatusMergedResult;
import org.apache.shardingsphere.core.merge.dal.show.ShowTablesMergedResult;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.dialect.mysql.DescribeStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.dialect.mysql.ShowCreateTableStatement;
......
......@@ -21,7 +21,7 @@ import com.google.common.base.Optional;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.dql.common.MemoryMergedResult;
import org.apache.shardingsphere.core.merge.dql.common.MemoryQueryResultRow;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.core.strategy.encrypt.EncryptTable;
......
......@@ -33,9 +33,10 @@ import org.apache.shardingsphere.core.merge.dql.orderby.OrderByStreamMergedResul
import org.apache.shardingsphere.core.merge.dql.pagination.LimitDecoratorMergedResult;
import org.apache.shardingsphere.core.merge.dql.pagination.RowNumberDecoratorMergedResult;
import org.apache.shardingsphere.core.merge.dql.pagination.TopAndRowNumberDecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.util.SQLUtil;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.spi.database.DatabaseType;
......@@ -64,15 +65,15 @@ public final class DQLMergeEngine implements MergeEngine {
@Getter
private final Map<String, Integer> columnLabelIndexMap;
public DQLMergeEngine(final DatabaseType databaseType, final SQLRouteResult routeResult, final List<QueryResult> queryResults) throws SQLException {
public DQLMergeEngine(final DatabaseType databaseType, final TableMetas tableMetas, final SQLRouteResult routeResult, final List<QueryResult> queryResults) throws SQLException {
this.databaseType = databaseType;
this.routeResult = routeResult;
this.shardingStatement = (SelectOptimizedStatement) routeResult.getShardingStatement();
this.queryResults = getRealQueryResults(queryResults);
this.queryResults = getRealQueryResults(tableMetas, queryResults);
columnLabelIndexMap = getColumnLabelIndexMap(this.queryResults.get(0));
}
private List<QueryResult> getRealQueryResults(final List<QueryResult> queryResults) throws SQLException {
private List<QueryResult> getRealQueryResults(final TableMetas tableMetas, final List<QueryResult> queryResults) throws SQLException {
List<QueryResult> result = queryResults;
if (1 == result.size()) {
return result;
......@@ -82,7 +83,7 @@ public final class DQLMergeEngine implements MergeEngine {
result = getDividedQueryResults(new AggregationDistinctQueryResult(queryResults, aggregationDistinctSelectItems));
}
if (isDistinctRowSelectItems()) {
result = getDividedQueryResults(new DistinctQueryResult(queryResults, shardingStatement.getSelectItems().getColumnLabels()));
result = getDividedQueryResults(new DistinctQueryResult(queryResults, shardingStatement.getColumnLabels(tableMetas)));
}
return result.isEmpty() ? queryResults : result;
}
......
......@@ -26,8 +26,8 @@ import org.apache.shardingsphere.core.merge.dql.common.MemoryMergedResult;
import org.apache.shardingsphere.core.merge.dql.common.MemoryQueryResultRow;
import org.apache.shardingsphere.core.merge.dql.groupby.aggregation.AggregationUnit;
import org.apache.shardingsphere.core.merge.dql.groupby.aggregation.AggregationUnitFactory;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
......
......@@ -21,8 +21,8 @@ import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.merge.dql.common.MemoryQueryResultRow;
import org.apache.shardingsphere.core.merge.dql.orderby.CompareUtil;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import java.util.Collection;
import java.util.Comparator;
......
......@@ -24,8 +24,8 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.dql.groupby.aggregation.AggregationUnit;
import org.apache.shardingsphere.core.merge.dql.groupby.aggregation.AggregationUnitFactory;
import org.apache.shardingsphere.core.merge.dql.orderby.OrderByStreamMergedResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.merge.dql.groupby;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import java.sql.SQLException;
import java.util.ArrayList;
......
......@@ -21,7 +21,7 @@ import lombok.AccessLevel;
import lombok.Getter;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.dql.common.StreamMergedResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import java.sql.SQLException;
import java.util.Collection;
......
......@@ -21,7 +21,7 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import java.sql.SQLException;
import java.util.ArrayList;
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.merge.dql.pagination;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.common.DecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import java.sql.SQLException;
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.merge.dql.pagination;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.common.DecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import java.sql.SQLException;
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.merge.dql.pagination;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.common.DecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import java.sql.SQLException;
......
......@@ -23,15 +23,15 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.dal.DALMergeEngine;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement;
......@@ -76,7 +76,7 @@ public final class MergeEngineFactoryTest {
SQLRouteResult routeResult = new SQLRouteResult(
new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList())),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList())),
new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
assertThat(MergeEngineFactory.newInstance(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, null, queryResults), instanceOf(DQLMergeEngine.class));
}
......
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.merge.dal.show.ShowDatabasesMergedResult;
import org.apache.shardingsphere.core.merge.dal.show.ShowOtherMergedResult;
import org.apache.shardingsphere.core.merge.dal.show.ShowTablesMergedResult;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.dialect.mysql.DescribeStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dal.dialect.mysql.ShowCreateTableStatement;
......
......@@ -21,8 +21,8 @@ import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.fixture.DescribeQueryResultFixture;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.Tables;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.rule.EncryptRule;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.core.strategy.encrypt.EncryptTable;
......
......@@ -23,20 +23,19 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -87,7 +86,7 @@ public final class GroupByMemoryMergedResultTest {
AggregationSelectItem derivedAggregationSelectItem2 = new AggregationSelectItem(AggregationType.SUM, "(num)", "AVG_DERIVED_SUM_0");
aggregationSelectItem2.setIndex(5);
aggregationSelectItem2.getDerivedAggregationItems().add(derivedAggregationSelectItem2);
SelectItems selectItems = new SelectItems(0, 0, false, Arrays.<SelectItem>asList(aggregationSelectItem1, aggregationSelectItem2), Collections.<TableSegment>emptyList(), null);
SelectItems selectItems = new SelectItems(0, 0, false, Arrays.<SelectItem>asList(aggregationSelectItem1, aggregationSelectItem2));
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.singletonList(createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))), 0),
new OrderBy(Collections.singletonList(createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))), false),
......@@ -116,14 +115,14 @@ public final class GroupByMemoryMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
@Test
public void assertNextForSomeResultSetsEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
when(resultSets.get(0).next()).thenReturn(true, false);
when(resultSets.get(0).getObject(1)).thenReturn(20);
when(resultSets.get(0).getObject(2)).thenReturn(0);
......
......@@ -21,16 +21,15 @@ import com.google.common.collect.Lists;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.dql.common.MemoryQueryResultRow;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.junit.Test;
......@@ -60,7 +59,7 @@ public final class GroupByRowComparatorTest {
new OrderBy(Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(optimizedStatement, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
......@@ -76,7 +75,7 @@ public final class GroupByRowComparatorTest {
new OrderBy(Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(optimizedStatement, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
......@@ -92,7 +91,7 @@ public final class GroupByRowComparatorTest {
new OrderBy(Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(optimizedStatement, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
......@@ -105,7 +104,7 @@ public final class GroupByRowComparatorTest {
new GroupBy(Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(optimizedStatement, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
......@@ -118,7 +117,7 @@ public final class GroupByRowComparatorTest {
new GroupBy(Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(optimizedStatement, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
......@@ -131,7 +130,7 @@ public final class GroupByRowComparatorTest {
new GroupBy(Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(optimizedStatement, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
......
......@@ -23,20 +23,19 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -89,7 +88,7 @@ public final class GroupByStreamMergedResultTest {
AggregationSelectItem derivedAggregationSelectItem2 = new AggregationSelectItem(AggregationType.SUM, "(num)", "AVG_DERIVED_SUM_0");
aggregationSelectItem2.setIndex(6);
aggregationSelectItem2.getDerivedAggregationItems().add(derivedAggregationSelectItem2);
SelectItems selectItems = new SelectItems(0, 0, false, Arrays.<SelectItem>asList(aggregationSelectItem1, aggregationSelectItem2), Collections.<TableSegment>emptyList(), null);
SelectItems selectItems = new SelectItems(0, 0, false, Arrays.<SelectItem>asList(aggregationSelectItem1, aggregationSelectItem2));
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.singletonList(new OrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))), 0),
new OrderBy(Collections.singletonList(new OrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))), false),
......@@ -113,14 +112,14 @@ public final class GroupByStreamMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
@Test
public void assertNextForSomeResultSetsEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
when(resultSets.get(0).next()).thenReturn(true, false);
when(resultSets.get(0).getObject(1)).thenReturn(20);
when(resultSets.get(0).getObject(2)).thenReturn(0);
......@@ -162,7 +161,7 @@ public final class GroupByStreamMergedResultTest {
@Test
public void assertNextForMix() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
when(resultSets.get(0).next()).thenReturn(true, false);
when(resultSets.get(0).getObject(1)).thenReturn(20);
when(resultSets.get(0).getObject(2)).thenReturn(0);
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.merge.dql.groupby;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.junit.Before;
......
......@@ -23,15 +23,14 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -66,13 +65,13 @@ public final class IteratorStreamMergedResultTest {
queryResults = Lists.<QueryResult>newArrayList(new TestQueryResult(resultSet), new TestQueryResult(mock(ResultSet.class)), new TestQueryResult(mock(ResultSet.class)));
routeResult = new SQLRouteResult(new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList())),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList())),
new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
}
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
......@@ -82,7 +81,7 @@ public final class IteratorStreamMergedResultTest {
for (QueryResult each : queryResults) {
when(each.next()).thenReturn(true, false);
}
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
......@@ -93,7 +92,7 @@ public final class IteratorStreamMergedResultTest {
@Test
public void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException {
when(queryResults.get(0).next()).thenReturn(true, false);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertFalse(actual.next());
......@@ -102,7 +101,7 @@ public final class IteratorStreamMergedResultTest {
@Test
public void assertNextForMiddleResultSetsNotEmpty() throws SQLException {
when(queryResults.get(1).next()).thenReturn(true, false);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertFalse(actual.next());
......@@ -111,7 +110,7 @@ public final class IteratorStreamMergedResultTest {
@Test
public void assertNextForLastResultSetsNotEmptyOnly() throws SQLException {
when(queryResults.get(2).next()).thenReturn(true, false);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertFalse(actual.next());
......@@ -125,7 +124,7 @@ public final class IteratorStreamMergedResultTest {
when(queryResults.get(1).next()).thenReturn(true, false);
when(queryResults.get(3).next()).thenReturn(true, false);
when(queryResults.get(5).next()).thenReturn(true, false);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
......
......@@ -23,18 +23,17 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -70,7 +69,7 @@ public final class OrderByStreamMergedResultTest {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0),
new OrderBy(Collections.singletonList(new OrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC))), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
routeResult = new SQLRouteResult(shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
}
......@@ -83,14 +82,14 @@ public final class OrderByStreamMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
@Test
public void assertNextForSomeResultSetsEmpty() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
when(queryResults.get(0).next()).thenReturn(true, false);
when(queryResults.get(0).getValue(1, Object.class)).thenReturn("2");
when(queryResults.get(2).next()).thenReturn(true, true, false);
......@@ -107,7 +106,7 @@ public final class OrderByStreamMergedResultTest {
@Test
public void assertNextForMix() throws SQLException {
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
when(queryResults.get(0).next()).thenReturn(true, false);
when(queryResults.get(0).getValue(1, Object.class)).thenReturn("2");
when(queryResults.get(1).next()).thenReturn(true, true, true, false);
......@@ -141,7 +140,7 @@ public final class OrderByStreamMergedResultTest {
when(queryResults.get(2).next()).thenReturn(true, false);
when(queryResults.get(2).isCaseSensitive(1)).thenReturn(true);
when(queryResults.get(2).getValue(1, Object.class)).thenReturn("A");
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class).toString(), is("A"));
......@@ -165,7 +164,7 @@ public final class OrderByStreamMergedResultTest {
when(queryResults.get(2).next()).thenReturn(true, false);
when(queryResults.get(2).isCaseSensitive(1)).thenReturn(false);
when(queryResults.get(2).getValue(1, Object.class)).thenReturn("A");
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class).toString(), is("a"));
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.merge.dql.orderby;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.junit.Before;
......
......@@ -23,17 +23,16 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -78,11 +77,11 @@ public final class LimitDecoratorMergedResultTest {
public void assertNextForSkipAll() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE), null, Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
......@@ -91,11 +90,11 @@ public final class LimitDecoratorMergedResultTest {
public void assertNextWithoutRowCount() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralLimitValueSegment(0, 0, 2), null, Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
for (int i = 0; i < 6; i++) {
assertTrue(actual.next());
......@@ -107,11 +106,11 @@ public final class LimitDecoratorMergedResultTest {
public void assertNextWithRowCount() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralLimitValueSegment(0, 0, 2), new NumberLiteralLimitValueSegment(0, 0, 2), Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("MySQL"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
......
......@@ -23,17 +23,16 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -78,11 +77,11 @@ public final class RowNumberDecoratorMergedResultTest {
public void assertNextForSkipAll() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null, Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
......@@ -91,10 +90,10 @@ public final class RowNumberDecoratorMergedResultTest {
public void assertNextWithoutOffsetWithoutRowCount() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null), new Pagination(null, null, Collections.emptyList()));
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()), new Pagination(null, null, Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
for (int i = 0; i < 8; i++) {
assertTrue(actual.next());
......@@ -106,11 +105,11 @@ public final class RowNumberDecoratorMergedResultTest {
public void assertNextForRowCountBoundOpenedFalse() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralRowNumberValueSegment(0, 0, 4, false), Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
......@@ -121,11 +120,11 @@ public final class RowNumberDecoratorMergedResultTest {
public void assertNextForRowCountBoundOpenedTrue() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralRowNumberValueSegment(0, 0, 4, true), Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("Oracle"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
......
......@@ -23,18 +23,17 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine;
import org.apache.shardingsphere.core.merge.fixture.TestQueryResult;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingCondition;
......@@ -79,11 +78,11 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
public void assertNextForSkipAll() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null, Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertFalse(actual.next());
}
......@@ -92,11 +91,11 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
public void assertNextWithoutOffsetWithRowCount() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(null, new NumberLiteralLimitValueSegment(0, 0, 5), Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
for (int i = 0; i < 5; i++) {
assertTrue(actual.next());
......@@ -108,11 +107,11 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
public void assertNextWithOffsetWithoutRowCount() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, 2, true), null, Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
for (int i = 0; i < 7; i++) {
assertTrue(actual.next());
......@@ -124,26 +123,26 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
public void assertNextWithOffsetBoundOpenedFalse() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, 2, false), new NumberLiteralLimitValueSegment(0, 0, 4), Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
assertFalse(actual.next());
}
@Test
public void assertNextWithOffsetBoundOpenedTrue() throws SQLException {
OptimizedStatement shardingStatement = new SelectOptimizedStatement(new SelectStatement(),
new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), null),
new SelectItems(0, 0, false, Collections.<SelectItem>emptyList()),
new Pagination(new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4), Collections.emptyList()));
SQLRouteResult routeResult = new SQLRouteResult(
shardingStatement, new CommonOptimizedStatement(new SelectStatement()), new ShardingConditions(Collections.<ShardingCondition>emptyList()));
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), routeResult, queryResults);
mergeEngine = new DQLMergeEngine(DatabaseTypes.getActualDatabaseType("SQLServer"), null, routeResult, queryResults);
MergedResult actual = mergeEngine.merge();
assertTrue(actual.next());
assertTrue(actual.next());
......
......@@ -15,15 +15,15 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api;
package org.apache.shardingsphere.core.optimize;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.statement.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.engnie.ShardingSelectOptimizeEngine;
import org.apache.shardingsphere.core.optimize.statement.impl.CommonOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
......@@ -51,7 +51,7 @@ public final class OptimizedStatementFactory {
*/
public static OptimizedStatement newInstance(final TableMetas tableMetas, final String sql, final List<Object> parameters, final SQLStatement sqlStatement) {
if (sqlStatement instanceof SelectStatement) {
return new ShardingSelectOptimizeEngine().optimize(tableMetas, sql, parameters, (SelectStatement) sqlStatement);
return new SelectOptimizedStatement(tableMetas, sql, parameters, (SelectStatement) sqlStatement);
}
if (sqlStatement instanceof InsertStatement) {
return new InsertOptimizedStatement(tableMetas, parameters, (InsertStatement) sqlStatement);
......
/*
* 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.core.optimize.api.engine;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import java.util.List;
/**
* Optimize engine.
*
* @author maxiaoguang
* @author panjuan
*
* @param <T> type of SQL statement
*/
public interface OptimizeEngine<T extends SQLStatement> {
/**
* Optimize.
*
* @param tableMetas table metas
* @param sql SQL
* @param parameters SQL parameters
* @param sqlStatement SQL statement
* @return optimized statement
*/
OptimizedStatement optimize(TableMetas tableMetas, String sql, List<Object> parameters, T sqlStatement);
}
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment;
package org.apache.shardingsphere.core.optimize.segment;
import com.google.common.base.Optional;
import lombok.EqualsAndHashCode;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment;
package org.apache.shardingsphere.core.optimize.segment;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
......
......@@ -15,13 +15,13 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment;
package org.apache.shardingsphere.core.optimize.segment.insert;
import lombok.Getter;
import lombok.ToString;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.optimize.api.segment.expression.DerivedLiteralExpressionSegment;
import org.apache.shardingsphere.core.optimize.api.segment.expression.DerivedParameterMarkerExpressionSegment;
import org.apache.shardingsphere.core.optimize.segment.insert.expression.DerivedLiteralExpressionSegment;
import org.apache.shardingsphere.core.optimize.segment.insert.expression.DerivedParameterMarkerExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment.expression;
package org.apache.shardingsphere.core.optimize.segment.insert.expression;
import lombok.Getter;
import lombok.ToString;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment.expression;
package org.apache.shardingsphere.core.optimize.segment.insert.expression;
import lombok.Getter;
import lombok.ToString;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment.expression;
package org.apache.shardingsphere.core.optimize.segment.insert.expression;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.SimpleExpressionSegment;
......
......@@ -15,11 +15,11 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.groupby;
package org.apache.shardingsphere.core.optimize.segment.select.groupby;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import java.util.Collection;
......
......@@ -15,9 +15,10 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.groupby;
package org.apache.shardingsphere.core.optimize.segment.select.groupby.engine;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item;
import com.google.common.base.Optional;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item;
import com.google.common.base.Optional;
import lombok.Getter;
......@@ -23,6 +23,9 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ShorthandSelectItem;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import java.util.ArrayList;
......@@ -40,7 +43,7 @@ import java.util.List;
@RequiredArgsConstructor
@Getter
@Setter
@ToString(exclude = "tableMetas")
@ToString
public final class SelectItems {
private final int startIndex;
......@@ -51,10 +54,6 @@ public final class SelectItems {
private final Collection<SelectItem> items;
private final Collection<TableSegment> tables;
private final TableMetas tableMetas;
/**
* Judge is unqualified shorthand item or not.
*
......@@ -135,13 +134,15 @@ public final class SelectItems {
/**
* Get column labels.
*
* @param tableMetas table metas
* @param tables tables
* @return column labels
*/
public List<String> getColumnLabels() {
public List<String> getColumnLabels(final TableMetas tableMetas, final Collection<TableSegment> tables) {
List<String> result = new ArrayList<>(items.size());
for (SelectItem each : items) {
if (each instanceof ShorthandSelectItem) {
result.addAll(getShorthandColumnLabels((ShorthandSelectItem) each));
result.addAll(getShorthandColumnLabels(tableMetas, tables, (ShorthandSelectItem) each));
} else {
result.add(each.getColumnLabel());
}
......@@ -149,11 +150,12 @@ public final class SelectItems {
return result;
}
private Collection<String> getShorthandColumnLabels(final ShorthandSelectItem shorthandSelectItem) {
return shorthandSelectItem.getOwner().isPresent() ? getQualifiedShorthandColumnLabels(shorthandSelectItem.getOwner().get()) : getUnqualifiedShorthandColumnLabels();
private Collection<String> getShorthandColumnLabels(final TableMetas tableMetas, final Collection<TableSegment> tables, final ShorthandSelectItem shorthandSelectItem) {
return shorthandSelectItem.getOwner().isPresent()
? getQualifiedShorthandColumnLabels(tableMetas, tables, shorthandSelectItem.getOwner().get()) : getUnqualifiedShorthandColumnLabels(tableMetas, tables);
}
private Collection<String> getQualifiedShorthandColumnLabels(final String owner) {
private Collection<String> getQualifiedShorthandColumnLabels(final TableMetas tableMetas, final Collection<TableSegment> tables, final String owner) {
for (TableSegment each : tables) {
if (owner.equalsIgnoreCase(each.getAlias().or(each.getTableName()))) {
return tableMetas.get(each.getTableName()).getColumns().keySet();
......@@ -162,7 +164,7 @@ public final class SelectItems {
return Collections.emptyList();
}
private Collection<String> getUnqualifiedShorthandColumnLabels() {
private Collection<String> getUnqualifiedShorthandColumnLabels(final TableMetas tableMetas, final Collection<TableSegment> tables) {
Collection<String> result = new LinkedList<>();
for (TableSegment each : tables) {
result.addAll(tableMetas.get(each.getTableName()).getColumns().keySet());
......
......@@ -15,16 +15,16 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item.engine;
package org.apache.shardingsphere.core.optimize.segment.select.item.engine;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.ColumnSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.DerivedColumn;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.ExpressionSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.ShorthandSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ColumnSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.DerivedColumn;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ExpressionSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ShorthandSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.AggregationDistinctSelectItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.AggregationSelectItemSegment;
......
......@@ -15,22 +15,22 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item.engine;
package org.apache.shardingsphere.core.optimize.segment.select.item.engine;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.segment.Table;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.DerivedColumn;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.DerivedSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.ShorthandSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.Table;
import org.apache.shardingsphere.core.optimize.segment.Tables;
import org.apache.shardingsphere.core.optimize.segment.select.item.DerivedColumn;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ShorthandSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.DerivedSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment;
......@@ -67,8 +67,7 @@ public final class SelectItemsEngine {
public SelectItems createSelectItems(final String sql, final SelectStatement selectStatement, final GroupBy groupBy, final OrderBy orderBy) {
SelectItemsSegment selectItemsSegment = selectStatement.getSelectItems();
Collection<SelectItem> items = getSelectItemList(sql, selectItemsSegment);
SelectItems result = new SelectItems(
selectItemsSegment.getStartIndex(), selectItemsSegment.getStopIndex(), selectItemsSegment.isDistinctRow(), items, selectStatement.getTables(), tableMetas);
SelectItems result = new SelectItems(selectItemsSegment.getStartIndex(), selectItemsSegment.getStopIndex(), selectItemsSegment.isDistinctRow(), items);
Tables tables = new Tables(selectStatement);
result.getItems().addAll(getDerivedGroupByColumns(tables, items, groupBy));
result.getItems().addAll(getDerivedOrderByColumns(tables, items, orderBy));
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import lombok.Getter;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import com.google.common.base.Optional;
import lombok.EqualsAndHashCode;
......@@ -23,6 +23,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.apache.shardingsphere.core.parse.util.SQLUtil;
......
......@@ -15,13 +15,14 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import com.google.common.base.Optional;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
/**
* Common select item.
......
......@@ -15,13 +15,14 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import com.google.common.base.Optional;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
/**
* Derived common select item.
......
......@@ -15,13 +15,14 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import com.google.common.base.Optional;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
/**
* Expression select item.
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
......@@ -23,6 +23,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
/**
* Shorthand select item.
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.orderby;
package org.apache.shardingsphere.core.optimize.segment.select.orderby;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.orderby;
package org.apache.shardingsphere.core.optimize.segment.select.orderby;
import lombok.EqualsAndHashCode;
import lombok.Getter;
......
......@@ -15,9 +15,11 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.orderby;
package org.apache.shardingsphere.core.optimize.segment.select.orderby.engine;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
......
......@@ -15,11 +15,11 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.pagination;
package org.apache.shardingsphere.core.optimize.segment.select.pagination;
import com.google.common.base.Optional;
import lombok.Getter;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.ParameterMarkerPaginationValueSegment;
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.pagination.engine;
package org.apache.shardingsphere.core.optimize.segment.select.pagination.engine;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitSegment;
import java.util.List;
......
......@@ -15,11 +15,11 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.pagination.engine;
package org.apache.shardingsphere.core.optimize.segment.select.pagination.engine;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.top.TopSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.AndPredicate;
......
......@@ -15,11 +15,11 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.pagination.engine;
package org.apache.shardingsphere.core.optimize.segment.select.pagination.engine;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
......
......@@ -15,10 +15,10 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.pagination.engine;
package org.apache.shardingsphere.core.optimize.segment.select.pagination.engine;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
......
/*
* 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.core.optimize.sharding.engnie;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.engine.OptimizeEngine;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupByEngine;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.engine.SelectItemsEngine;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByEngine;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.engine.PaginationEngine;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.SubqueryPredicateSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import java.util.Collection;
import java.util.List;
/**
* Select optimize engine for sharding.
*
* @author zhangliang
*/
public final class ShardingSelectOptimizeEngine implements OptimizeEngine<SelectStatement> {
@Override
public SelectOptimizedStatement optimize(final TableMetas tableMetas, final String sql, final List<Object> parameters, final SelectStatement sqlStatement) {
GroupByEngine groupByEngine = new GroupByEngine();
OrderByEngine orderByEngine = new OrderByEngine();
SelectItemsEngine selectItemsEngine = new SelectItemsEngine(tableMetas);
PaginationEngine paginationEngine = new PaginationEngine();
GroupBy groupBy = groupByEngine.createGroupBy(sqlStatement);
OrderBy orderBy = orderByEngine.createOrderBy(sqlStatement, groupBy);
SelectItems selectItems = selectItemsEngine.createSelectItems(sql, sqlStatement, groupBy, orderBy);
Pagination pagination = paginationEngine.createPagination(sqlStatement, selectItems, parameters);
SelectOptimizedStatement result = new SelectOptimizedStatement(sqlStatement, groupBy, orderBy, selectItems, pagination);
setContainsSubquery(sqlStatement, result);
return result;
}
private void setContainsSubquery(final SelectStatement sqlStatement, final SelectOptimizedStatement optimizedStatement) {
Collection<SubqueryPredicateSegment> subqueryPredicateSegments = sqlStatement.findSQLSegments(SubqueryPredicateSegment.class);
for (SubqueryPredicateSegment each : subqueryPredicateSegments) {
if (!each.getAndPredicates().isEmpty()) {
optimizedStatement.setContainsSubquery(true);
return;
}
}
}
}
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.statement;
package org.apache.shardingsphere.core.optimize.statement;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.segment.Tables;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
/**
......
......@@ -15,11 +15,12 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.statement;
package org.apache.shardingsphere.core.optimize.statement.impl;
import lombok.Getter;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.segment.Tables;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
/**
......@@ -29,7 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
*/
@Getter
@ToString
public final class CommonOptimizedStatement implements OptimizedStatement {
public class CommonOptimizedStatement implements OptimizedStatement {
private final SQLStatement sqlStatement;
......
......@@ -15,13 +15,12 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.statement;
package org.apache.shardingsphere.core.optimize.statement.impl;
import lombok.Getter;
import lombok.ToString;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.segment.InsertValue;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.segment.insert.InsertValue;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement;
......@@ -35,28 +34,23 @@ import java.util.List;
* @author zhangliang
*/
@Getter
@ToString
public final class InsertOptimizedStatement implements OptimizedStatement {
private final InsertStatement sqlStatement;
private final Tables tables;
@ToString(callSuper = true)
public final class InsertOptimizedStatement extends CommonOptimizedStatement {
private final List<String> columnNames;
private final List<InsertValue> insertValues;
public InsertOptimizedStatement(final TableMetas tableMetas, final List<Object> parameters, final InsertStatement sqlStatement) {
this.sqlStatement = sqlStatement;
tables = new Tables(sqlStatement);
columnNames = sqlStatement.useDefaultColumns() ? tableMetas.getAllColumnNames(tables.getSingleTableName()) : sqlStatement.getColumnNames();
insertValues = getInsertValues(parameters, sqlStatement);
super(sqlStatement);
columnNames = sqlStatement.useDefaultColumns() ? tableMetas.getAllColumnNames(getTables().getSingleTableName()) : sqlStatement.getColumnNames();
insertValues = getInsertValues(parameters);
}
private List<InsertValue> getInsertValues(final List<Object> parameters, final InsertStatement sqlStatement) {
private List<InsertValue> getInsertValues(final List<Object> parameters) {
List<InsertValue> result = new LinkedList<>();
int parametersOffset = 0;
for (Collection<ExpressionSegment> each : sqlStatement.getAllValueExpressions()) {
for (Collection<ExpressionSegment> each : ((InsertStatement) getSqlStatement()).getAllValueExpressions()) {
InsertValue insertValue = new InsertValue(each, parameters, parametersOffset);
result.add(insertValue);
parametersOffset += insertValue.getParametersCount();
......
......@@ -15,29 +15,34 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.statement;
package org.apache.shardingsphere.core.optimize.statement.impl;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.engine.GroupByEngine;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.item.engine.SelectItemsEngine;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.engine.OrderByEngine;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.engine.PaginationEngine;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ExpressionOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.TextOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.SubqueryPredicateSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.parse.util.SQLUtil;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
......@@ -46,13 +51,8 @@ import java.util.Map;
* @author zhangliang
*/
@Getter
@Setter
@ToString
public final class SelectOptimizedStatement implements OptimizedStatement {
private final SQLStatement sqlStatement;
private final Tables tables;
@ToString(callSuper = true)
public final class SelectOptimizedStatement extends CommonOptimizedStatement {
private final GroupBy groupBy;
......@@ -62,15 +62,35 @@ public final class SelectOptimizedStatement implements OptimizedStatement {
private final Pagination pagination;
private boolean containsSubquery;
private final boolean containsSubquery;
public SelectOptimizedStatement(final SQLStatement sqlStatement, final GroupBy groupBy, final OrderBy orderBy, final SelectItems selectItems, final Pagination pagination) {
this.sqlStatement = sqlStatement;
this.tables = new Tables(sqlStatement);
// TODO to be remove, for test case only
public SelectOptimizedStatement(final SelectStatement sqlStatement, final GroupBy groupBy, final OrderBy orderBy, final SelectItems selectItems, final Pagination pagination) {
super(sqlStatement);
this.groupBy = groupBy;
this.orderBy = orderBy;
this.selectItems = selectItems;
this.pagination = pagination;
containsSubquery = containsSubquery();
}
public SelectOptimizedStatement(final TableMetas tableMetas, final String sql, final List<Object> parameters, final SelectStatement sqlStatement) {
super(sqlStatement);
this.groupBy = new GroupByEngine().createGroupBy(sqlStatement);
this.orderBy = new OrderByEngine().createOrderBy(sqlStatement, groupBy);
this.selectItems = new SelectItemsEngine(tableMetas).createSelectItems(sql, sqlStatement, groupBy, orderBy);
this.pagination = new PaginationEngine().createPagination(sqlStatement, selectItems, parameters);
containsSubquery = containsSubquery();
}
private boolean containsSubquery() {
Collection<SubqueryPredicateSegment> subqueryPredicateSegments = getSqlStatement().findSQLSegments(SubqueryPredicateSegment.class);
for (SubqueryPredicateSegment each : subqueryPredicateSegments) {
if (!each.getAndPredicates().isEmpty()) {
return true;
}
}
return false;
}
/**
......@@ -138,6 +158,16 @@ public final class SelectOptimizedStatement implements OptimizedStatement {
? ((ColumnOrderByItemSegment) orderByItemSegment).getColumn().getName() : ((ExpressionOrderByItemSegment) orderByItemSegment).getExpression();
}
/**
* Get column labels.
*
* @param tableMetas table metas
* @return column labels
*/
public List<String> getColumnLabels(final TableMetas tableMetas) {
return selectItems.getColumnLabels(tableMetas, ((SelectStatement) getSqlStatement()).getTables());
}
/**
* Judge group by and order by sequence is same or not.
*
......
/*
* 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.core.optimize.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.spi.encrypt.ShardingQueryAssistedEncryptor;
import java.util.Properties;
@Getter
@Setter
public final class TestQueryAssistedShardingEncryptor implements ShardingQueryAssistedEncryptor {
private Properties properties = new Properties();
@Override
public String getType() {
return "assistedTest";
}
@Override
public void init() {
}
@Override
public String encrypt(final Object plaintext) {
return "encryptValue";
}
@Override
public Object decrypt(final String ciphertext) {
return "decryptValue";
}
@Override
public String queryAssistedEncrypt(final String plaintext) {
return "assistedEncryptValue";
}
}
/*
* 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.core.optimize.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.spi.encrypt.ShardingEncryptor;
import java.util.Properties;
@Getter
@Setter
public final class TestShardingEncryptor implements ShardingEncryptor {
private Properties properties = new Properties();
@Override
public String getType() {
return "test";
}
@Override
public void init() {
}
@Override
public String encrypt(final Object plaintext) {
return "encryptValue";
}
@Override
public Object decrypt(final String ciphertext) {
return "decryptValue";
}
}
/*
* 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.core.optimize.fixture;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;
import java.util.Properties;
public final class TestShardingKeyGenerator implements ShardingKeyGenerator {
@Override
public String getType() {
return "TEST-OPTIMIZE";
}
@Override
public Properties getProperties() {
return new Properties();
}
@Override
public void setProperties(final Properties properties) {
}
@Override
public Comparable<?> generateKey() {
return 1;
}
}
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.segment;
package org.apache.shardingsphere.core.optimize.segment;
import com.google.common.base.Optional;
import com.google.common.collect.Sets;
......
......@@ -15,8 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item;
import org.apache.shardingsphere.core.optimize.segment.select.item.DerivedColumn;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
......
......@@ -15,12 +15,20 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.metadata.column.ColumnMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ColumnSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.DerivedSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ExpressionSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ShorthandSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.junit.Test;
......@@ -41,46 +49,46 @@ public final class SelectItemsTest {
@Test
public void assertUnqualifiedShorthandItemWithEmptyItems() {
SelectItems selectItems = new SelectItems(0, 0, true, Collections.<SelectItem>emptySet(), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.<SelectItem>emptySet());
assertFalse(selectItems.isUnqualifiedShorthandItem());
}
@Test
public void assertUnqualifiedShorthandItemWithWrongSelectItem() {
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton((SelectItem) getColumnSelectItem()), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton((SelectItem) getColumnSelectItem()));
assertFalse(selectItems.isUnqualifiedShorthandItem());
}
@Test
public void assertUnqualifiedShorthandItemWithWrongShortSelectItem() {
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton((SelectItem) getShorthandSelectItem()), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton((SelectItem) getShorthandSelectItem()));
assertFalse(selectItems.isUnqualifiedShorthandItem());
}
@Test
public void assertUnqualifiedShorthandItem() {
SelectItem selectItem = new ShorthandSelectItem(null);
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem));
assertTrue(selectItems.isUnqualifiedShorthandItem());
}
@Test
public void assertFindAliasWithOutAlias() {
SelectItems selectItems = new SelectItems(0, 0, true, Collections.<SelectItem>emptyList(), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.<SelectItem>emptyList());
assertFalse(selectItems.findAlias("").isPresent());
}
@Test
public void assertFindAlias() {
SelectItem selectItem = getColumnSelectItemWithAlias();
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem));
assertTrue(selectItems.findAlias(selectItem.getExpression()).isPresent());
}
@Test
public void assertFindItemIndex() {
SelectItem selectItem = getColumnSelectItem();
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem));
Optional<Integer> actual = selectItems.findItemIndex(selectItem.getExpression());
assertTrue(actual.isPresent());
assertThat(actual.get(), is(1));
......@@ -89,7 +97,7 @@ public final class SelectItemsTest {
@Test
public void assertFindItemIndexFailure() {
SelectItem selectItem = getColumnSelectItem();
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem), Collections.<TableSegment>emptyList(), createTableMetas());
SelectItems selectItems = new SelectItems(0, 0, true, Collections.singleton(selectItem));
Optional<Integer> actual = selectItems.findItemIndex("");
assertFalse(actual.isPresent());
}
......@@ -98,7 +106,7 @@ public final class SelectItemsTest {
public void assertGetAggregationSelectItems() {
SelectItem aggregationSelectItem = getAggregationSelectItem();
List<AggregationSelectItem> items = new SelectItems(0, 0, true,
Arrays.asList(aggregationSelectItem, getColumnSelectItem()), Collections.<TableSegment>emptyList(), createTableMetas()).getAggregationSelectItems();
Arrays.asList(aggregationSelectItem, getColumnSelectItem())).getAggregationSelectItems();
assertTrue(items.contains(aggregationSelectItem));
assertEquals(items.size(), 1);
}
......@@ -106,8 +114,7 @@ public final class SelectItemsTest {
@Test
public void assertGetAggregationDistinctSelectItems() {
SelectItem aggregationDistinctSelectItem = getAggregationDistinctSelectItem();
List<AggregationDistinctSelectItem> items = new SelectItems(0, 0, true,
Arrays.asList(aggregationDistinctSelectItem, getColumnSelectItem()), Collections.<TableSegment>emptyList(), createTableMetas()).getAggregationDistinctSelectItems();
List<AggregationDistinctSelectItem> items = new SelectItems(0, 0, true, Arrays.asList(aggregationDistinctSelectItem, getColumnSelectItem())).getAggregationDistinctSelectItems();
assertTrue(items.contains(aggregationDistinctSelectItem));
assertEquals(items.size(), 1);
}
......@@ -115,72 +122,70 @@ public final class SelectItemsTest {
@Test
public void assertGetColumnLabelWithShorthandSelectItem() {
SelectItem selectItem = getShorthandSelectItem();
List<String> columnLabels = new SelectItems(
0, 0, true, Collections.singletonList(selectItem), Collections.singletonList(new TableSegment(0, 0, "table")), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.singletonList(new TableSegment(0, 0, "table")));
assertEquals(columnLabels, Arrays.asList("id", "name"));
}
@Test
public void assertGetColumnLabelWithShorthandSelectItem2() {
SelectItem selectItem = getShorthandSelectItemWithOutOwner();
List<String> columnLabels = new SelectItems(
0, 0, true, Collections.singletonList(selectItem), Collections.singletonList(new TableSegment(0, 0, "table")), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.singletonList(new TableSegment(0, 0, "table")));
assertEquals(columnLabels, Arrays.asList("id", "name"));
}
@Test
public void assertGetColumnLabelsWithCommonSelectItem() {
SelectItem selectItem = getColumnSelectItem();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getColumnLabel()));
}
@Test
public void assertGetColumnLabelsWithCommonSelectItemAlias() {
SelectItem selectItem = getColumnSelectItemWithAlias();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getAlias().or("")));
}
@Test
public void assertGetColumnLabelsWithExpressionSelectItem() {
SelectItem selectItem = getExpressionSelectItem();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getColumnLabel()));
}
@Test
public void assertGetColumnLabelsWithExpressionSelectItemAlias() {
SelectItem selectItem = getExpressionSelectItemWithAlias();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getAlias().or("")));
}
@Test
public void assertGetColumnLabelsWithDerivedSelectItem() {
SelectItem selectItem = getDerivedSelectItem();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getColumnLabel()));
}
@Test
public void assertGetColumnLabelsWithDerivedSelectItemAlias() {
SelectItem selectItem = getDerivedSelectItemWithAlias();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getAlias().or("")));
}
@Test
public void assertGetColumnLabelsWithAggregationSelectItem() {
SelectItem selectItem = getAggregationSelectItem();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getColumnLabel()));
}
@Test
public void assertGetColumnLabelsWithAggregationDistinctSelectItem() {
SelectItem selectItem = getAggregationDistinctSelectItem();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem), Collections.<TableSegment>emptyList(), createTableMetas()).getColumnLabels();
List<String> columnLabels = new SelectItems(0, 0, true, Collections.singletonList(selectItem)).getColumnLabels(createTableMetas(), Collections.<TableSegment>emptyList());
assertTrue(columnLabels.contains(selectItem.getColumnLabel()));
}
......
......@@ -15,8 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.item;
package org.apache.shardingsphere.core.optimize.segment.select.item.impl;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.parse.core.constant.AggregationType;
import org.junit.Test;
......
......@@ -15,14 +15,15 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.sharding.segment.pagination;
package org.apache.shardingsphere.core.optimize.segment.select.pagination;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment;
......
/*
* 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.core.optimize.sharding.engnie;
import org.apache.shardingsphere.core.metadata.column.ColumnMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ShorthandSelectItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.AndPredicate;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.WhereSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateBetweenRightValue;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateCompareRightValue;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateInRightValue;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class ShardingSelectOptimizeEngineTest {
@Mock
private TableMetas tableMetas;
private SelectStatement selectStatement;
@Before
public void setUp() {
selectStatement = new SelectStatement();
selectStatement.getAllSQLSegments().add(new TableSegment(0, 0, "tbl"));
}
@Test
public void assertOptimizeAlwaysFalseListConditions() {
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
Collection<AndPredicate> andPredicates = new LinkedList<>();
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateInRightValue(Arrays.<ExpressionSegment>asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2)))));
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(), new PredicateCompareRightValue("=", new LiteralExpressionSegment(0, 0, 3))));
andPredicates.add(andPredicate);
WhereSegment whereSegment = new WhereSegment(0, 0, 0);
whereSegment.getAndPredicates().addAll(andPredicates);
selectStatement.setWhere(whereSegment);
}
@Test
public void assertOptimizeAlwaysFalseRangeConditions() {
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
Collection<AndPredicate> andPredicates = new LinkedList<>();
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateInRightValue(Arrays.<ExpressionSegment>asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2)))));
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateInRightValue(Arrays.<ExpressionSegment>asList(new LiteralExpressionSegment(0, 0, 3), new LiteralExpressionSegment(0, 0, 4)))));
andPredicates.add(andPredicate);
WhereSegment whereSegment = new WhereSegment(0, 0, 0);
whereSegment.getAndPredicates().addAll(andPredicates);
selectStatement.setWhere(whereSegment);
}
@Test
public void assertOptimizeAlwaysFalseListConditionsAndRangeConditions() {
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
Collection<AndPredicate> andPredicates = new LinkedList<>();
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateInRightValue(Arrays.<ExpressionSegment>asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2)))));
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateBetweenRightValue(new LiteralExpressionSegment(0, 0, 3), new LiteralExpressionSegment(0, 0, 4))));
andPredicates.add(andPredicate);
WhereSegment whereSegment = new WhereSegment(0, 0, 0);
whereSegment.getAndPredicates().addAll(andPredicates);
selectStatement.setWhere(whereSegment);
}
@SuppressWarnings("unchecked")
@Test
public void assertOptimizeListConditions() {
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
Collection<AndPredicate> andPredicates = new LinkedList<>();
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateInRightValue(Arrays.<ExpressionSegment>asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2)))));
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(), new PredicateCompareRightValue("=", new LiteralExpressionSegment(0, 0, 1))));
andPredicates.add(andPredicate);
WhereSegment whereSegment = new WhereSegment(0, 0, 0);
whereSegment.getAndPredicates().addAll(andPredicates);
selectStatement.setWhere(whereSegment);
}
@SuppressWarnings("unchecked")
@Test
public void assertOptimizeRangeConditions() {
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
Collection<AndPredicate> andPredicates = new LinkedList<>();
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateBetweenRightValue(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2))));
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateBetweenRightValue(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 3))));
andPredicates.add(andPredicate);
WhereSegment whereSegment = new WhereSegment(0, 0, 0);
whereSegment.getAndPredicates().addAll(andPredicates);
selectStatement.setWhere(whereSegment);
}
@SuppressWarnings("unchecked")
@Test
public void assertOptimizeListConditionsAndRangeConditions() {
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
Collection<AndPredicate> andPredicates = new LinkedList<>();
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateInRightValue(Arrays.<ExpressionSegment>asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2)))));
andPredicate.getPredicates().add(new PredicateSegment(0, 0, createColumnSegment(),
new PredicateBetweenRightValue(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 2))));
andPredicates.add(andPredicate);
WhereSegment whereSegment = new WhereSegment(0, 0, 0);
whereSegment.getAndPredicates().addAll(andPredicates);
selectStatement.setWhere(whereSegment);
}
private ColumnSegment createColumnSegment() {
ColumnSegment result = new ColumnSegment(0, 0, "column");
result.setOwner(new TableSegment(0, 0, "tbl"));
return result;
}
@Test
public void assertOptimizeWithShorthandItems() {
when(tableMetas.get("tbl")).thenReturn(createTableMetaData());
selectStatement.setSelectItems(createSelectItemsSegment());
selectStatement.getTables().add(new TableSegment(0, 0, "tbl"));
SelectItems selectItems = new ShardingSelectOptimizeEngine().optimize(tableMetas, "", Collections.emptyList(), selectStatement).getSelectItems();
assertThat(selectItems.getColumnLabels().size(), is(2));
assertThat(selectItems.getColumnLabels().get(0), is("id"));
assertThat(selectItems.getColumnLabels().get(1), is("user_id"));
}
private SelectItemsSegment createSelectItemsSegment() {
TableSegment owner = mock(TableSegment.class);
when(owner.getTableName()).thenReturn("tbl");
ShorthandSelectItemSegment shorthandSelectItemSegment = new ShorthandSelectItemSegment(0, 0, "tbl.*");
shorthandSelectItemSegment.setOwner(owner);
SelectItemsSegment result = new SelectItemsSegment(0, 0, false);
result.getSelectItems().add(shorthandSelectItemSegment);
return result;
}
private TableMetaData createTableMetaData() {
ColumnMetaData idColumnMetaData = new ColumnMetaData("id", "int", true);
ColumnMetaData nameColumnMetaData = new ColumnMetaData("user_id", "int", false);
return new TableMetaData(Arrays.asList(idColumnMetaData, nameColumnMetaData), Arrays.asList("id", "user_id"));
}
}
......@@ -15,9 +15,10 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.statement;
package org.apache.shardingsphere.core.optimize.statement.impl;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.InsertValuesSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
......
......@@ -15,20 +15,20 @@
* limitations under the License.
*/
package org.apache.shardingsphere.core.optimize.api.statement;
package org.apache.shardingsphere.core.optimize.statement.impl;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.core.metadata.column.ColumnMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.sharding.segment.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.ColumnSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.segment.select.groupby.GroupBy;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.ColumnSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderBy;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.parse.core.constant.OrderDirection;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.GroupBySegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.OrderBySegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment;
......@@ -36,7 +36,6 @@ import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
......@@ -45,6 +44,7 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public final class SelectOptimizedStatementTest {
......@@ -94,8 +94,29 @@ public final class SelectOptimizedStatementTest {
@Test
public void assertIsSameGroupByAndOrderByItems() {
SelectOptimizedStatement selectOptimizedStatement = new SelectOptimizedStatement(
new SelectStatement(), new GroupBy(Collections.<OrderByItem>emptyList(), 0), new OrderBy(Collections.<OrderByItem>emptyList(), false), createSelectItems(), null);
SelectStatement selectStatement = new SelectStatement();
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.<OrderByItemSegment>singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.<OrderByItemSegment>singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
SelectOptimizedStatement selectOptimizedStatement = new SelectOptimizedStatement(null, "", Collections.emptyList(), selectStatement);
assertTrue(selectOptimizedStatement.isSameGroupByAndOrderByItems());
}
@Test
public void assertIsNotSameGroupByAndOrderByItemsWhenEmptyGroupBy() {
SelectStatement selectStatement = new SelectStatement();
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
SelectOptimizedStatement selectOptimizedStatement = new SelectOptimizedStatement(null, "", Collections.emptyList(), selectStatement);
assertFalse(selectOptimizedStatement.isSameGroupByAndOrderByItems());
}
@Test
public void assertIsNotSameGroupByAndOrderByItemsWhenDifferentGroupByAndOrderBy() {
SelectStatement selectStatement = new SelectStatement();
selectStatement.setSelectItems(new SelectItemsSegment(0, 0, false));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.<OrderByItemSegment>singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.DESC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.<OrderByItemSegment>singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
SelectOptimizedStatement selectOptimizedStatement = new SelectOptimizedStatement(null, "", Collections.emptyList(), selectStatement);
assertFalse(selectOptimizedStatement.isSameGroupByAndOrderByItems());
}
......@@ -122,7 +143,7 @@ public final class SelectOptimizedStatementTest {
private SelectItems createSelectItems() {
Collection<SelectItem> selectItems = Lists.newArrayList(getColumnSelectItemWithoutOwner(), getColumnSelectItemWithoutOwner(true), getColumnSelectItemWithoutOwner(false));
return new SelectItems(0, 0, true, selectItems, Collections.<TableSegment>emptyList(), createTableMetas());
return new SelectItems(0, 0, true, selectItems);
}
private SelectItem getColumnSelectItemWithoutOwner() {
......@@ -132,10 +153,4 @@ public final class SelectOptimizedStatementTest {
private SelectItem getColumnSelectItemWithoutOwner(final boolean hasAlias) {
return new ColumnSelectItem(null, hasAlias ? "name" : "id", hasAlias ? "n" : null);
}
private TableMetas createTableMetas() {
Map<String, TableMetaData> tables = new HashMap<>(1, 1);
tables.put("table", new TableMetaData(Arrays.asList(new ColumnMetaData("id", "number", true), new ColumnMetaData("name", "varchar", false)), Collections.<String>emptyList()));
return new TableMetas(tables);
}
}
#
# 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.
#
org.apache.shardingsphere.core.optimize.fixture.TestShardingEncryptor
org.apache.shardingsphere.core.optimize.fixture.TestQueryAssistedShardingEncryptor
#
# 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.
#
org.apache.shardingsphere.core.optimize.fixture.TestShardingKeyGenerator
#
# 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.
#
dataSources:
ds_0: !!com.zaxxer.hikari.HikariDataSource
driverClassName: org.h2.Driver
jdbcUrl: jdbc:h2:mem:db0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
username: sa
password:
ds_1: !!com.zaxxer.hikari.HikariDataSource
driverClassName: org.h2.Driver
jdbcUrl: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
username: sa
password:
shardingRule:
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
databaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: t_order_${user_id % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
type: TEST-OPTIMIZE
column: order_id
t_encrypt:
actualDataNodes: ds_${0..1}.t_encrypt_${0..1}
databaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: t_encrypt_${user_id % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_encrypt_${order_id % 2}
keyGenerator:
type: TEST-OPTIMIZE
column: order_id
t_encrypt_query:
actualDataNodes: ds_${0..1}.t_encrypt_query${0..1}
databaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: t_encrypt_query${user_id % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_encrypt_query${order_id % 2}
keyGenerator:
type: TEST-OPTIMIZE
column: order_id
encryptRule:
encryptors:
t_encryptor:
type: test
t_query_encryptor:
type: assistedTest
tables:
t_encrypt:
columns:
order_id:
cipherColumn: order_id
encryptor: t_encryptor
t_encrypt_query:
columns:
user_id:
cipherColumn: user_id
encryptor: t_query_encryptor
assistedQueryColumn: assisted_user_id
\ No newline at end of file
......@@ -18,9 +18,9 @@
package org.apache.shardingsphere.core.rewrite;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.segment.InsertValue;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.insert.InsertValue;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.builder.parameter.group.GroupedParameterBuilder;
import org.apache.shardingsphere.core.rewrite.builder.parameter.standard.StandardParameterBuilder;
......
......@@ -19,8 +19,8 @@ package org.apache.shardingsphere.core.rewrite.builder.parameter.standard;
import com.google.common.base.Optional;
import lombok.Getter;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.type.RoutingUnit;
......
......@@ -21,7 +21,7 @@ import com.google.common.base.Optional;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import org.apache.shardingsphere.core.optimize.segment.Tables;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.SimpleExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.AndPredicate;
......
......@@ -19,8 +19,8 @@ package org.apache.shardingsphere.core.rewrite.statement;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.core.optimize.api.segment.InsertValue;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.insert.InsertValue;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.rewrite.encrypt.EncryptConditions;
import org.apache.shardingsphere.core.rewrite.statement.constant.EncryptDerivedColumnType;
import org.apache.shardingsphere.core.rewrite.statement.constant.ShardingDerivedColumnType;
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.rewrite.statement;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.rewrite.encrypt.EncryptConditions;
import org.apache.shardingsphere.core.route.router.sharding.condition.ShardingConditions;
......
......@@ -20,8 +20,8 @@ package org.apache.shardingsphere.core.rewrite.statement;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dml.DMLStatement;
import org.apache.shardingsphere.core.rewrite.encrypt.EncryptCondition;
import org.apache.shardingsphere.core.rewrite.encrypt.EncryptConditions;
......
......@@ -18,9 +18,9 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.DerivedColumn;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.item.impl.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.optimize.segment.select.item.DerivedColumn;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.RewriteStatement;
import org.apache.shardingsphere.core.rewrite.token.pojo.AggregationDistinctToken;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.InsertColumnsSegment;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.InsertColumnsSegment;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.InsertRewriteStatement;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.InsertColumnsSegment;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.RewriteStatement;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.InsertColumnsSegment;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.InsertRewriteStatement;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
......
......@@ -19,9 +19,9 @@ package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.core.optimize.api.segment.expression.DerivedSimpleExpressionSegment;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.insert.expression.DerivedSimpleExpressionSegment;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.rewrite.statement.constant.EncryptDerivedColumnType;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment;
......
......@@ -18,9 +18,9 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.segment.InsertValue;
import org.apache.shardingsphere.core.optimize.api.statement.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.insert.InsertValue;
import org.apache.shardingsphere.core.optimize.statement.impl.InsertOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.InsertValuesSegment;
import org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.RewriteStatement;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.core.constant.QuoteCharacter;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ExpressionOrderByItemSegment;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.RewriteStatement;
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.OptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ColumnSelectItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegment;
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.core.rewrite.token.generator;
import com.google.common.base.Optional;
import org.apache.shardingsphere.core.optimize.sharding.segment.item.SelectItems;
import org.apache.shardingsphere.core.optimize.api.statement.SelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.segment.select.item.SelectItems;
import org.apache.shardingsphere.core.optimize.statement.impl.SelectOptimizedStatement;
import org.apache.shardingsphere.core.rewrite.builder.parameter.ParameterBuilder;
import org.apache.shardingsphere.core.rewrite.statement.RewriteStatement;
import org.apache.shardingsphere.core.rewrite.token.pojo.SelectItemPrefixToken;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册