Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Saisimon committed Jul 9, 2019
2 parents 5683971 + 5aaa193 commit 878c830
Show file tree
Hide file tree
Showing 91 changed files with 1,353 additions and 852 deletions.
71 changes: 71 additions & 0 deletions jenkinsfile
@@ -0,0 +1,71 @@
/*
* 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.
*
*/

def ssBuildBadge = addEmbeddableBadgeConfiguration(id: "ssbuild", subject: "Build")
pipeline {
agent {
label 'xenial'
}
options {
buildDiscarder(logRotator(
numToKeepStr: '60',
))
timestamps()
skipStagesAfterUnstable()
timeout time: 60, unit: 'MINUTES'
}
stages {
stage('SCM checkout') {
steps {
deleteDir()
checkout scm
sh 'git submodule update --init'
}
}
stage('Build & Test') {
tools {
maven 'maven-3.2.1'
jdk 'JDK 1.8 (latest)'
}
steps {
script {
ssBuildBadge.setStatus('running')
try {
sh '''
echo "MAVEN_OPTS='-Xmx1024m -XX:MaxPermSize=256m'" > ~/.mavenrc
mvn clean install cobertura:cobertura coveralls:report -DrepoToken=${COVERALLS_REPO_TOKEN} -Prelease
'''
ssBuildBadge.setStatus('passing')
} catch (Exception err) {
ssBuildBadge.setStatus('failing')
ssBuildBadge.setColor('pink')
error 'Build failed'
}
}
}
}
}
post {
success {
junit '**/target/surefire-reports/*.xml'
}
cleanup {
deleteDir()
}
}
}
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.core.rule;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import lombok.Getter;
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
Expand All @@ -41,6 +42,7 @@ public final class ShardingDataSourceNames {
private final Collection<String> dataSourceNames;

public ShardingDataSourceNames(final ShardingRuleConfiguration shardingRuleConfig, final Collection<String> rawDataSourceNames) {
Preconditions.checkArgument(null != shardingRuleConfig, "can not construct ShardingDataSourceNames with null ShardingRuleConfig");
this.shardingRuleConfig = shardingRuleConfig;
dataSourceNames = getAllDataSourceNames(rawDataSourceNames);
}
Expand Down
Expand Up @@ -73,7 +73,8 @@ public class ShardingRule implements BaseRule {
private final EncryptRule encryptRule;

public ShardingRule(final ShardingRuleConfiguration shardingRuleConfig, final Collection<String> dataSourceNames) {
Preconditions.checkArgument(!dataSourceNames.isEmpty(), "Data sources cannot be empty.");
Preconditions.checkArgument(null != shardingRuleConfig, "ShardingRuleConfig cannot be null.");
Preconditions.checkArgument(null != dataSourceNames && !dataSourceNames.isEmpty(), "Data sources cannot be empty.");
this.shardingRuleConfig = shardingRuleConfig;
shardingDataSourceNames = new ShardingDataSourceNames(shardingRuleConfig, dataSourceNames);
tableRules = createTableRules(shardingRuleConfig);
Expand Down
Expand Up @@ -90,4 +90,9 @@ public void assertGetDefaultDataSourceNameWithoutMasterSlaveDataSourceName() {
String actual = new ShardingDataSourceNames(shardingRuleConfig, Arrays.asList("master_ds", "slave_ds")).getRawMasterDataSourceName("default_ds");
assertThat(actual, is("default_ds"));
}

@Test(expected = IllegalArgumentException.class)
public void assertConstructShardingDataSourceNamesWithNullShardingRuleConfiguration() {
new ShardingDataSourceNames(null, Arrays.asList("master_ds", "slave_ds")).getRawMasterDataSourceName("default_ds");
}
}
Expand Up @@ -328,6 +328,21 @@ public void assertGetShardingLogicTableNames() {
ShardingRule actual = createMaximumShardingRule();
assertThat(actual.getShardingLogicTableNames(Arrays.asList("LOGIC_TABLE", "BROADCAST_TABLE")), CoreMatchers.<Collection<String>>is(Collections.singletonList("LOGIC_TABLE")));
}

@Test(expected = IllegalArgumentException.class)
public void assertConstructShardingRuleWithNullShardingRuleConfiguration() {
new ShardingRule(null, createDataSourceNames());
}

@Test(expected = IllegalArgumentException.class)
public void assertConstructShardingRuleWithNullDataSourceNames(){
ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ms_ds_${0..1}.table_${0..2}");
shardingRuleConfiguration.getTableRuleConfigs().add(tableRuleConfiguration);
shardingRuleConfiguration.getMasterSlaveRuleConfigs().add(createMasterSlaveRuleConfiguration("ms_ds_0", "master_ds_0", "slave_ds_0"));
shardingRuleConfiguration.getMasterSlaveRuleConfigs().add(createMasterSlaveRuleConfiguration("ms_ds_1", "master_ds_1", "slave_ds_1"));
new ShardingRule(shardingRuleConfiguration, null);
}

private ShardingRule createMaximumShardingRule() {
ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
Expand Down
Expand Up @@ -33,7 +33,7 @@
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.statement.sharding.dml.select.Pagination;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.pagination.Pagination;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.ShardingSelectOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.context.selectitem.AggregationDistinctSelectItem;
import org.apache.shardingsphere.core.parse.util.SQLUtil;
Expand Down Expand Up @@ -99,7 +99,7 @@ public QueryResult apply(final DistinctQueryResult input) {
}

private boolean isNeedProcessDistinctSelectItem() {
return optimizedStatement.getDistinctSelectItem().isPresent() && optimizedStatement.getGroupByItems().isEmpty();
return optimizedStatement.getDistinctSelectItem().isPresent() && optimizedStatement.getGroupBy().getItems().isEmpty();
}

private Map<String, Integer> getColumnLabelIndexMap(final QueryResult queryResult) throws SQLException {
Expand All @@ -120,11 +120,11 @@ public MergedResult merge() throws SQLException {
}

private MergedResult build() throws SQLException {
if (!optimizedStatement.getGroupByItems().isEmpty() || !optimizedStatement.getAggregationSelectItems().isEmpty()) {
if (!optimizedStatement.getGroupBy().getItems().isEmpty() || !optimizedStatement.getAggregationSelectItems().isEmpty()) {
return getGroupByMergedResult();
}
if (!optimizedStatement.getOrderByItems().isEmpty()) {
return new OrderByStreamMergedResult(queryResults, optimizedStatement.getOrderByItems());
if (!optimizedStatement.getOrderBy().getItems().isEmpty()) {
return new OrderByStreamMergedResult(queryResults, optimizedStatement.getOrderBy().getItems());
}
return new IteratorStreamMergedResult(queryResults);
}
Expand All @@ -136,7 +136,7 @@ private MergedResult getGroupByMergedResult() throws SQLException {

private MergedResult decorate(final MergedResult mergedResult) throws SQLException {
Pagination pagination = ((ShardingSelectOptimizedStatement) routeResult.getOptimizedStatement()).getPagination();
if (null == pagination || 1 == queryResults.size()) {
if (!pagination.isHasPagination() || 1 == queryResults.size()) {
return mergedResult;
}
String trunkDatabaseName = DatabaseTypes.getTrunkDatabaseType(databaseType.getName()).getName();
Expand Down
Expand Up @@ -60,7 +60,7 @@ private Iterator<MemoryQueryResultRow> init(final List<QueryResult> queryResults
Map<GroupByValue, Map<AggregationSelectItem, AggregationUnit>> aggregationMap = new HashMap<>(1024);
for (QueryResult each : queryResults) {
while (each.next()) {
GroupByValue groupByValue = new GroupByValue(each, optimizedStatement.getGroupByItems());
GroupByValue groupByValue = new GroupByValue(each, optimizedStatement.getGroupBy().getItems());
initForFirstGroupByValue(each, groupByValue, dataMap, aggregationMap);
aggregate(each, groupByValue, aggregationMap);
}
Expand Down
Expand Up @@ -21,11 +21,11 @@
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.statement.sharding.dml.select.OrderByItem;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.ShardingSelectOptimizedStatement;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.orderby.OrderByItem;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;

/**
* Group by row comparator.
Expand All @@ -39,13 +39,13 @@ public final class GroupByRowComparator implements Comparator<MemoryQueryResultR

@Override
public int compare(final MemoryQueryResultRow o1, final MemoryQueryResultRow o2) {
if (!optimizedStatement.getOrderByItems().isEmpty()) {
return compare(o1, o2, optimizedStatement.getOrderByItems());
if (!optimizedStatement.getOrderBy().getItems().isEmpty()) {
return compare(o1, o2, optimizedStatement.getOrderBy().getItems());
}
return compare(o1, o2, optimizedStatement.getGroupByItems());
return compare(o1, o2, optimizedStatement.getGroupBy().getItems());
}

private int compare(final MemoryQueryResultRow o1, final MemoryQueryResultRow o2, final List<OrderByItem> orderByItems) {
private int compare(final MemoryQueryResultRow o1, final MemoryQueryResultRow o2, final Collection<OrderByItem> orderByItems) {
for (OrderByItem each : orderByItems) {
Object orderValue1 = o1.getCell(each.getIndex());
Preconditions.checkState(null == orderValue1 || orderValue1 instanceof Comparable, "Order by value must implements Comparable");
Expand Down
Expand Up @@ -52,12 +52,12 @@ public final class GroupByStreamMergedResult extends OrderByStreamMergedResult {

public GroupByStreamMergedResult(
final Map<String, Integer> labelAndIndexMap, final List<QueryResult> queryResults, final ShardingSelectOptimizedStatement optimizedStatement) throws SQLException {
super(queryResults, optimizedStatement.getOrderByItems());
super(queryResults, optimizedStatement.getOrderBy().getItems());
this.labelAndIndexMap = labelAndIndexMap;
this.optimizedStatement = optimizedStatement;
currentRow = new ArrayList<>(labelAndIndexMap.size());
currentGroupByValues = getOrderByValuesQueue().isEmpty()
? Collections.emptyList() : new GroupByValue(getCurrentQueryResult(), optimizedStatement.getGroupByItems()).getGroupValues();
? Collections.emptyList() : new GroupByValue(getCurrentQueryResult(), optimizedStatement.getGroupBy().getItems()).getGroupValues();
}

@Override
Expand All @@ -70,7 +70,7 @@ public boolean next() throws SQLException {
super.next();
}
if (aggregateCurrentGroupByRowAndNext()) {
currentGroupByValues = new GroupByValue(getCurrentQueryResult(), optimizedStatement.getGroupByItems()).getGroupValues();
currentGroupByValues = new GroupByValue(getCurrentQueryResult(), optimizedStatement.getGroupBy().getItems()).getGroupValues();
}
return true;
}
Expand All @@ -84,7 +84,7 @@ public AggregationUnit apply(final AggregationSelectItem input) {
return AggregationUnitFactory.create(input.getType());
}
});
while (currentGroupByValues.equals(new GroupByValue(getCurrentQueryResult(), optimizedStatement.getGroupByItems()).getGroupValues())) {
while (currentGroupByValues.equals(new GroupByValue(getCurrentQueryResult(), optimizedStatement.getGroupBy().getItems()).getGroupValues())) {
aggregate(aggregationUnitMap);
cacheCurrentRow();
result = super.next();
Expand Down
Expand Up @@ -20,10 +20,11 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.OrderByItem;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.orderby.OrderByItem;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -37,11 +38,11 @@ public final class GroupByValue {

private final List<?> groupValues;

public GroupByValue(final QueryResult queryResult, final List<OrderByItem> groupByItems) throws SQLException {
public GroupByValue(final QueryResult queryResult, final Collection<OrderByItem> groupByItems) throws SQLException {
groupValues = getGroupByValues(queryResult, groupByItems);
}

private List<?> getGroupByValues(final QueryResult queryResult, final List<OrderByItem> groupByItems) throws SQLException {
private List<?> getGroupByValues(final QueryResult queryResult, final Collection<OrderByItem> groupByItems) throws SQLException {
List<Object> result = new ArrayList<>(groupByItems.size());
for (OrderByItem each : groupByItems) {
result.add(queryResult.getValue(each.getIndex(), Object.class));
Expand Down
Expand Up @@ -21,9 +21,10 @@
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.statement.sharding.dml.select.OrderByItem;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.orderby.OrderByItem;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
Expand All @@ -35,15 +36,15 @@
*/
public class OrderByStreamMergedResult extends StreamMergedResult {

private final List<OrderByItem> orderByItems;
private final Collection<OrderByItem> orderByItems;

@Getter(AccessLevel.PROTECTED)
private final Queue<OrderByValue> orderByValuesQueue;

@Getter(AccessLevel.PROTECTED)
private boolean isFirstNext;

public OrderByStreamMergedResult(final List<QueryResult> queryResults, final List<OrderByItem> orderByItems) throws SQLException {
public OrderByStreamMergedResult(final List<QueryResult> queryResults, final Collection<OrderByItem> orderByItems) throws SQLException {
this.orderByItems = orderByItems;
this.orderByValuesQueue = new PriorityQueue<>(queryResults.size());
orderResultSetsToQueue(queryResults);
Expand Down
Expand Up @@ -21,10 +21,11 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.OrderByItem;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.orderby.OrderByItem;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand All @@ -39,7 +40,7 @@ public final class OrderByValue implements Comparable<OrderByValue> {
@Getter
private final QueryResult queryResult;

private final List<OrderByItem> orderByItems;
private final Collection<OrderByItem> orderByItems;

private List<Comparable<?>> orderValues;

Expand Down Expand Up @@ -67,12 +68,13 @@ private List<Comparable<?>> getOrderValues() throws SQLException {

@Override
public int compareTo(final OrderByValue o) {
for (int i = 0; i < orderByItems.size(); i++) {
OrderByItem thisOrderByItem = orderByItems.get(i);
int result = CompareUtil.compareTo(orderValues.get(i), o.orderValues.get(i), thisOrderByItem.getSegment().getOrderDirection(), thisOrderByItem.getSegment().getNullOrderDirection());
int i = 0;
for (OrderByItem each : orderByItems) {
int result = CompareUtil.compareTo(orderValues.get(i), o.orderValues.get(i), each.getSegment().getOrderDirection(), each.getSegment().getNullOrderDirection());
if (0 != result) {
return result;
}
i++;
}
return 0;
}
Expand Down
Expand Up @@ -19,7 +19,7 @@

import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.common.DecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.Pagination;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.pagination.Pagination;

import java.sql.SQLException;

Expand Down
Expand Up @@ -19,7 +19,7 @@

import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.common.DecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.Pagination;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.pagination.Pagination;

import java.sql.SQLException;

Expand Down
Expand Up @@ -19,7 +19,7 @@

import org.apache.shardingsphere.core.merge.MergedResult;
import org.apache.shardingsphere.core.merge.dql.common.DecoratorMergedResult;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.Pagination;
import org.apache.shardingsphere.core.optimize.statement.sharding.dml.select.pagination.Pagination;

import java.sql.SQLException;

Expand Down

0 comments on commit 878c830

Please sign in to comment.