Skip to content

Commit

Permalink
Merge 8c82157 into b45c832
Browse files Browse the repository at this point in the history
  • Loading branch information
nancyzrh committed Aug 6, 2019
2 parents b45c832 + 8c82157 commit 300303e
Show file tree
Hide file tree
Showing 26 changed files with 1,352 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -12,6 +12,6 @@ jdk:
before_script:
- echo "MAVEN_OPTS='-Xmx1024m -XX:MaxPermSize=256m'" > ~/.mavenrc
script:
- mvn clean install cobertura:cobertura coveralls:report -DrepoToken="${COVERALLS_REPO_TOKEN}" -Dmaven.javadoc.skip=true
- mvn clean install -Dmaven.javadoc.skip=true

install: travis_wait 30 mvn install --quiet
Expand Up @@ -29,7 +29,9 @@
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.pagination.limit.LimitSegment;
import org.apache.shardingsphere.core.parse.integrate.asserts.selectitem.SelectItemAssert;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegment;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.sql.statement.ddl.AlterTableStatement;
import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
Expand Down Expand Up @@ -63,6 +65,8 @@ public final class ShardingSQLStatementAssert {
private final PaginationAssert paginationAssert;

private final AlterTableAssert alterTableAssert;

private final SelectItemAssert selectItemAssert;

public ShardingSQLStatementAssert(final SQLStatement actual, final String sqlCaseId, final SQLCaseType sqlCaseType) {
SQLStatementAssertMessage assertMessage = new SQLStatementAssertMessage(
Expand All @@ -75,6 +79,7 @@ public ShardingSQLStatementAssert(final SQLStatement actual, final String sqlCas
orderByAssert = new OrderByAssert(assertMessage);
paginationAssert = new PaginationAssert(sqlCaseType, assertMessage);
alterTableAssert = new AlterTableAssert(assertMessage);
selectItemAssert = new SelectItemAssert(sqlCaseType, assertMessage);
}

/**
Expand All @@ -96,9 +101,10 @@ public void assertSQLStatement() {

private void assertSelectStatement(final SelectStatement actual) {
// TODO do select items assert
// Optional<SelectItemsSegment> selectItemsSegment = actual.findSQLSegment(SelectItemsSegment.class);
// if (selectItemsSegment.isPresent()) {
// }
Optional<SelectItemsSegment> selectItemsSegment = actual.findSQLSegment(SelectItemsSegment.class);
if (selectItemsSegment.isPresent()) {
selectItemAssert.assertSelectItems(selectItemsSegment.get(),expected.getSelectItems());
}
Optional<GroupBySegment> groupBySegment = actual.findSQLSegment(GroupBySegment.class);
if (groupBySegment.isPresent()) {
groupByAssert.assertGroupByItems(groupBySegment.get().getGroupByItems(), expected.getGroupByColumns());
Expand Down
@@ -0,0 +1,85 @@
/*
* 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.parse.integrate.asserts.selectitem;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage;
import org.apache.shardingsphere.core.parse.integrate.jaxb.selectitem.*;
import org.apache.shardingsphere.core.parse.sql.segment.dml.item.*;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.top.TopSegment;
import org.apache.shardingsphere.test.sql.SQLCaseType;

import java.util.Collection;
import java.util.LinkedList;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
* Select item assert.
*
* @author zhaoyanan
*/
@RequiredArgsConstructor
public final class SelectItemAssert {

private final SQLCaseType sqlCaseType;

private final SQLStatementAssertMessage assertMessage;

public void assertSelectItems(final SelectItemsSegment actual, final ExpectedSelectItems expectedSelectItems){
Collection<SelectItemSegment> actualItems = actual.getSelectItems();
assertThat(assertMessage.getFullAssertMessage("Select items size error: "), actualItems.size(), is(expectedSelectItems.getSize()));
Collection<ExpectedSelectItem> expectedBaseItems = new LinkedList<>();
for (SelectItemSegment each : actualItems) {
if (each instanceof ShorthandSelectItemSegment) {
expectedBaseItems = expectedSelectItems.findExpectedSelectItems(ExpectedShorthandSelectItem.class);
}
if (each instanceof AggregationSelectItemSegment) {
expectedBaseItems = expectedSelectItems.findExpectedSelectItems(ExpectedAggregationItem.class);
}
if (each instanceof AggregationDistinctSelectItemSegment) {
expectedBaseItems = expectedSelectItems.findExpectedSelectItems(ExpectedAggregationDistinctItem.class);
}
if (each instanceof ColumnSelectItemSegment) {
expectedBaseItems = expectedSelectItems.findExpectedSelectItems(ExpectedColumnSelectItem.class);
}
if (each instanceof ExpressionSelectItemSegment) {
expectedBaseItems = expectedSelectItems.findExpectedSelectItems(ExpectedExpressionItem.class);
}
if (each instanceof TopSegment && SQLCaseType.Literal.equals(sqlCaseType)) {
expectedBaseItems = expectedSelectItems.findExpectedSelectItems(ExpectedTopSelectItem.class);
}
if (!expectedBaseItems.isEmpty()) {
assertSelectItem(each, expectedBaseItems);
}
}
}

private void assertSelectItem(final SelectItemSegment actual, final Collection<ExpectedSelectItem> expected) {
String actualText = actual.getText();
String expectedText = "";
for (ExpectedSelectItem each: expected) {
if(actualText.equals(each.getText())) {
expectedText = each.getText();
break;
}
}
assertThat(assertMessage.getFullAssertMessage("selectItem text assert error: "),actualText,is(expectedText));
}
}

Expand Up @@ -24,6 +24,7 @@
import org.apache.shardingsphere.core.parse.integrate.jaxb.insert.ExpectedInsertColumnsAndValues;
import org.apache.shardingsphere.core.parse.integrate.jaxb.orderby.ExpectedOrderByColumn;
import org.apache.shardingsphere.core.parse.integrate.jaxb.pagination.ExpectedPaginationValue;
import org.apache.shardingsphere.core.parse.integrate.jaxb.selectitem.ExpectedSelectItems;
import org.apache.shardingsphere.core.parse.integrate.jaxb.table.ExpectedAlterTable;
import org.apache.shardingsphere.core.parse.integrate.jaxb.table.ExpectedTable;
import org.apache.shardingsphere.core.parse.integrate.jaxb.token.ExpectedTokens;
Expand Down Expand Up @@ -84,6 +85,9 @@ public final class ParserResult {

@XmlAttribute(name = "auto-commit")
private boolean autoCommit;

@XmlElement(name = "select-items")
private ExpectedSelectItems selectItems = new ExpectedSelectItems();

/**
* Get parameters.
Expand Down
@@ -0,0 +1,34 @@
/*
* 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.parse.integrate.jaxb.selectitem;

import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedAggregationDistinctItem extends ExpectedAggregationItem{

@XmlAttribute
private String distinctExpression;
}
@@ -0,0 +1,43 @@
/*
* 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.parse.integrate.jaxb.selectitem;

import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class ExpectedAggregationItem extends ExpectedBaseSelectItem {

@XmlAttribute
private Integer innerExpressionStartIndex;

@XmlAttribute
private String type;

@XmlAttribute
private String alias;

@XmlAttribute(name = "aggregation-inner-expression")
private String innerExpression;

}
@@ -0,0 +1,40 @@
/*
* 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.parse.integrate.jaxb.selectitem;

import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class ExpectedBaseSelectItem implements ExpectedSelectItem {

@XmlAttribute(name = "start-index")
protected Integer startIndex;

@XmlAttribute(name = "stop-index")
protected Integer stopIndex;

@XmlAttribute
protected String text;

}
@@ -0,0 +1,45 @@
/*
* 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.parse.integrate.jaxb.selectitem;

import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.core.parse.core.constant.QuoteCharacter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedColumnSelectItem extends ExpectedBaseSelectItem{

@XmlAttribute
private String alias;

@XmlAttribute
private String name;

@XmlAttribute
private QuoteCharacter quoteCharacter = QuoteCharacter.NONE;

@XmlElement(name = "table-segment")
private ExpectedTableSegment owner = new ExpectedTableSegment();

}
@@ -0,0 +1,33 @@
/*
* 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.parse.integrate.jaxb.selectitem;

import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementWrapper;


@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedExpressionItem extends ExpectedBaseSelectItem {
@XmlAttribute
private String alias;
}
@@ -0,0 +1,44 @@
/*
* 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.parse.integrate.jaxb.selectitem;

import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedRowNumberValueSegment {

@XmlAttribute(name = "parameter-index")
protected Integer parameterIndex;

@XmlAttribute(name = "start-index")
private Integer startIndex;

@XmlAttribute(name = "stop-index")
private Integer stopIndex;

@XmlAttribute(name = "bound-opened")
private boolean boundOpened = false;

}

0 comments on commit 300303e

Please sign in to comment.