-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add the
shardingsphere-infra-expr-purelist
module to replace the …
…`shardingsphere-infra-expr-espresso` module
- Loading branch information
1 parent
576e705
commit f7f6162
Showing
11 changed files
with
214 additions
and
49 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.shardingsphere</groupId> | ||
<artifactId>shardingsphere-infra-expr</artifactId> | ||
<version>5.4.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>shardingsphere-infra-expr-purelist</artifactId> | ||
<name>${project.artifactId}</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.shardingsphere</groupId> | ||
<artifactId>shardingsphere-infra-expr-spi</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.groovy</groupId> | ||
<artifactId>groovy</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
72 changes: 72 additions & 0 deletions
72
...in/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParser.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,72 @@ | ||
/* | ||
* 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.infra.expr.purelist; | ||
|
||
import com.google.common.base.Strings; | ||
import groovy.lang.Closure; | ||
import org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Pure List inline expression parser. | ||
*/ | ||
public final class PureListInlineExpressionParser implements InlineExpressionParser { | ||
|
||
private static final char SPLITTER = ','; | ||
|
||
@Override | ||
public String handlePlaceHolder(final String inlineExpression) { | ||
return inlineExpression.contains("$->{") ? inlineExpression.replaceAll("\\$->\\{", "\\$\\{") : inlineExpression; | ||
} | ||
|
||
@Override | ||
public List<String> splitAndEvaluate(final String inlineExpression) { | ||
return Strings.isNullOrEmpty(inlineExpression) ? Collections.emptyList() : split(inlineExpression); | ||
} | ||
|
||
@Override | ||
public Closure<?> evaluateClosure(final String inlineExpression) { | ||
throw new RuntimeException("Groovy classes cannot be used directly within GraalVM Native Image."); | ||
} | ||
|
||
private List<String> split(final String inlineExpression) { | ||
List<String> result = new ArrayList<>(); | ||
StringBuilder segment = new StringBuilder(); | ||
for (int i = 0; i < inlineExpression.length(); i++) { | ||
char each = inlineExpression.charAt(i); | ||
if (each == SPLITTER) { | ||
result.add(segment.toString().trim()); | ||
segment.setLength(0); | ||
} else { | ||
segment.append(each); | ||
} | ||
} | ||
if (segment.length() > 0) { | ||
result.add(segment.toString().trim()); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "PURELIST"; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...sources/META-INF/services/org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser
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,18 @@ | ||
# | ||
# 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.infra.expr.purelist.PureListInlineExpressionParser |
60 changes: 60 additions & 0 deletions
60
...ava/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParserTest.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,60 @@ | ||
/* | ||
* 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.infra.expr.purelist; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.hasItems; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class PureListInlineExpressionParserTest { | ||
|
||
@Test | ||
void assertEvaluateForExpressionIsNull() { | ||
List<String> expected = new PureListInlineExpressionParser().splitAndEvaluate(null); | ||
assertThat(expected, is(Collections.<String>emptyList())); | ||
} | ||
|
||
@Test | ||
void assertEvaluateForSimpleString() { | ||
List<String> expected = new PureListInlineExpressionParser().splitAndEvaluate(" t_order_0, t_order_1 "); | ||
assertThat(expected.size(), is(2)); | ||
assertThat(expected, hasItems("t_order_0", "t_order_1")); | ||
} | ||
|
||
@Test | ||
void assertEvaluateForLong() { | ||
StringBuilder expression = new StringBuilder(); | ||
for (int i = 0; i < 1024; i++) { | ||
expression.append("ds_"); | ||
expression.append(i / 64); | ||
expression.append(".t_user_"); | ||
expression.append(i); | ||
if (i != 1023) { | ||
expression.append(","); | ||
} | ||
} | ||
List<String> expected = new PureListInlineExpressionParser().splitAndEvaluate(expression.toString()); | ||
assertThat(expected.size(), is(1024)); | ||
assertThat(expected, hasItems("ds_0.t_user_0", "ds_15.t_user_1023")); | ||
} | ||
} |