github-actions[bot] commented on code in PR #62242: URL: https://github.com/apache/doris/pull/62242#discussion_r3061743575
########## 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: This hard-casts every array's nested storage to `ColumnNullable`, but Doris still produces plain `ColumnArray(nested->create_column(), ...)` for non-nullable `Array<T>` in `DataTypeArray::create_column()`, and the old `extract_column_array_info()` handled both shapes. That means `array_join(Array<String>)` / `l2_distance(Array<Float>, ...)` now regress on ordinary non-nullable arrays. ########## 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 { Review Comment: `ColumnElementView::get_data()` returns `nullptr` when the flattened nested column is empty. This method then does pointer arithmetic on that null pointer. `FunctionArrayDistance` now calls `get_data()` for every row, so inputs like `[]` / `const([])` can hit UB here even though the previous implementation used `PaddedPODArray::data()` and stayed valid for empty arrays. -- 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]
