github-actions[bot] commented on code in PR #64864: URL: https://github.com/apache/doris/pull/64864#discussion_r3476642032
########## be/test/exprs/aggregate/agg_window_nth_value_test.cpp: ########## @@ -0,0 +1,81 @@ +// 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. + +#include <gtest/gtest.h> + +#include "core/column/column_nullable.h" +#include "core/column/column_string.h" +#include "core/column/column_vector.h" +#include "core/data_type/data_type_number.h" +#include "core/data_type/data_type_string.h" +#include "exprs/aggregate/aggregate_function.h" +#include "exprs/aggregate/aggregate_function_simple_factory.h" + +namespace doris { + +void register_aggregate_function_window_lead_lag_first_last( + AggregateFunctionSimpleFactory& factory); + +TEST(AggregateWindowNthValueTest, UpperBoundedLowerUnboundedFrame) { + AggregateFunctionSimpleFactory factory; + register_aggregate_function_window_lead_lag_first_last(factory); + + DataTypes argument_types = {std::make_shared<DataTypeString>(), + std::make_shared<DataTypeInt64>()}; + auto function = factory.get("nth_value", argument_types, nullptr, true, -1, + {.is_window_function = true, .column_names = {}}); + ASSERT_NE(function, nullptr); + + auto value_column = ColumnString::create(); + value_column->insert_data("C", 1); + value_column->insert_data("B", 1); + value_column->insert_data("A", 1); + + auto offset_column = ColumnInt64::create(); + offset_column->insert_value(-2); + + const IColumn* columns[] = {value_column.get(), offset_column.get()}; + + Arena arena; + auto* place = reinterpret_cast<AggregateDataPtr>(arena.alloc(function->size_of_data())); + function->create(place); + + auto result_column = ColumnNullable::create(ColumnString::create(), ColumnUInt8::create()); + UInt8 use_null_result = false; + UInt8 could_use_previous_result = false; + + function->add_range_single_place(0, 3, 0, 1, place, columns, arena, &use_null_result, + &could_use_previous_result); + function->insert_result_into(place, *result_column); + + function->add_range_single_place(0, 3, 0, 2, place, columns, arena, &use_null_result, Review Comment: The direct test does not mirror the executor protocol for this window shape. After FE reverses `ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING`, `_get_next_for_unbounded_rows()` feeds `nth_value` only the newly added range (`current_row_end - 1, current_row_end`) on each row. This test instead calls `[0,1)`, then `[0,2)`, then `[0,3)`. With the implementation above, `_frame_total_rows` becomes `1`, then `3`, then `6`, so offset `-2` reads position `1` (`"B"`) for the second result and later goes past the three-row input, rather than producing the expected `"C"`/`"B"`. Please change the test to feed the same delta ranges as the analytic executor (for example `[0,1)`, `[1,2)`, `[2,3)`) or reset state between full-frame evaluations; otherwise the added BE UT will fail when it is run. -- 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]
