You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/03 02:57:25 UTC

[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #21431: Dynamic Loading SQL Parser Parameterized Test

terrymanu commented on code in PR #21431:
URL: https://github.com/apache/shardingsphere/pull/21431#discussion_r1012453045


##########
pom.xml:
##########
@@ -153,7 +153,8 @@
         <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
         <freemarker.version>2.3.31</freemarker.version>
         <spotless-maven-plugin.version>2.22.1</spotless-maven-plugin.version>
-        <caffeine.version>2.9.3</caffeine.version>
+        <caffeine.version>2.9.2</caffeine.version>

Review Comment:
   Is it necessary to downgrade caffeine?



##########
test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.test.sql.parser.parameterized.engine;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+import org.junit.Test;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ArrayList;
+
+@RequiredArgsConstructor
+@SingletonSPI
+public abstract class DynamicLoadingSQLParserParameterizedTest {
+    
+    private final String sqlCaseId;
+    
+    private final String sqlCaseValue;
+    
+    private final String databaseType;
+    
+    private static ArrayList<Map<String, String>> getResponse(final String sqlCaseURL) {
+        String[] patches = sqlCaseURL.split("/", 8);
+        String sqlCasesOwner = patches[3];
+        String sqlCasesRepo = patches[4];
+        String sqlCasesDirectory = patches[7];
+        return new RestTemplate().getForObject(
+                "https://api.github.com/repos/{owner}/{repo}/contents/{directory}", ArrayList.class,
+                sqlCasesOwner, sqlCasesRepo, sqlCasesDirectory);
+    }
+    
+    protected static Collection<Object[]> getTestParameters(final String sqlCaseURL) throws IOException, URISyntaxException {
+        Collection<Object[]> result = new ArrayList<>();
+        ArrayList<Map<String, String>> response = getResponse(sqlCaseURL);

Review Comment:
   Please use List to instead of ArrayList here



##########
test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.test.sql.parser.parameterized.engine;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+import org.junit.Test;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ArrayList;
+
+@RequiredArgsConstructor
+@SingletonSPI

Review Comment:
   What is the useful?



##########
test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.test.sql.parser.parameterized.engine;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+import org.junit.Test;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ArrayList;
+
+@RequiredArgsConstructor
+@SingletonSPI
+public abstract class DynamicLoadingSQLParserParameterizedTest {
+    
+    private final String sqlCaseId;
+    
+    private final String sqlCaseValue;
+    
+    private final String databaseType;
+    
+    private static ArrayList<Map<String, String>> getResponse(final String sqlCaseURL) {
+        String[] patches = sqlCaseURL.split("/", 8);
+        String sqlCasesOwner = patches[3];
+        String sqlCasesRepo = patches[4];
+        String sqlCasesDirectory = patches[7];
+        return new RestTemplate().getForObject(
+                "https://api.github.com/repos/{owner}/{repo}/contents/{directory}", ArrayList.class,
+                sqlCasesOwner, sqlCasesRepo, sqlCasesDirectory);
+    }
+    
+    protected static Collection<Object[]> getTestParameters(final String sqlCaseURL) throws IOException, URISyntaxException {
+        Collection<Object[]> result = new ArrayList<>();
+        ArrayList<Map<String, String>> response = getResponse(sqlCaseURL);
+        for (Map<String, String> each : response) {
+            result.addAll(getSqlCases(each));
+        }
+        return result;
+    }
+    
+    private static Collection<Object[]> getSqlCases(final Map<String, String> elements) throws IOException, URISyntaxException {
+        Collection<Object[]> result = new ArrayList<>();
+        String sqlCaseFileName = elements.get("name");
+        String sqlCaseFileContent = IOUtils.toString(new URI(elements.get("download_url")), StandardCharsets.UTF_8);
+        String[] lines = sqlCaseFileContent.split("\n");
+        int sqlCaseEnum = 1;
+        for (String each : lines) {
+            if (each.isEmpty()) {
+                continue;
+            }
+            if (Character.isLetter(each.charAt(0)) && each.charAt(each.length() - 1) == ';') {
+                String sqlCaseId = sqlCaseFileName.split("\\.")[0] + sqlCaseEnum;
+                result.add(new Object[]{
+                        sqlCaseId, each,
+                });
+                sqlCaseEnum++;
+            }
+        }
+        return result;
+    }
+    
+    @Test(expected = Exception.class)
+    public final void assertDynamicLoadingSQL() {
+        CacheOption cacheOption = new CacheOption(128, 1024L);
+        ParseASTNode parseContext = new SQLParserEngine(databaseType, cacheOption).parse(sqlCaseValue, false);
+        new SQLVisitorEngine(databaseType, "STATEMENT", true, new Properties()).visit(parseContext);
+        System.out.println("ParserError: " + sqlCaseId + " value: " + sqlCaseValue + " db-type: " + databaseType);
+        throw new RuntimeException();

Review Comment:
   Why always throw exception?



##########
.mvn/jvm.config:
##########
@@ -1 +1 @@
--Xmx2g -XX:MaxMetaspaceSize=512m

Review Comment:
   Why need to increase so much mem here?



##########
test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.test.sql.parser.parameterized.engine;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+import org.junit.Test;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ArrayList;
+
+@RequiredArgsConstructor
+@SingletonSPI
+public abstract class DynamicLoadingSQLParserParameterizedTest {
+    
+    private final String sqlCaseId;
+    
+    private final String sqlCaseValue;
+    
+    private final String databaseType;
+    
+    private static ArrayList<Map<String, String>> getResponse(final String sqlCaseURL) {
+        String[] patches = sqlCaseURL.split("/", 8);
+        String sqlCasesOwner = patches[3];
+        String sqlCasesRepo = patches[4];
+        String sqlCasesDirectory = patches[7];
+        return new RestTemplate().getForObject(
+                "https://api.github.com/repos/{owner}/{repo}/contents/{directory}", ArrayList.class,
+                sqlCasesOwner, sqlCasesRepo, sqlCasesDirectory);
+    }
+    
+    protected static Collection<Object[]> getTestParameters(final String sqlCaseURL) throws IOException, URISyntaxException {
+        Collection<Object[]> result = new ArrayList<>();

Review Comment:
   Please use LinkedList to instead of ArrayList here



##########
pom.xml:
##########
@@ -688,6 +689,11 @@
                 <version>${springframework.version}</version>
                 <scope>test</scope>
             </dependency>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-web</artifactId>
+                <version>${springframework.version}</version>
+            </dependency>

Review Comment:
   ShardingSphere is a backend project, please do not involve spring-web dependencies



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org