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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/dev/pr-13373-f34fa479c99bad36958867b456f0dd1210e833a9
in repository https://gitbox.apache.org/repos/asf/seatunnel.git

commit 8323d5f1947a9f77b94897675066f2acd9a4058a
Author: 龙骑士k <[email protected]>
AuthorDate: Tue Nov 24 05:58:02 2026 +0000

    [Fix][Connector-V2][Doris] Quote read fields in the Doris source query plan 
SQL (#13373)
    
    Signed-off-by: dragonknightk 
<[email protected]>
---
 docs/en/connectors/source/Doris.md                 |   6 +-
 docs/zh/connectors/source/Doris.md                 |   6 +-
 .../connectors/doris/rest/RestService.java         |  45 ++++++---
 .../connectors/doris/util/DorisCatalogUtil.java    |   2 +-
 .../connectors/doris/rest/RestServiceTest.java     |  73 ++++++++++++++
 .../seatunnel/e2e/connector/doris/DorisIT.java     |  41 ++++++++
 .../doris_source_keyword_columns_to_assert.conf    | 107 +++++++++++++++++++++
 7 files changed, 257 insertions(+), 23 deletions(-)

diff --git a/docs/en/connectors/source/Doris.md 
b/docs/en/connectors/source/Doris.md
index bfe78635c5..aedba9c302 100644
--- a/docs/en/connectors/source/Doris.md
+++ b/docs/en/connectors/source/Doris.md
@@ -88,8 +88,8 @@ Table list configuration:
 
|----------------------------------|--------|----------|------------|-----------------------------------------------------------------------------------------------------|
 | database                         | string | yes      | -          | The name 
of Doris database                                                               
           |
 | table                            | string | yes      | -          | The name 
of Doris table                                                                  
           |
-| doris.read.field                 | string | no       | -          | Use the 
'doris.read.field' parameter to select the doris table columns to read          
            |
-| doris.filter.query               | string | no       | -          | Data 
filtering in doris. the format is "field = value",example : doris.filter.query 
= "F_ID > 2"    |
+| doris.read.field                 | string | no       | -          | Use the 
'doris.read.field' parameter to select the doris table columns to read. Column 
names are quoted automatically, so write them unquoted. |
+| doris.filter.query               | string | no       | -          | Data 
filtering in doris. The format is "field = value",example : doris.filter.query 
= "F_ID > 2". The value is passed to Doris unchanged, so keyword or 
special-character column names must be backtick-quoted here, for example 
``doris.filter.query = "`from` > 1"``. |
 | doris.request.tablet.size        | int    | no       | Integer.MAX_VALUE | 
The number of Doris tablets grouped into each SeaTunnel split for this table. 
The minimum value is `1`. |
 | doris.batch.size                 | int    | no       | 1024       | The 
maximum value that can be obtained by reading Doris BE once.                    
                |
 | doris.exec.mem.limit             | long   | no       | 2147483648 | Maximum 
memory that can be used by a single be scan request. The default memory is 2G 
(2147483648). |
@@ -158,7 +158,7 @@ sink {
 }
 ```
 
-Use 'doris.filter.query' to filter the data, and the parameter values are 
passed directly to doris
+Use 'doris.filter.query' to filter the data, and the parameter values are 
passed directly to doris. Keyword column names must be backtick-quoted, for 
example ``doris.filter.query = "`from` > 1"``.
 
 ```
 env {
diff --git a/docs/zh/connectors/source/Doris.md 
b/docs/zh/connectors/source/Doris.md
index 5e2a958416..016acbd561 100644
--- a/docs/zh/connectors/source/Doris.md
+++ b/docs/zh/connectors/source/Doris.md
@@ -88,8 +88,8 @@ import ChangeLog from '../changelog/connector-doris.md';
 
|----------------------------------|--------|----------|------------|-----------------------------------------------------------------------------------------------------|
 | database                         | string | yes      | -          | 数据库      
                                                                                
         |
 | table                            | string | yes      | -          | 表名       
                                                                                
         |
-| doris.read.field                 | string | no       | -          | 
选择要读取的Doris表字段                                                                  
              |
-| doris.filter.query               | string | no       | -          | 数据过滤. 
格式:"字段 = 值", 例如:doris.filter.query = "F_ID > 2"                                 
      |
+| doris.read.field                 | string | no       | -          | 
选择要读取的Doris表字段。列名会自动加引号,填写裸名即可。 |
+| doris.filter.query               | string | no       | -          | 数据过滤. 
格式:"字段 = 值", 例如:doris.filter.query = "F_ID > 2"。该值原样传给 
Doris,关键字或特殊字符列名在这里必须用反引号括起,例如 ``doris.filter.query = "`from` > 1"``。 |
 | doris.request.tablet.size        | int    | no       | Integer.MAX_VALUE | 
当前表每个 SeaTunnel split 包含的 Doris tablet 数量,最小值为 `1`。                             
 |
 | doris.batch.size                 | int    | no       | 1024       | 
每次能够从BE中读取到的最大行数                                                                
           |
 | doris.exec.mem.limit             | long   | no       | 2147483648 | 
单个be扫描请求可以使用的最大内存。默认内存为2G(2147483648)                                           
     |
@@ -158,7 +158,7 @@ sink {
 }
 ```
 
-使用`doris.filter.query`来过滤数据,参数值将作为过滤条件直接传递到doris:
+使用`doris.filter.query`来过滤数据,参数值将作为过滤条件直接传递到doris。关键字列名需用反引号括起,例如 
``doris.filter.query = "`from` > 1"``。
 
 ```
 env {
diff --git 
a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
 
b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
index edc5d608a7..3bd0a2d131 100644
--- 
a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
+++ 
b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
@@ -31,6 +31,7 @@ import 
org.apache.seatunnel.connectors.doris.exception.DorisConnectorException;
 import org.apache.seatunnel.connectors.doris.rest.models.QueryPlan;
 import org.apache.seatunnel.connectors.doris.rest.models.Tablet;
 import org.apache.seatunnel.connectors.doris.source.DorisSourceTable;
+import org.apache.seatunnel.connectors.doris.util.DorisCatalogUtil;
 import org.apache.seatunnel.connectors.doris.util.ErrorMessages;
 
 import org.apache.commons.io.IOUtils;
@@ -62,6 +63,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 @Slf4j
 public class RestService implements Serializable {
@@ -276,23 +278,8 @@ public class RestService implements Serializable {
                 dorisSourceTable.getTablePath().getDatabaseName()
                         + "."
                         + dorisSourceTable.getTablePath().getTableName();
-        SeaTunnelRowType rowType = 
dorisSourceTable.getCatalogTable().getSeaTunnelRowType();
         String[] tableIdentifiers = parseIdentifier(tableIdentifier, logger);
-        String readFields = "*";
-        if (rowType.getFieldNames().length != 0) {
-            readFields = String.join(",", rowType.getFieldNames());
-        }
-        String sql =
-                "select "
-                        + readFields
-                        + " from `"
-                        + tableIdentifiers[0]
-                        + "`.`"
-                        + tableIdentifiers[1]
-                        + "`";
-        if (!StringUtils.isEmpty(dorisSourceTable.getFilterQuery())) {
-            sql += " where " + dorisSourceTable.getFilterQuery();
-        }
+        String sql = buildQuerySql(dorisSourceTable, tableIdentifiers[0], 
tableIdentifiers[1]);
         logger.debug("Query SQL Sending to Doris FE is: '{}'.", sql);
 
         String entity = "{\"sql\": \"" + sql + "\"}";
@@ -338,6 +325,32 @@ public class RestService implements Serializable {
                 logger);
     }
 
+    /**
+     * Builds the SQL that is sent to the Doris FE query plan API.
+     *
+     * <p>The read fields are the raw field names of the catalog table. Each 
field is quoted on its
+     * own with {@link DorisCatalogUtil#quoteIdentifier}, which wraps it in 
backticks and doubles
+     * any embedded backtick. When the catalog table has no fields, the 
projection falls back to
+     * {@code select *}. The filter query is caller-supplied SQL and is 
appended unchanged after
+     * {@code where}. When the filter query is empty, no {@code where} clause 
is added.
+     */
+    @VisibleForTesting
+    static String buildQuerySql(DorisSourceTable dorisSourceTable, String 
database, String table) {
+        SeaTunnelRowType rowType = 
dorisSourceTable.getCatalogTable().getSeaTunnelRowType();
+        String readFields = "*";
+        if (rowType.getFieldNames().length != 0) {
+            readFields =
+                    Arrays.stream(rowType.getFieldNames())
+                            .map(DorisCatalogUtil::quoteIdentifier)
+                            .collect(Collectors.joining(","));
+        }
+        String sql = "select " + readFields + " from `" + database + "`.`" + 
table + "`";
+        if (!StringUtils.isEmpty(dorisSourceTable.getFilterQuery())) {
+            sql += " where " + dorisSourceTable.getFilterQuery();
+        }
+        return sql;
+    }
+
     @VisibleForTesting
     static QueryPlan getQueryPlan(String response, Logger logger) throws 
DorisConnectorException {
         ObjectMapper mapper = new ObjectMapper();
diff --git 
a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/util/DorisCatalogUtil.java
 
b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/util/DorisCatalogUtil.java
index 2ca95a0dd3..0863d9f104 100644
--- 
a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/util/DorisCatalogUtil.java
+++ 
b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/util/DorisCatalogUtil.java
@@ -117,7 +117,7 @@ public class DorisCatalogUtil {
     }
 
     /** Quotes a Doris identifier and escapes embedded backticks. */
-    private static String quoteIdentifier(String identifier) {
+    public static String quoteIdentifier(String identifier) {
         return "`" + identifier.replace("`", "``") + "`";
     }
 
diff --git 
a/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java
 
b/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java
index 9a6bf770b8..948a22638d 100644
--- 
a/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java
+++ 
b/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java
@@ -18,8 +18,16 @@
 package org.apache.seatunnel.connectors.doris.rest;
 
 import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.Column;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+import org.apache.seatunnel.api.table.catalog.TableIdentifier;
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.type.BasicType;
 import org.apache.seatunnel.connectors.doris.config.DorisSourceConfig;
 import org.apache.seatunnel.connectors.doris.exception.DorisConnectorException;
+import org.apache.seatunnel.connectors.doris.source.DorisSourceTable;
 
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
@@ -41,11 +49,15 @@ import java.io.OutputStream;
 import java.net.InetSocketAddress;
 import java.net.SocketTimeoutException;
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 public class RestServiceTest {
 
@@ -133,6 +145,40 @@ public class RestServiceTest {
         assertReadTimeoutFailsFast(request);
     }
 
+    @Test
+    void quotesReadFieldsThatAreDorisKeywords() {
+        // Column names taken from the doris.read.field value reported in 
issue 13369. Doris FE
+        // rejected the unquoted "From" column with a parse error, so every 
projected column must
+        // be wrapped in backticks.
+        DorisSourceTable table =
+                sourceTable(Arrays.asList("Date", "Version", "From", "desc", 
"to", "system"), null);
+
+        Assertions.assertEquals(
+                "select `Date`,`Version`,`From`,`desc`,`to`,`system` from 
`test`.`test`",
+                RestService.buildQuerySql(table, "test", "test"));
+    }
+
+    @Test
+    void escapesBackticksInsideReadFields() {
+        // A backtick inside a quoted Doris identifier is written as two 
backticks, the same rule
+        // DorisCatalogUtil already applies to partition names.
+        DorisSourceTable table = sourceTable(Collections.singletonList("a`b"), 
null);
+
+        Assertions.assertEquals(
+                "select `a``b` from `db`.`tbl`", 
RestService.buildQuerySql(table, "db", "tbl"));
+    }
+
+    @Test
+    void keepsStarProjectionAndFilterQueryWhenSchemaIsEmpty() {
+        // An empty schema keeps the original "select *" projection, and the 
user filter query is
+        // appended unchanged.
+        DorisSourceTable table = sourceTable(Collections.emptyList(), "`from` 
> 1");
+
+        Assertions.assertEquals(
+                "select * from `db`.`tbl` where `from` > 1",
+                RestService.buildQuerySql(table, "db", "tbl"));
+    }
+
     private String queryPlanUrl() {
         return "http://127.0.0.1:"; + server.getAddress().getPort() + 
QUERY_PLAN_PATH;
     }
@@ -155,4 +201,31 @@ public class RestServiceTest {
                         + elapsedMs
                         + "ms");
     }
+
+    private static DorisSourceTable sourceTable(List<String> columnNames, 
String filterQuery) {
+        List<Column> columns =
+                columnNames.stream()
+                        .map(
+                                name ->
+                                        PhysicalColumn.of(
+                                                name,
+                                                BasicType.STRING_TYPE,
+                                                (Long) null,
+                                                true,
+                                                null,
+                                                null))
+                        .collect(Collectors.toList());
+        CatalogTable catalogTable =
+                CatalogTable.of(
+                        TableIdentifier.of("doris", "db", "tbl"),
+                        TableSchema.builder().columns(columns).build(),
+                        Collections.emptyMap(),
+                        Collections.emptyList(),
+                        "");
+        return DorisSourceTable.builder()
+                .tablePath(TablePath.of("db", "tbl"))
+                .catalogTable(catalogTable)
+                .filterQuery(filterQuery)
+                .build();
+    }
 }
diff --git 
a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java
 
b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java
index f789186f21..ff9261c168 100644
--- 
a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java
+++ 
b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java
@@ -75,6 +75,7 @@ public class DorisIT extends AbstractDorisIT {
     private static final String DUPLICATE_TABLE = "doris_duplicate_table";
     private static final String sourceDB = "e2e_source";
     private static final String sinkDB = "e2e_sink";
+    private static final String KEYWORD_COLUMN_TABLE = 
"doris_keyword_column_table";
     private static final String TZ_UNSET_TABLE = "doris_tz_unset";
     private static final String TZ_EXPLICIT_TABLE = "doris_tz_explicit";
     private static final OffsetDateTime TZ_SOURCE_VALUE =
@@ -331,6 +332,46 @@ public class DorisIT extends AbstractDorisIT {
                 0, exitCode, "failed to update the container INPUT chain: " + 
output);
     }
 
+    @TestTemplate
+    public void testReadKeywordColumns(TestContainer container)
+            throws IOException, InterruptedException, SQLException {
+        // Issue 13369: Doris FE rejected the source query plan SQL when a 
read field such as
+        // "from" was a Doris keyword. The Assert sink checks the single 
seeded row below.
+        initializeJdbcTable();
+        try {
+            try (Statement statement = conn.createStatement()) {
+                statement.execute(
+                        String.format(
+                                "create table if not exists `%s`.`%s`(\n"
+                                        + "`id` int not null,\n"
+                                        + "`from` varchar(32) null,\n"
+                                        + "`desc` varchar(32) null,\n"
+                                        + "`to` int null,\n"
+                                        + "`system` varchar(32) null\n"
+                                        + ")\n"
+                                        + "DUPLICATE KEY(`id`)\n"
+                                        + "DISTRIBUTED BY HASH(`id`) BUCKETS 
1\n"
+                                        + "properties(\n"
+                                        + "\"replication_allocation\" = 
\"tag.location.default: 1\""
+                                        + ");",
+                                sourceDB, KEYWORD_COLUMN_TABLE));
+                // A run killed before the finally block can leave a row 
behind. Truncate it so
+                // the Assert sink still sees exactly one row.
+                statement.execute(
+                        String.format("truncate table `%s`.`%s`", sourceDB, 
KEYWORD_COLUMN_TABLE));
+                statement.execute(
+                        String.format(
+                                "insert into `%s`.`%s` values (1, 'beijing', 
'first', 7, 'erp')",
+                                sourceDB, KEYWORD_COLUMN_TABLE));
+            }
+            Container.ExecResult execResult =
+                    
container.executeJob("/doris_source_keyword_columns_to_assert.conf");
+            Assertions.assertEquals(0, execResult.getExitCode(), 
execResult.getStderr());
+        } finally {
+            dropTable(sourceDB, KEYWORD_COLUMN_TABLE);
+        }
+    }
+
     @TestTemplate
     public void testTimestampTzZoneWarning(TestContainer container)
             throws IOException, InterruptedException {
diff --git 
a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/resources/doris_source_keyword_columns_to_assert.conf
 
b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/resources/doris_source_keyword_columns_to_assert.conf
new file mode 100644
index 0000000000..5ecd31bbd7
--- /dev/null
+++ 
b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/resources/doris_source_keyword_columns_to_assert.conf
@@ -0,0 +1,107 @@
+#
+# 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.
+#
+
+env {
+  parallelism = 1
+  job.mode = "BATCH"
+}
+
+source {
+  Doris {
+    fenodes = "doris_e2e:8030"
+    username = root
+    password = ""
+    table_list = [
+      {
+        database = "e2e_source"
+        table = "doris_keyword_column_table"
+        doris.read.field = "id,from,desc,to,system"
+      }
+    ]
+  }
+}
+
+transform {}
+
+sink {
+  Assert {
+    rules = {
+      row_rules = [
+        {
+          rule_type = MAX_ROW
+          rule_value = 1
+        },
+        {
+          rule_type = MIN_ROW
+          rule_value = 1
+        }
+      ]
+      field_rules = [
+        {
+          field_name = "id"
+          field_type = int
+          field_value = [
+            {
+              rule_type = NOT_NULL
+              equals_to = 1
+            }
+          ]
+        },
+        {
+          field_name = "from"
+          field_type = string
+          field_value = [
+            {
+              rule_type = NOT_NULL
+              equals_to = "beijing"
+            }
+          ]
+        },
+        {
+          field_name = "desc"
+          field_type = string
+          field_value = [
+            {
+              rule_type = NOT_NULL
+              equals_to = "first"
+            }
+          ]
+        },
+        {
+          field_name = "to"
+          field_type = int
+          field_value = [
+            {
+              rule_type = NOT_NULL
+              equals_to = 7
+            }
+          ]
+        },
+        {
+          field_name = "system"
+          field_type = string
+          field_value = [
+            {
+              rule_type = NOT_NULL
+              equals_to = "erp"
+            }
+          ]
+        }
+      ]
+    }
+  }
+}

Reply via email to