This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 25550ae695d Refactor ProjectionIdentifierExtractEngineTest (#33193)
25550ae695d is described below

commit 25550ae695d285309fd978f524ce11d50f34c13f
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 9 20:22:25 2024 +0800

    Refactor ProjectionIdentifierExtractEngineTest (#33193)
---
 .../ProjectionIdentifierExtractEngineTest.java     | 60 +++++++++++++++++
 ...OpenGaussProjectionIdentifierExtractorTest.java | 59 +++++++++++++++++
 .../OracleProjectionIdentifierExtractorTest.java   | 59 +++++++++++++++++
 ...ostgreSQLProjectionIdentifierExtractorTest.java | 59 +++++++++++++++++
 .../ProjectionIdentifierExtractEngineTest.java     | 75 ----------------------
 5 files changed, 237 insertions(+), 75 deletions(-)

diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
new file mode 100644
index 00000000000..6e51dd14c38
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
@@ -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.binder.context.segment.select.projection.extractor;
+
+import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+
+class ProjectionIdentifierExtractEngineTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
+    @Test
+    void assertGetIdentifierValueWithQuoteIdentifier() {
+        assertThat(new 
ProjectionIdentifierExtractEngine(databaseType).getIdentifierValue(new 
IdentifierValue("Data", QuoteCharacter.QUOTE)), is("Data"));
+    }
+    
+    @Test
+    void assertGetIdentifierValueWithNoneIdentifier() {
+        assertThat(new 
ProjectionIdentifierExtractEngine(databaseType).getIdentifierValue(new 
IdentifierValue("Data", QuoteCharacter.NONE)), is("Data"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromFunction() {
+        assertThat(new 
ProjectionIdentifierExtractEngine(databaseType).getColumnNameFromFunction("Function",
 "FunctionExpression"), is("FunctionExpression"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromExpression() {
+        assertThat(new 
ProjectionIdentifierExtractEngine(databaseType).getColumnNameFromExpression("expression"),
 is("expression"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromSubquery() {
+        assertThat(new 
ProjectionIdentifierExtractEngine(databaseType).getColumnNameFromSubquery(new 
SubqueryProjectionSegment(mock(SubquerySegment.class), "text")), is("text"));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OpenGaussProjectionIdentifierExtractorTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OpenGaussProjectionIdentifierExtractorTest.java
new file mode 100644
index 00000000000..e898c4c23c4
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OpenGaussProjectionIdentifierExtractorTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.binder.context.segment.select.projection.extractor.dialect;
+
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+
+class OpenGaussProjectionIdentifierExtractorTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "openGauss");
+    
+    private final DialectProjectionIdentifierExtractor extractor = 
DatabaseTypedSPILoader.getService(DialectProjectionIdentifierExtractor.class, 
databaseType);
+    
+    @Test
+    void assertGetIdentifierValue() {
+        assertThat(extractor.getIdentifierValue(new IdentifierValue("Data", 
QuoteCharacter.NONE)), is("data"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromFunction() {
+        assertThat(extractor.getColumnNameFromFunction("Function", 
"FunctionExpression"), is("function"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromExpression() {
+        assertThat(extractor.getColumnNameFromExpression("expression"), 
is("?column?"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromSubquery() {
+        assertThat(extractor.getColumnNameFromSubquery(new 
SubqueryProjectionSegment(mock(SubquerySegment.class), "text")), is("text"));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OracleProjectionIdentifierExtractorTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OracleProjectionIdentifierExtractorTest.java
new file mode 100644
index 00000000000..563b1eca8d3
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OracleProjectionIdentifierExtractorTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.binder.context.segment.select.projection.extractor.dialect;
+
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+
+class OracleProjectionIdentifierExtractorTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "Oracle");
+    
+    private final DialectProjectionIdentifierExtractor extractor = 
DatabaseTypedSPILoader.getService(DialectProjectionIdentifierExtractor.class, 
databaseType);
+    
+    @Test
+    void assertGetIdentifierValue() {
+        assertThat(extractor.getIdentifierValue(new IdentifierValue("Data", 
QuoteCharacter.NONE)), is("DATA"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromFunction() {
+        assertThat(extractor.getColumnNameFromFunction("Function", 
"FunctionExpression"), is("FUNCTIONEXPRESSION"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromExpression() {
+        assertThat(extractor.getColumnNameFromExpression("expression"), 
is("EXPRESSION"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromSubquery() {
+        assertThat(extractor.getColumnNameFromSubquery(new 
SubqueryProjectionSegment(mock(SubquerySegment.class), "text")), is("TEXT"));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/PostgreSQLProjectionIdentifierExtractorTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/PostgreSQLProjectionIdentifierExtractorTest.java
new file mode 100644
index 00000000000..42f3afbb3bc
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/PostgreSQLProjectionIdentifierExtractorTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.binder.context.segment.select.projection.extractor.dialect;
+
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+
+class PostgreSQLProjectionIdentifierExtractorTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+    
+    private final DialectProjectionIdentifierExtractor extractor = 
DatabaseTypedSPILoader.getService(DialectProjectionIdentifierExtractor.class, 
databaseType);
+    
+    @Test
+    void assertGetIdentifierValue() {
+        assertThat(extractor.getIdentifierValue(new IdentifierValue("Data", 
QuoteCharacter.NONE)), is("data"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromFunction() {
+        assertThat(extractor.getColumnNameFromFunction("Function", 
"FunctionExpression"), is("function"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromExpression() {
+        assertThat(extractor.getColumnNameFromExpression("expression"), 
is("?column?"));
+    }
+    
+    @Test
+    void assertGetColumnNameFromSubquery() {
+        assertThat(extractor.getColumnNameFromSubquery(new 
SubqueryProjectionSegment(mock(SubquerySegment.class), "text")), is("text"));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
deleted file mode 100644
index 3f172eb8980..00000000000
--- 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.binder.engine.segment.select.projection.extractor;
-
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
-import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
-import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
-import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.mockito.Mockito.mock;
-
-class ProjectionIdentifierExtractEngineTest {
-    
-    @Test
-    void assertGetIdentifierValue() {
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getIdentifierValue(new IdentifierValue("Data", 
QuoteCharacter.QUOTE)),
-                is("Data"));
-        IdentifierValue identifierValue = new IdentifierValue("Data", 
QuoteCharacter.NONE);
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getIdentifierValue(identifierValue), is("data"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"openGauss")).getIdentifierValue(identifierValue), is("data"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"Oracle")).getIdentifierValue(identifierValue), is("DATA"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")).getIdentifierValue(identifierValue), is("Data"));
-    }
-    
-    @Test
-    void assertGetColumnNameFromFunction() {
-        String functionName = "Function";
-        String functionExpression = "FunctionExpression";
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getColumnNameFromFunction(functionName, functionExpression), 
is("function"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"openGauss")).getColumnNameFromFunction(functionName, functionExpression), 
is("function"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"Oracle")).getColumnNameFromFunction(functionName, functionExpression),
-                is("FUNCTIONEXPRESSION"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")).getColumnNameFromFunction(functionName, functionExpression),
-                is("FunctionExpression"));
-    }
-    
-    @Test
-    void assertGetColumnNameFromExpression() {
-        String expression = "expression";
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getColumnNameFromExpression(expression), is("?column?"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"openGauss")).getColumnNameFromExpression(expression), is("?column?"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"Oracle")).getColumnNameFromExpression(expression), is("EXPRESSION"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")).getColumnNameFromExpression(expression), is("expression"));
-    }
-    
-    @Test
-    void assertGetColumnNameFromSubquery() {
-        SubqueryProjectionSegment projectionSegment = new 
SubqueryProjectionSegment(mock(SubquerySegment.class), "text");
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getColumnNameFromSubquery(projectionSegment), is("text"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"openGauss")).getColumnNameFromSubquery(projectionSegment), is("text"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"Oracle")).getColumnNameFromSubquery(projectionSegment), is("TEXT"));
-        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")).getColumnNameFromSubquery(projectionSegment), is("text"));
-    }
-}

Reply via email to