github-actions[bot] commented on code in PR #62242:
URL: https://github.com/apache/doris/pull/62242#discussion_r3077682248


##########
be/src/core/column/column_array_view.h:
##########
@@ -0,0 +1,114 @@
+// 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.
+
+#pragma once
+
+#include "core/column/column_array.h"
+#include "core/column/column_execute_util.h"
+
+namespace doris {
+
+// ArrayDataView represents a read-only view of a single row's array data
+// (a slice of ColumnArray's flat nested data).
+// Used as the return type of ColumnArrayView::operator[].
+template <PrimitiveType PType>
+struct ArrayDataView {
+    using ElementType = typename ColumnElementView<PType>::ElementType;
+
+    const ColumnElementView<PType>& data;
+    const NullMap& nested_null_map;
+    const size_t offset;
+    const size_t length;
+
+    size_t size() const { return length; }
+
+    const ElementType* get_data() const {
+        const ElementType* raw_data = data.get_data();
+        return raw_data + offset;
+    }
+
+    // ColumnArray's data column is always Nullable, no need to check nullptr
+    bool is_null_at(size_t idx) const { return nested_null_map[offset + idx]; }
+
+    ElementType value_at(size_t idx) const { return data.get_element(offset + 
idx); }
+};
+
+// ColumnArrayView provides a read-only view over a column of 
Array<scalar_type>,
+// handling Const / Nullable wrapping automatically.
+//
+// Supports index-based access: operator[](row) returns ArrayDataView, uses 
offsets[row-1] (sentinel)
+template <PrimitiveType PType>
+struct ColumnArrayView {
+    const ColumnElementView<PType> element_data;
+    const ColumnArray::Offsets64& offsets;
+    const NullMap* outer_null_map;
+    const NullMap& nested_null_map;
+    const bool is_const;
+    const size_t count;
+
+    static ColumnArrayView create(const ColumnPtr& column_ptr) {
+        // Step 1: unpack const
+        const auto& [unpacked, is_const] = unpack_if_const(column_ptr);
+
+        // Step 2: unpack outer nullable
+        const NullMap* outer_null_map = nullptr;
+        const IColumn* array_raw = nullptr;
+        if (const auto* nullable = 
check_and_get_column<ColumnNullable>(unpacked.get())) {
+            outer_null_map = &nullable->get_null_map_data();
+            array_raw = nullable->get_nested_column_ptr().get();
+        } else {
+            array_raw = unpacked.get();
+        }
+
+        // Step 3: get ColumnArray
+        const auto& array_column = assert_cast<const ColumnArray&>(*array_raw);
+
+        // Step 4: unpack inner nullable (data column is always Nullable)
+        const auto& nested_nullable = assert_cast<const 
ColumnNullable&>(array_column.get_data());

Review Comment:
   `ColumnArray` does not guarantee that its nested payload is always 
`ColumnNullable`. `DataTypeArray::create_column()` still builds 
`ColumnArray::create(nested->create_column(), ...)`, so `Array<T NOT NULL>` 
reaches BE with a plain nested column, and the previous implementations handled 
that shape explicitly. This unconditional `assert_cast<const ColumnNullable&>` 
therefore regresses existing valid inputs: for example the 
`array_join(..._notnull)` regression cases now crash/fail as soon as they hit 
`ColumnArrayView::create()`. The helper needs to preserve both layouts, e.g. by 
checking whether `array_column.get_data()` is nullable and only wiring 
`nested_null_map` when it actually exists.



-- 
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]

Reply via email to