You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/11/06 11:33:06 UTC

(shardingsphere) branch master updated: Add MySQLProjectionIdentifierExtractorTest (#37027)

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 fbf93a91a4c Add MySQLProjectionIdentifierExtractorTest (#37027)
fbf93a91a4c is described below

commit fbf93a91a4c47c3c6bbfd4b18e7d47f9896727ec
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Nov 6 19:33:00 2025 +0800

    Add MySQLProjectionIdentifierExtractorTest (#37027)
---
 .../MySQLProjectionIdentifierExtractorTest.java}   | 26 ++++++++++++----------
 ...ostgreSQLProjectionIdentifierExtractorTest.java |  6 +++++
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java b/infra/binder/dialect/mysql/src/test/java/org/apache/shardingsphere/infra/binder/mysql/MySQLProjectionIdentifierExtractorTest.java
similarity index 67%
copy from infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java
copy to infra/binder/dialect/mysql/src/test/java/org/apache/shardingsphere/infra/binder/mysql/MySQLProjectionIdentifierExtractorTest.java
index 1019d583047..82b4a1f414d 100644
--- a/infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java
+++ b/infra/binder/dialect/mysql/src/test/java/org/apache/shardingsphere/infra/binder/mysql/MySQLProjectionIdentifierExtractorTest.java
@@ -15,14 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.binder.postgresql;
+package org.apache.shardingsphere.infra.binder.mysql;
 
-import org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter;
 import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
@@ -33,34 +31,38 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.mockito.Mockito.mock;
 
-class PostgreSQLProjectionIdentifierExtractorTest {
+class MySQLProjectionIdentifierExtractorTest {
     
-    private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+    private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "MySQL");
     
     private final DialectProjectionIdentifierExtractor extractor = DatabaseTypedSPILoader.getService(DialectProjectionIdentifierExtractor.class, databaseType);
     
     @Test
     void assertGetIdentifierValue() {
-        assertThat(extractor.getIdentifierValue(new IdentifierValue("Data", QuoteCharacter.NONE)), is("data"));
+        assertThat(extractor.getIdentifierValue(new IdentifierValue("foo_id")), is("foo_id"));
     }
     
     @Test
     void assertGetColumnNameFromFunction() {
-        assertThat(extractor.getColumnNameFromFunction("Function", "FunctionExpression"), is("function"));
+        assertThat(extractor.getColumnNameFromFunction("COUNT", "COUNT(*)"), is("COUNT(*)"));
     }
     
     @Test
     void assertGetColumnNameFromExpression() {
-        assertThat(extractor.getColumnNameFromExpression(new ExpressionProjectionSegment(0, 0, "expression")), is("?column?"));
+        assertThat(extractor.getColumnNameFromExpression(new ExpressionProjectionSegment(0, 0, "expression")), is("expression"));
     }
     
     @Test
-    void assertGetColumnNameFromFunctionExpression() {
-        assertThat(extractor.getColumnNameFromExpression(new ExpressionProjectionSegment(0, 0, "SUM(ID)", new FunctionSegment(0, 0, "SUM", "SUM(ID)"))), is("SUM"));
+    void assertGetColumnNameFromSubqueryWithoutTruncation() {
+        String text = "SELECT id FROM subquery";
+        assertThat(extractor.getColumnNameFromSubquery(new SubqueryProjectionSegment(mock(SubquerySegment.class), text)), is(text));
     }
     
     @Test
-    void assertGetColumnNameFromSubquery() {
-        assertThat(extractor.getColumnNameFromSubquery(new SubqueryProjectionSegment(mock(SubquerySegment.class), "text")), is("text"));
+    void assertGetColumnNameFromSubqueryWithTruncation() {
+        String text = "SELECT id FROM subquery WHERE column_name > 100 AND another_column LIKE '%some_long_text_value%' AND condition_3 = true"
+                + " AND condition_4 = false AND condition_5 IS NOT NULL AND condition_6 BETWEEN 1 AND 1000 AND condition_7 IN "
+                + "(SELECT id FROM another_table WHERE description LIKE '%even_more_detailed_description_text%' AND status = 'active' AND created_at > '2023-01-01')";
+        assertThat(extractor.getColumnNameFromSubquery(new SubqueryProjectionSegment(mock(SubquerySegment.class), text)), is(text.substring(0, 255)));
     }
 }
diff --git a/infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java b/infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java
index 1019d583047..d920bd9ba51 100644
--- a/infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java
+++ b/infra/binder/dialect/postgresql/src/test/java/org/apache/shardingsphere/infra/binder/postgresql/PostgreSQLProjectionIdentifierExtractorTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoa
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment;
@@ -54,6 +55,11 @@ class PostgreSQLProjectionIdentifierExtractorTest {
         assertThat(extractor.getColumnNameFromExpression(new ExpressionProjectionSegment(0, 0, "expression")), is("?column?"));
     }
     
+    @Test
+    void assertGetColumnNameFromExpressionWithNonExpressionProjection() {
+        assertThat(extractor.getColumnNameFromExpression(mock(ExpressionSegment.class)), is("?column?"));
+    }
+    
     @Test
     void assertGetColumnNameFromFunctionExpression() {
         assertThat(extractor.getColumnNameFromExpression(new ExpressionProjectionSegment(0, 0, "SUM(ID)", new FunctionSegment(0, 0, "SUM", "SUM(ID)"))), is("SUM"));