HappenLee commented on a change in pull request #7601: URL: https://github.com/apache/incubator-doris/pull/7601#discussion_r779354519
########## File path: be/src/vec/functions/function_grouping_id.h ########## @@ -0,0 +1,76 @@ +// 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. + +#ifndef DORIS_FUNCTION_GROUPING_ID_H +#define DORIS_FUNCTION_GROUPING_ID_H + +#include "vec/functions/simple_function_factory.h" +#include "vec/columns/column_nullable.h" +#include "vec/functions/function_helpers.h" +#include "vec/utils/util.hpp" +#include "vec/data_types/get_least_supertype.h" + +namespace doris::vectorized { +class FunctionGroupingId : public IFunction { +public: + static constexpr auto name = "grouping_id"; + + static FunctionPtr create() { return std::make_shared<FunctionGroupingId>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + bool use_default_implementation_for_constants() const override { return false; } + + bool use_default_implementation_for_nulls() const override { return false; } + + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + return std::make_shared<DataTypeInt64>(); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + if (arguments.size() != 1) + return Status::InternalError("Illegal number of parameters"); + + const ColumnWithTypeAndName& src_column = block.get_by_position(arguments[0]); + const ColumnWithTypeAndName& rel_column = block.get_by_position(result); + if (!src_column.column) + return Status::InternalError("Illegal column " + src_column.column->get_name() + " of first argument of function " + name); + + bool src_is_nullable = src_column.type->is_nullable(); + TypeIndex src_typeid = src_column.type->get_type_id(); + TypeIndex res_typeid = rel_column.type->get_type_id(); + if (res_typeid != TypeIndex::Int64) + return Status::InternalError("Return type is not int64 of function grouping_id"); + + MutableColumnPtr res_column = rel_column.type->create_column(); + if (src_is_nullable) { Review comment: the argument may nullable ? maybe we should promise the argument is not nullable and DCHECK here ########## File path: be/src/vec/functions/function_grouping_id.h ########## @@ -0,0 +1,76 @@ +// 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. + +#ifndef DORIS_FUNCTION_GROUPING_ID_H +#define DORIS_FUNCTION_GROUPING_ID_H + +#include "vec/functions/simple_function_factory.h" +#include "vec/columns/column_nullable.h" +#include "vec/functions/function_helpers.h" +#include "vec/utils/util.hpp" +#include "vec/data_types/get_least_supertype.h" + +namespace doris::vectorized { +class FunctionGroupingId : public IFunction { Review comment: the funcion GroupingId and Grouping is similar, you should do a union abstruct. like other funcion maybe the FunctionToNoNullableOneArgument ########## File path: be/src/vec/functions/function_grouping_id.h ########## @@ -0,0 +1,76 @@ +// 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. + +#ifndef DORIS_FUNCTION_GROUPING_ID_H +#define DORIS_FUNCTION_GROUPING_ID_H + +#include "vec/functions/simple_function_factory.h" +#include "vec/columns/column_nullable.h" +#include "vec/functions/function_helpers.h" +#include "vec/utils/util.hpp" +#include "vec/data_types/get_least_supertype.h" + +namespace doris::vectorized { +class FunctionGroupingId : public IFunction { +public: + static constexpr auto name = "grouping_id"; + + static FunctionPtr create() { return std::make_shared<FunctionGroupingId>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + bool use_default_implementation_for_constants() const override { return false; } + + bool use_default_implementation_for_nulls() const override { return false; } + + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + return std::make_shared<DataTypeInt64>(); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + if (arguments.size() != 1) Review comment: No Need Check here, you set `get_number_of_arguments()` == 1 ########## File path: be/src/vec/functions/function_grouping_id.h ########## @@ -0,0 +1,76 @@ +// 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. + +#ifndef DORIS_FUNCTION_GROUPING_ID_H +#define DORIS_FUNCTION_GROUPING_ID_H + +#include "vec/functions/simple_function_factory.h" +#include "vec/columns/column_nullable.h" +#include "vec/functions/function_helpers.h" +#include "vec/utils/util.hpp" +#include "vec/data_types/get_least_supertype.h" + +namespace doris::vectorized { +class FunctionGroupingId : public IFunction { +public: + static constexpr auto name = "grouping_id"; + + static FunctionPtr create() { return std::make_shared<FunctionGroupingId>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + bool use_default_implementation_for_constants() const override { return false; } + + bool use_default_implementation_for_nulls() const override { return false; } + + DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { + return std::make_shared<DataTypeInt64>(); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + if (arguments.size() != 1) + return Status::InternalError("Illegal number of parameters"); + + const ColumnWithTypeAndName& src_column = block.get_by_position(arguments[0]); + const ColumnWithTypeAndName& rel_column = block.get_by_position(result); + if (!src_column.column) + return Status::InternalError("Illegal column " + src_column.column->get_name() + " of first argument of function " + name); + + bool src_is_nullable = src_column.type->is_nullable(); + TypeIndex src_typeid = src_column.type->get_type_id(); + TypeIndex res_typeid = rel_column.type->get_type_id(); + if (res_typeid != TypeIndex::Int64) Review comment: no need check here, FE will promise the argment is bigint ########## File path: fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java ########## @@ -1070,6 +1070,16 @@ private PlanNode createRepeatNodePlan(SelectStmt selectStmt, Analyzer analyzer, && groupingInfo != null); root = new RepeatNode(ctx_.getNextNodeId(), root, groupingInfo, groupByClause); root.init(analyzer); + // set agg outtuple nullable + AggregateInfo aggInfo = selectStmt.getAggInfo(); + TupleId aggOutTupleId = aggInfo.getOutputTupleId(); + TupleDescriptor aggOutTupleDescriptor = analyzer.getDescTbl().getTupleDesc(aggOutTupleId); + int aggregateExprStartIndex = groupByClause.getGroupingExprs().size(); + for (int i = 0; i < aggregateExprStartIndex; ++i) { + SlotDescriptor slot = aggOutTupleDescriptor.getSlots().get(i); + if (!slot.getIsNullable()) + slot.setIsNullable(true); Review comment: why change the slot nullable ? give a problem case please -- 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]
