This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new fb67aa56f0e [fix](jdbc) Reject unsupported scan column types before
execution (branch-4.2) (#71243)
fb67aa56f0e is described below
commit fb67aa56f0e641b4743120ca8e1fd24483ef9f1b
Author: Gabriel <[email protected]>
AuthorDate: Wed Dec 2 10:12:21 2026 +0800
[fix](jdbc) Reject unsupported scan column types before execution
(branch-4.2) (#71243)
### Background
JDBC catalogs expose external schemas that can include types Doris
cannot read. Queries such as `COUNT(*)` do not reference a source
column, but the physical scan still needs one column to preserve row
counts.
### What problem does this PR solve?
Issue Number: None
Related PR: #71242 (same fix on master), #41548 (introduced the
constant-projection path)
PR Type: Bugfix
Problem Summary:
`COUNT(*)` on a PostgreSQL table containing only unsupported columns can
send `UNSUPPORTED` slot metadata to BE and abort it during descriptor
construction. Select a supported fallback column when available and
otherwise report an analysis error; validate serialized slots and reject
unsupported metadata on BE as well. Most changed lines add coverage.
Supported projections from mixed schemas continue to work.
### Details
- **Change map:** 58 production lines and 351 test/result lines. FE
selection and serialization checks account for 40 production lines; BE
descriptor validation accounts for 18.
- **Frequency:** Always for a column-free scan over an unsupported-only
schema; PostgreSQL built-in `oid`, `name`, and `regnamespace` types
reproduce it without extensions.
- **Root cause:** A constant projection hides source column types from
logical expression checks. `getSmallestSlot` can retain an unsupported
scan column, whose BE datatype construction reaches a fatal type switch.
- **Why existing tests missed it:** `CountStarSmallestSlotTest` and
`SlotDescriptorTest` cover valid column metadata. PostgreSQL
catalog/type suites cover readable types and arrays containing NULL,
without an unsupported-only count scan.
- **Fix:** Exclude recursively unsupported fallback types, check the
actual serialized slot, and return a BE error before constructing its
datatype. Check specifically for `UNSUPPORTED` so legitimate types such
as `ARRAY<NULL>` remain accepted.
- **Other paths and branches:** The shared scan/descriptor checks also
cover other external scans and requests from older FEs, in both
deployment modes. The master companion uses its newer descriptor
converter; this branch validates slots in `SlotDescriptor.toThrift()`.
`branch-4.1` shares the path but is not included here. Other release
branches were not checked.
- **Behavior change:** Unsupported-only scans report an error instead of
crashing BE; supported fallback ordering is preserved. No protocol or
configuration changes.
### Testing
- Locally passed 32 FE tests, including six new slot-validation tests
and 19 existing COUNT(*) tests. The new FE tests failed three cases
before the fix.
- Locally passed 13 descriptor tests under ASAN. The baseline BE test
reproduced the fatal unsupported-type check.
- PostgreSQL 15 regression suite `test_pg_jdbc_unsupported_scan_types`:
12 query expectations, generation and comparison both passed without
skips. Covers unsupported-only scans, explicit unsupported projections,
mixed schemas, source casts, and subsequent queries.
- FE Checkstyle, clang-format 16, clang-tidy, and local review passed.
All review findings were fixed and re-reviewed.
### Release note
JDBC queries that retain an unsupported scan column now report a
descriptive error instead of crashing a BE. Queries using supported
columns from mixed schemas continue to work.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: Codex (GPT-6); GPT-6 Astra for local review.
- Generated: Implementation, tests, and this description.
- Human review: None reported in this session.
- Prompts: Fix both master and branch-4.2, add unit and regression
coverage, and resolve all local review findings before opening the pull
requests.
---
be/src/runtime/descriptors.cpp | 18 ++++
be/test/runtime/descriptor_test.cpp | 99 +++++++++++++++++
.../main/java/org/apache/doris/catalog/Type.java | 18 ++++
.../org/apache/doris/analysis/SlotDescriptor.java | 6 ++
.../glue/translator/PhysicalPlanTranslator.java | 16 ++-
.../translator/ScanSlotTypeValidationTest.java | 118 +++++++++++++++++++++
.../jdbc/test_pg_jdbc_unsupported_scan_types.out | 25 +++++
.../test_pg_jdbc_unsupported_scan_types.groovy | 109 +++++++++++++++++++
8 files changed, 406 insertions(+), 3 deletions(-)
diff --git a/be/src/runtime/descriptors.cpp b/be/src/runtime/descriptors.cpp
index 91756d5cec5..54721835b5d 100644
--- a/be/src/runtime/descriptors.cpp
+++ b/be/src/runtime/descriptors.cpp
@@ -642,6 +642,19 @@ int RowDescriptor::get_column_id(int slot_id) const {
return -1;
}
+static bool slot_type_contains_unsupported(const TTypeDesc& type) {
+ // Array, map and struct children share the flattened type-node list.
+ for (const auto& node : type.types) {
+ if (node.type == TTypeNodeType::SCALAR &&
+ node.scalar_type.type == TPrimitiveType::UNSUPPORTED) {
+ return true;
+ }
+ }
+ // Aggregate-state inputs are stored as separate type descriptors.
+ return std::any_of(type.sub_types.begin(), type.sub_types.end(),
+ slot_type_contains_unsupported);
+}
+
Status DescriptorTbl::create(ObjectPool* pool, const TDescriptorTable&
thrift_tbl,
DescriptorTbl** tbl) {
*tbl = pool->add(new DescriptorTbl());
@@ -710,6 +723,11 @@ Status DescriptorTbl::create(ObjectPool* pool, const
TDescriptorTable& thrift_tb
}
for (const auto& tdesc : thrift_tbl.slotDescriptors) {
+ // Older FEs can retain an unsupported fallback column for COUNT(*).
+ if (slot_type_contains_unsupported(tdesc.slotType)) {
+ return Status::NotSupported("Unsupported type UNSUPPORTED for slot
{} (column '{}')",
+ tdesc.id, tdesc.colName);
+ }
SlotDescriptor* slot_d = pool->add(new SlotDescriptor(tdesc));
(*tbl)->_slot_desc_map[tdesc.id] = slot_d;
diff --git a/be/test/runtime/descriptor_test.cpp
b/be/test/runtime/descriptor_test.cpp
index 0a665cfc34c..182dfd3971a 100644
--- a/be/test/runtime/descriptor_test.cpp
+++ b/be/test/runtime/descriptor_test.cpp
@@ -22,6 +22,7 @@
#include <gtest/gtest.h>
#include "common/exception.h"
+#include "common/object_pool.h"
#include "runtime/descriptors.h"
namespace doris {
@@ -86,6 +87,104 @@ TEST_F(SlotDescriptorTest, BasicConstructor) {
});
}
+TEST_F(SlotDescriptorTest, RejectUnsupportedSlotType) {
+ auto slot = create_basic_slot_descriptor(7, "unsupported_column");
+ slot.slotType.types[0].scalar_type.__set_type(TPrimitiveType::UNSUPPORTED);
+ TTupleDescriptor tuple;
+ tuple.__set_id(1);
+ TDescriptorTable thrift_table;
+ thrift_table.__set_tupleDescriptors({tuple});
+ thrift_table.__set_slotDescriptors({slot});
+ ObjectPool pool;
+ DescriptorTbl* table = nullptr;
+ auto status = DescriptorTbl::create(&pool, thrift_table, &table);
+ ASSERT_FALSE(status.ok());
+ EXPECT_NE(status.to_string().find("UNSUPPORTED"), std::string::npos);
+ EXPECT_NE(status.to_string().find("unsupported_column"),
std::string::npos);
+ EXPECT_NE(status.to_string().find("7"), std::string::npos);
+}
+
+TEST_F(SlotDescriptorTest, RejectUnsupportedNestedSlotTypes) {
+ for (auto nested_type : {TTypeNodeType::ARRAY, TTypeNodeType::MAP,
TTypeNodeType::STRUCT}) {
+ auto slot = create_basic_slot_descriptor();
+ auto unsupported = slot.slotType.types[0];
+ unsupported.scalar_type.__set_type(TPrimitiveType::UNSUPPORTED);
+ TTypeNode root;
+ root.__set_type(nested_type);
+ if (nested_type == TTypeNodeType::ARRAY) {
+ root.__set_contains_nulls({true});
+ }
+ if (nested_type == TTypeNodeType::MAP) {
+ root.__set_contains_nulls({true, true});
+ slot.slotType.__set_types({root, slot.slotType.types[0],
unsupported});
+ } else {
+ if (nested_type == TTypeNodeType::STRUCT) {
+ TStructField field;
+ field.__set_name("nested_column");
+ field.__set_contains_null(true);
+ root.__set_struct_fields({field});
+ }
+ slot.slotType.__set_types({root, unsupported});
+ }
+ TTupleDescriptor tuple;
+ tuple.__set_id(1);
+ TDescriptorTable thrift_table;
+ thrift_table.__set_tupleDescriptors({tuple});
+ thrift_table.__set_slotDescriptors({slot});
+ ObjectPool pool;
+ DescriptorTbl* table = nullptr;
+ EXPECT_FALSE(DescriptorTbl::create(&pool, thrift_table, &table).ok());
+
+ for (auto& node : slot.slotType.types) {
+ if (node.type == TTypeNodeType::SCALAR &&
+ node.scalar_type.type == TPrimitiveType::UNSUPPORTED) {
+ node.scalar_type.__set_type(TPrimitiveType::INT);
+ }
+ }
+ thrift_table.__set_slotDescriptors({slot});
+ EXPECT_TRUE(DescriptorTbl::create(&pool, thrift_table, &table).ok());
+ }
+}
+
+TEST_F(SlotDescriptorTest, RejectUnsupportedAggregateStateInput) {
+ auto slot = create_basic_slot_descriptor();
+ auto unsupported = slot.slotType;
+ unsupported.types[0].scalar_type.__set_type(TPrimitiveType::UNSUPPORTED);
+ slot.slotType.types[0].scalar_type.__set_type(TPrimitiveType::AGG_STATE);
+ slot.slotType.__set_sub_types({unsupported});
+ slot.slotType.__set_function_name("sum");
+ slot.slotType.__set_result_is_nullable(true);
+ TTupleDescriptor tuple;
+ tuple.__set_id(1);
+ TDescriptorTable thrift_table;
+ thrift_table.__set_tupleDescriptors({tuple});
+ thrift_table.__set_slotDescriptors({slot});
+ ObjectPool pool;
+ DescriptorTbl* table = nullptr;
+ EXPECT_FALSE(DescriptorTbl::create(&pool, thrift_table, &table).ok());
+}
+
+TEST_F(SlotDescriptorTest, ValidDescriptorAfterUnsupportedDescriptor) {
+ auto slot = create_basic_slot_descriptor();
+ slot.slotType.types[0].scalar_type.__set_type(TPrimitiveType::UNSUPPORTED);
+ TTupleDescriptor tuple;
+ tuple.__set_id(1);
+ TDescriptorTable thrift_table;
+ thrift_table.__set_tupleDescriptors({tuple});
+ thrift_table.__set_slotDescriptors({slot});
+ ObjectPool pool;
+ DescriptorTbl* table = nullptr;
+ ASSERT_FALSE(DescriptorTbl::create(&pool, thrift_table, &table).ok());
+
+ for (auto scalar_type :
+ {TPrimitiveType::INT, TPrimitiveType::STRING,
TPrimitiveType::NULL_TYPE}) {
+ slot.slotType.types[0].scalar_type.__set_type(scalar_type);
+ thrift_table.__set_slotDescriptors({slot});
+ ASSERT_TRUE(DescriptorTbl::create(&pool, thrift_table, &table).ok());
+ ASSERT_NE(table->get_slot_descriptor(slot.id), nullptr);
+ }
+}
+
TEST_F(SlotDescriptorTest, VirtualColumnExprValid) {
// Test constructor with valid virtual column expression
TSlotDescriptor tdesc = create_basic_slot_descriptor();
diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
index 2963ea1d6a1..1858169be15 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
@@ -439,6 +439,24 @@ public abstract class Type {
return isScalarType(PrimitiveType.UNSUPPORTED);
}
+ /** Whether this type contains an external type that BE cannot execute. */
+ public boolean typeContainsUnsupported() {
+ // An external ARRAY<UNSUPPORTED>, for example, must not become a scan
fallback column.
+ if (isStructType()) {
+ return ((StructType) this).getFields().stream()
+ .anyMatch(field ->
field.getType().typeContainsUnsupported());
+ } else if (isMapType()) {
+ MapType mapType = (MapType) this;
+ return mapType.getKeyType().typeContainsUnsupported()
+ || mapType.getValueType().typeContainsUnsupported();
+ } else if (isArrayType()) {
+ return ((ArrayType) this).getItemType().typeContainsUnsupported();
+ } else if (isAggStateType()) {
+ return ((AggStateType)
this).getSubTypes().stream().anyMatch(Type::typeContainsUnsupported);
+ }
+ return isUnsupported();
+ }
+
public boolean isValid() {
return !isInvalid();
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotDescriptor.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotDescriptor.java
index ecb765be3c7..60fe209ae4f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotDescriptor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotDescriptor.java
@@ -23,6 +23,7 @@ package org.apache.doris.analysis;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.thrift.TColumnAccessPath;
import org.apache.doris.thrift.TSlotDescriptor;
@@ -207,6 +208,11 @@ public class SlotDescriptor {
// Non-nullable slots will have 0 for the byte offset and -1 for the
bit mask
String colName = materializedColumnName != null ?
materializedColumnName :
((column != null) ?
column.getNonShadowName() : "");
+ // Physical scan fallback columns are selected after the logical
expression type checks.
+ if (type.typeContainsUnsupported()) {
+ throw new AnalysisException("Cannot serialize slot " + id + "
(column '" + colName
+ + "') with unsupported type " + type.toSql());
+ }
TSlotDescriptor tSlotDescriptor = new TSlotDescriptor(id.asInt(),
parent.getId().asInt(), type.toThrift(), -1,
0, 0, getIsNullable() ? 0 : -1, colName, -1,
true);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index d14184a9ed6..369baabe366 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -3012,6 +3012,13 @@ public class PhysicalPlanTranslator extends
DefaultPlanVisitor<PlanFragment, Pla
SlotDescriptor smallest =
getSmallestSlot(scanNode.getTupleDesc().getSlots());
scanNode.getTupleDesc().getSlots().removeIf(s ->
!requiredWithVirtualColumns.contains(s.getId()));
if (scanNode.getTupleDesc().getSlots().isEmpty()) {
+ // COUNT(*) hides source types from expression checks, but BE
still constructs this scan slot.
+ if (smallest == null) {
+ TableIf table = scanNode.getTupleDesc().getTable();
+ throw new AnalysisException("No supported columns available to
scan "
+ + (table == null ? "tuple " +
scanNode.getTupleDesc().getId()
+ : "table '" + table.getName() + "'"));
+ }
scanNode.getTupleDesc().getSlots().add(smallest);
}
if (context.getSessionVariable() != null
@@ -3028,10 +3035,10 @@ public class PhysicalPlanTranslator extends
DefaultPlanVisitor<PlanFragment, Pla
}
/**
- * Get the smallest slot in the slot list.
+ * Get the smallest slot whose type has no unsupported fields.
*
* @param slots slot list
- * @return the smallest slot
+ * @return the smallest eligible slot, or null if none is available
*/
@VisibleForTesting
@Nullable
@@ -3039,7 +3046,10 @@ public class PhysicalPlanTranslator extends
DefaultPlanVisitor<PlanFragment, Pla
if (slots == null || slots.isEmpty()) {
return null;
}
- return Collections.min(slots, new SlotSizeComparator());
+ return slots.stream()
+ .filter(slot -> !slot.getType().typeContainsUnsupported())
+ .min(new SlotSizeComparator())
+ .orElse(null);
}
/**
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/ScanSlotTypeValidationTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/ScanSlotTypeValidationTest.java
new file mode 100644
index 00000000000..6ec7021eebd
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/ScanSlotTypeValidationTest.java
@@ -0,0 +1,118 @@
+// 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.doris.nereids.glue.translator;
+
+import org.apache.doris.analysis.DescriptorTable;
+import org.apache.doris.analysis.SlotDescriptor;
+import org.apache.doris.analysis.SlotId;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.analysis.TupleId;
+import org.apache.doris.catalog.AggStateType;
+import org.apache.doris.catalog.ArrayType;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.MapType;
+import org.apache.doris.catalog.StructField;
+import org.apache.doris.catalog.StructType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class ScanSlotTypeValidationTest {
+ private SlotDescriptor slot(int id, Type type) {
+ SlotDescriptor slot = new SlotDescriptor(new SlotId(id), new
TupleDescriptor(new TupleId(0)));
+ slot.setColumn(new Column("column_" + id, type));
+ return slot;
+ }
+
+ private List<Type> unsupportedTypes() {
+ return Arrays.asList(Type.UNSUPPORTED,
+ new ArrayType(Type.UNSUPPORTED),
+ new MapType(Type.INT, Type.UNSUPPORTED),
+ new MapType(Type.UNSUPPORTED, Type.STRING),
+ new StructType(new StructField("nested", Type.UNSUPPORTED)),
+ new ArrayType(new MapType(Type.STRING, new
ArrayType(Type.UNSUPPORTED))),
+ new AggStateType("sum", true,
Collections.singletonList(Type.UNSUPPORTED),
+ Collections.singletonList(true)));
+ }
+
+ @Test
+ public void testNoUnsupportedFallbackColumn() {
+ for (Type type : unsupportedTypes()) {
+ Assertions.assertNull(PhysicalPlanTranslator.getSmallestSlot(
+ Collections.singletonList(slot(1, type))), type.toSql());
+ }
+ }
+
+ @Test
+ public void testSupportedColumnSurvivesMixedSchema() {
+ for (Type type : unsupportedTypes()) {
+ SlotDescriptor supported = slot(2, Type.VARIANT);
+ Assertions.assertSame(supported,
PhysicalPlanTranslator.getSmallestSlot(
+ Arrays.asList(slot(1, type), supported)), type.toSql());
+ }
+ }
+
+ @Test
+ public void testSupportedFallbackOrderingIsUnchanged() {
+ SlotDescriptor integer = slot(3, Type.INT);
+ Assertions.assertSame(integer, PhysicalPlanTranslator.getSmallestSlot(
+ Arrays.asList(slot(1, Type.STRING), slot(2, Type.BIGINT),
integer)));
+
Assertions.assertNull(PhysicalPlanTranslator.getSmallestSlot(Collections.emptyList()));
+ }
+
+ @Test
+ public void testNullNestedTypesAreNotUnsupported() {
+ for (Type type : Arrays.asList(Type.NULL, new ArrayType(Type.NULL),
+ new MapType(Type.NULL, Type.NULL))) {
+ SlotDescriptor supported = slot(1, type);
+ Assertions.assertSame(supported,
PhysicalPlanTranslator.getSmallestSlot(
+ Collections.singletonList(supported)));
+ }
+ }
+
+ @Test
+ public void testRejectUnsupportedSerializedSlot() {
+ for (Type type : unsupportedTypes()) {
+ DescriptorTable table = new DescriptorTable();
+ TupleDescriptor tuple = table.createTupleDescriptor();
+ table.addSlotDescriptor(tuple).setColumn(new
Column("unsupported_column", type));
+ AnalysisException exception =
Assertions.assertThrows(AnalysisException.class,
+ () -> table.toThrift(), type.toSql());
+
Assertions.assertTrue(exception.getMessage().contains("unsupported_column"));
+
Assertions.assertTrue(exception.getMessage().contains("UNSUPPORTED"));
+ }
+ }
+
+ @Test
+ public void testPrunedUnsupportedSlotDoesNotBlockSerialization() {
+ DescriptorTable table = new DescriptorTable();
+ TupleDescriptor tuple = table.createTupleDescriptor();
+ SlotDescriptor unused = table.addSlotDescriptor(tuple);
+ unused.setColumn(new Column("unused_column", Type.UNSUPPORTED));
+ SlotDescriptor supported = table.addSlotDescriptor(tuple);
+ supported.setColumn(new Column("supported_column", Type.INT));
+ tuple.getSlots().remove(unused);
+ Assertions.assertEquals(1, table.toThrift().getSlotDescriptorsSize());
+ }
+}
diff --git
a/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_unsupported_scan_types.out
b/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_unsupported_scan_types.out
new file mode 100644
index 00000000000..2b8677e429f
--- /dev/null
+++
b/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_unsupported_scan_types.out
@@ -0,0 +1,25 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !mixed_projection --
+1 value
+2 \N
+
+-- !mixed_count --
+2
+
+-- !mixed_count_one --
+2
+
+-- !mixed_constant --
+1
+1
+
+-- !mixed_filter --
+2
+
+-- !source_cast_view --
+1 first
+2 second
+
+-- !query_after_rejection --
+2
+
diff --git
a/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_unsupported_scan_types.groovy
b/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_unsupported_scan_types.groovy
new file mode 100644
index 00000000000..71f2ae902f4
--- /dev/null
+++
b/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_unsupported_scan_types.groovy
@@ -0,0 +1,109 @@
+// 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.
+
+import java.sql.DriverManager
+
+suite("test_pg_jdbc_unsupported_scan_types", "p0,external") {
+ String enabled = context.config.otherConfigs.get("enableJdbcTest")
+ if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+ return
+ }
+
+ String host = context.config.otherConfigs.get("externalEnvIp")
+ String port = context.config.otherConfigs.get("pg_14_port")
+ String user = context.config.otherConfigs.get("pgUser", "postgres")
+ String password = context.config.otherConfigs.get("pgPassword", "123456")
+ String jdbcUrl = "jdbc:postgresql://${host}:${port}/postgres?useSSL=false"
+ String driverUrl = context.config.otherConfigs.get("pgDriverUrl",
+
"https://${getS3BucketName()}.${getS3Endpoint()}/regression/jdbc_driver/postgresql-42.5.0.jar")
+
+ Class.forName("org.postgresql.Driver")
+ def connection = DriverManager.getConnection(jdbcUrl, user, password)
+ try {
+ def statement = connection.createStatement()
+ try {
+ statement.execute("DROP SCHEMA IF EXISTS unsupported_scan_test
CASCADE")
+ statement.execute("CREATE SCHEMA unsupported_scan_test")
+ // PostgreSQL built-in types reproduce the unsupported mapping
without an extension.
+ statement.execute("""CREATE TABLE
unsupported_scan_test.unsupported_only (
+ unsupported_oid oid, unsupported_name name,
unsupported_namespace regnamespace)""")
+ statement.execute("""INSERT INTO
unsupported_scan_test.unsupported_only VALUES
+ (1, 'first', 'pg_catalog'::regnamespace), (2, 'second',
'pg_catalog'::regnamespace)""")
+ statement.execute("""CREATE TABLE
unsupported_scan_test.mixed_types (
+ unsupported_name name, supported_id integer, supported_text
text)""")
+ statement.execute("""INSERT INTO unsupported_scan_test.mixed_types
VALUES
+ ('first', 1, 'value'), ('second', 2, NULL)""")
+ statement.execute("""CREATE VIEW
unsupported_scan_test.compatible_view AS
+ SELECT unsupported_oid::bigint AS object_id,
unsupported_name::text AS object_name
+ FROM unsupported_scan_test.unsupported_only""")
+ } finally {
+ statement.close()
+ }
+ } finally {
+ connection.close()
+ }
+
+ sql "DROP CATALOG IF EXISTS pg_unsupported_scan_catalog"
+ sql """CREATE CATALOG pg_unsupported_scan_catalog PROPERTIES (
+ "type" = "jdbc",
+ "user" = "${user}",
+ "password" = "${password}",
+ "jdbc_url" = "${jdbcUrl}¤tSchema=unsupported_scan_test",
+ "driver_url" = "${driverUrl}",
+ "driver_class" = "org.postgresql.Driver"
+ )"""
+
+ // These queries reference no source columns, but the scan still needs a
fallback slot.
+ [
+ "SELECT COUNT(*) FROM
pg_unsupported_scan_catalog.unsupported_scan_test.unsupported_only",
+ "SELECT COUNT(1) FROM
pg_unsupported_scan_catalog.unsupported_scan_test.unsupported_only",
+ "SELECT 1 FROM
pg_unsupported_scan_catalog.unsupported_scan_test.unsupported_only LIMIT 1"
+ ].each { query ->
+ test {
+ sql query
+ exception "No supported columns"
+ }
+ }
+
+ test {
+ sql """SELECT unsupported_oid
+ FROM
pg_unsupported_scan_catalog.unsupported_scan_test.unsupported_only LIMIT 1"""
+ exception "UNSUPPORTED"
+ }
+ test {
+ sql """SELECT unsupported_name
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types
LIMIT 1"""
+ exception "UNSUPPORTED"
+ }
+
+ // A pruned unsupported column must not reject a supported projection or
row count.
+ order_qt_mixed_projection """SELECT supported_id, supported_text
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types
ORDER BY supported_id"""
+ order_qt_mixed_count """SELECT COUNT(*)
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types"""
+ order_qt_mixed_count_one """SELECT COUNT(1)
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types"""
+ order_qt_mixed_constant """SELECT 1
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types"""
+ order_qt_mixed_filter """SELECT supported_id
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types
+ WHERE supported_id > 1 ORDER BY supported_id"""
+ order_qt_source_cast_view """SELECT object_id, object_name
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.compatible_view
ORDER BY object_id"""
+ order_qt_query_after_rejection """SELECT COUNT(*)
+ FROM pg_unsupported_scan_catalog.unsupported_scan_test.mixed_types"""
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]