-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Feature](func) Support INTERVAL function and fix EXPORT_SET constant process #58885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
linrrzqqq
wants to merge
5
commits into
apache:master
Choose a base branch
from
linrrzqqq:interval
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // 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 <algorithm> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "common/status.h" | ||
| #include "runtime/define_primitive_type.h" | ||
| #include "runtime/primitive_type.h" | ||
| #include "vec/columns/column.h" | ||
| #include "vec/columns/column_const.h" | ||
| #include "vec/columns/column_nullable.h" | ||
| #include "vec/columns/column_vector.h" | ||
| #include "vec/common/assert_cast.h" | ||
| #include "vec/core/block.h" | ||
| #include "vec/core/column_numbers.h" | ||
| #include "vec/core/column_with_type_and_name.h" | ||
| #include "vec/core/types.h" | ||
| #include "vec/data_types/data_type.h" | ||
| #include "vec/data_types/data_type_number.h" | ||
| #include "vec/functions/function.h" | ||
| #include "vec/functions/function_needs_to_handle_null.h" | ||
| #include "vec/functions/simple_function_factory.h" | ||
|
|
||
| namespace doris::vectorized { | ||
| class FunctionIntervalImpl { | ||
| public: | ||
| static constexpr auto name = "interval"; | ||
| static size_t get_number_of_arguments() { return 0; } | ||
| static bool is_variadic() { return true; } | ||
| static DataTypePtr get_return_type_impl(const DataTypes& /*arguments*/) { | ||
| return std::make_shared<DataTypeInt32>(); | ||
| } | ||
|
|
||
| static bool is_return_nullable(bool has_nullable, | ||
| const std::vector<ColumnWithConstAndNullMap>& cols_info) { | ||
| return false; | ||
| } | ||
|
|
||
| static bool execute_const_null(ColumnInt32::MutablePtr& res_col, | ||
| PaddedPODArray<UInt8>& res_null_map_data, | ||
| size_t input_rows_count, size_t null_index) { | ||
| if (null_index == 0) { | ||
| res_col->insert_many_vals(-1, input_rows_count); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static void collect_columns_info(std::vector<ColumnWithConstAndNullMap>& columns_info, | ||
| Block& block, const ColumnNumbers& arguments, | ||
| bool& has_nullable) { | ||
| const size_t arg_size = arguments.size(); | ||
| std::vector<ColumnPtr> arg_col(arg_size); | ||
| std::vector<uint8_t> is_const(arg_size); | ||
| std::vector<size_t> param_idx(arg_size - 1); | ||
| bool all_const = true; | ||
| for (size_t i = 0; i < arg_size; ++i) { | ||
| is_const[i] = is_column_const(*block.get_by_position(arguments[i]).column); | ||
| if (i != 0) { | ||
| param_idx[i - 1] = i; | ||
| all_const = all_const & is_const[i]; | ||
| } | ||
| } | ||
| arg_col[0] = is_const[0] ? assert_cast<const ColumnConst&>( | ||
| *block.get_by_position(arguments[0]).column) | ||
| .get_data_column_ptr() | ||
| : block.get_by_position(arguments[0]).column; | ||
| default_preprocess_parameter_columns(arg_col.data(), | ||
| reinterpret_cast<const bool*>(is_const.data()), | ||
| param_idx, block, arguments); | ||
|
|
||
| // The second parameter's `is_const` is used to indicate whether all the parameters are constants. | ||
| columns_info[0].is_const = is_const[0]; | ||
| columns_info[1].is_const = all_const; | ||
| for (size_t i = 0; i < arguments.size(); ++i) { | ||
| ColumnPtr col_ptr = arg_col[i]; | ||
| columns_info[i].type = block.get_by_position(arguments[i]).type; | ||
| columns_info[i].column = col_ptr; | ||
|
|
||
| if (const auto* nullable = check_and_get_column<ColumnNullable>(col_ptr.get())) { | ||
| has_nullable = true; | ||
| columns_info[i].nested_col = &nullable->get_nested_column(); | ||
| columns_info[i].null_map = &nullable->get_null_map_data(); | ||
| } else { | ||
| columns_info[i].nested_col = col_ptr.get(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static void execute(const std::vector<ColumnWithConstAndNullMap>& columns_info, | ||
| ColumnInt32::MutablePtr& res_col, PaddedPODArray<UInt8>& res_null_map_data, | ||
| size_t input_rows_count) { | ||
| res_col->resize(input_rows_count); | ||
| const auto& compare_data = | ||
| assert_cast<const ColumnInt64&>(*columns_info[0].nested_col).get_data(); | ||
| const size_t num_thresholds = columns_info.size() - 1; | ||
|
|
||
| for (size_t row = 0; row < input_rows_count; ++row) { | ||
| if (columns_info[0].is_null_at(row)) { | ||
| res_col->get_data()[row] = -1; | ||
| continue; | ||
| } | ||
|
|
||
| // Determine whether all the threshold columns are constant columns. | ||
| size_t row_idx = columns_info[1].is_const ? 0 : row; | ||
| auto compare_val = compare_data[index_check_const(row, columns_info[0].is_const)]; | ||
| std::vector<int64_t> thresholds; | ||
| thresholds.reserve(num_thresholds); | ||
|
|
||
| for (size_t i = 1; i < columns_info.size(); ++i) { | ||
| const auto& th_col = assert_cast<const ColumnInt64&>(*columns_info[i].nested_col); | ||
| thresholds.push_back( | ||
| columns_info[i].is_null_at(row_idx) ? 0 : th_col.get_data()[row_idx]); | ||
| } | ||
|
|
||
| auto it = std::upper_bound(thresholds.begin(), thresholds.end(), compare_val); | ||
| res_col->get_data()[row] = static_cast<Int32>(it - thresholds.begin()); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| void register_function_interval(SimpleFunctionFactory& factory) { | ||
| factory.register_function<FunctionNeedsToHandleNull<FunctionIntervalImpl, TYPE_INT>>(); | ||
| } | ||
|
|
||
| } // namespace doris::vectorized | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1690,6 +1690,7 @@ functionNameIdentifier | |
| | CURRENT_USER | ||
| | DATABASE | ||
| | IF | ||
| | INTERVAL | ||
| | LEFT | ||
| | LIKE | ||
| | PASSWORD | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...e/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Interval.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // 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. | ||
|
|
||
| package org.apache.doris.nereids.trees.expressions.functions.scalar; | ||
|
|
||
| import org.apache.doris.catalog.FunctionSignature; | ||
| import org.apache.doris.nereids.trees.expressions.Expression; | ||
| import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; | ||
| import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; | ||
| import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
| import org.apache.doris.nereids.types.BigIntType; | ||
| import org.apache.doris.nereids.types.IntegerType; | ||
| import org.apache.doris.nereids.util.ExpressionUtils; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * ScalarFunction 'interval'. | ||
| */ | ||
| public class Interval extends ScalarFunction implements ExplicitlyCastableSignature, AlwaysNotNullable { | ||
|
|
||
| public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
| FunctionSignature.ret(IntegerType.INSTANCE).varArgs(BigIntType.INSTANCE, BigIntType.INSTANCE)); | ||
|
|
||
| public Interval(Expression arg, Expression... varArgs) { | ||
| super("interval", ExpressionUtils.mergeArguments(arg, varArgs)); | ||
| } | ||
|
|
||
| @Override | ||
| public Interval withChildren(List<Expression> children) { | ||
| Preconditions.checkArgument(children.size() >= 2); | ||
| return new Interval(children.get(0), children.subList(1, children.size()).toArray(new Expression[0])); | ||
| } | ||
|
|
||
| @Override | ||
| public List<FunctionSignature> getSignatures() { | ||
| return SIGNATURES; | ||
| } | ||
|
|
||
| @Override | ||
| public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
| return visitor.visitInterval(this, context); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
利用这一套似乎并没有怎么简化代码。就自己手工处理下const和nullable就行了吧?