github-actions[bot] commented on code in PR #64007:
URL: https://github.com/apache/doris/pull/64007#discussion_r3339484291
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalView.java:
##########
@@ -121,16 +122,21 @@ public List<Slot> computeOutput() {
List<Slot> childOutput = child().getOutput();
ImmutableList.Builder<Slot> currentOutput = ImmutableList.builder();
List<String> fullQualifiers = this.view.getFullQualifiers();
+ List<Column> fullSchema = view.getFullSchema();
for (int i = 0; i < childOutput.size(); i++) {
Slot originSlot = childOutput.get(i);
Slot qualified;
// ATTN: because bug intro by #40715, after replace view, full
schema will be empty or null.
// So, we must just here to avoid NPE or out of bound exception.
- if (CollectionUtils.isEmpty(view.getFullSchema())) {
+ // Also guard against schema drift: when the underlying external
table (e.g. Hive) gains
+ // new columns after the view was created and REFRESH TABLE is
called, childOutput may
+ // have more slots than fullSchema (which still reflects the
schema at view-creation
+ // time). Fall back to qualifier-only for the extra columns to
avoid IndexOutOfBoundsException.
+ if (CollectionUtils.isEmpty(fullSchema) || i >= fullSchema.size())
{
qualified = originSlot.withQualifier(fullQualifiers);
Review Comment:
This avoids the exception by exposing every slot produced by the re-analyzed
child, including slots past the stored view schema. For a persisted view,
`view.getFullSchema()` is the view's output contract (it is built from
`CreateViewInfo.finalCols` at create/replace time), so after a base table gains
a column this makes `SELECT * FROM view` return a column that is not in `DESC
view` / the view metadata and is not decorated as a view column. The same
mismatch affects external views because `ExternalView.getFullSchema()`
delegates to the external view schema while the body can be re-expanded against
newer base-table columns. Please preserve the stored schema width when it is
present (or fail with a view-schema mismatch) instead of appending
qualifier-only extra child slots.
##########
regression-test/suites/external_table_p0/hive/test_hive_view_schema_drift.groovy:
##########
@@ -0,0 +1,104 @@
+// 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.
+
+// Regression test for: LogicalView.computeOutput() IndexOutOfBoundsException
when
+// an underlying Hive table gains new columns (schema drift) after the view
was created.
+//
+// Repro:
+// 1. Create Hive table with N columns; create a Doris view (SELECT *) on it.
+// 2. ADD COLUMN to the Hive table.
+// 3. REFRESH TABLE base_table in Doris (view schema not refreshed yet).
+// 4. Query the view → used to crash with "Index 3 out of bounds for length
3"
+// because LogicalView.computeOutput() iterated childOutput (4 slots from
+// re-analyzed view body) but called view.getFullSchema().get(i) on a
+// 3-element list (view's schema at creation time).
+
+suite("test_hive_view_schema_drift", "p0,external,hive_docker") {
+
+ String enabled = context.config.otherConfigs.get("enableHiveTest")
+ if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+ logger.info("disable Hive test.")
+ return;
+ }
+
+ for (String hivePrefix : ["hive2", "hive3"]) {
+ setHivePrefix(hivePrefix)
+ String hms_port = context.config.otherConfigs.get(hivePrefix +
"HmsPort")
+ String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+ String catalog_name = "test_${hivePrefix}_view_schema_drift"
+ String db = "test_view_schema_drift_db"
+ String base_table = "test_view_schema_drift_base"
+ String view_name = "test_view_schema_drift_view"
+
+ try {
+ // ---- Setup Hive catalog ----
+ sql """drop catalog if exists ${catalog_name}"""
+ sql """CREATE CATALOG ${catalog_name} PROPERTIES (
+ 'type'='hms',
+ 'hive.metastore.uris' =
'thrift://${externalEnvIp}:${hms_port}',
+ 'hadoop.username' = 'hive'
+ )"""
+
+ // ---- Create Hive database and base table with 3 columns ----
+ hive_docker """drop database if exists ${db} cascade"""
+ hive_docker """create database ${db}"""
+ hive_docker """
+ create table ${db}.${base_table} (
+ id bigint,
+ name string,
+ age string
+ )
+ partitioned by (dt string)
+ stored as parquet
+ """
+
+ // ---- Create Doris view on the Hive table ----
+ sql """switch ${catalog_name}"""
+ sql """use ${db}"""
+ sql """create view ${view_name} as select * from ${base_table}
where 1=1"""
+
Review Comment:
This setup switches to the HMS external catalog and then creates an
unqualified Doris view there. `CreateViewInfo.init()` rejects external catalogs
via `Util.prohibitExternalCatalog(viewName.getCtl(), "CreateViewCommand")`, so
the test fails at `create view` and never exercises the intended
`LogicalView.computeOutput()` drift path. Create the Doris view in an internal
catalog while referencing the Hive table with a fully qualified external name,
or create an actual Hive view through `hive_docker` and query that external
view from Doris.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]