Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,352 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...a/org/apache/shardingsphere/core/parse/integrate/asserts/selectitem/SelectItemAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../shardingsphere/core/parse/integrate/jaxb/selectitem/ExpectedAggregationDistinctItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
43 changes: 43 additions & 0 deletions
43
...g/apache/shardingsphere/core/parse/integrate/jaxb/selectitem/ExpectedAggregationItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...rg/apache/shardingsphere/core/parse/integrate/jaxb/selectitem/ExpectedBaseSelectItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
.../apache/shardingsphere/core/parse/integrate/jaxb/selectitem/ExpectedColumnSelectItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...rg/apache/shardingsphere/core/parse/integrate/jaxb/selectitem/ExpectedExpressionItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
44 changes: 44 additions & 0 deletions
44
...he/shardingsphere/core/parse/integrate/jaxb/selectitem/ExpectedRowNumberValueSegment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
Oops, something went wrong.