-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Feature](datatype) update be ut codes and opt datatype for IPv4/v6 #28648
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -348,4 +348,108 @@ class FunctionIPv6NumToString : public IFunction { | |||||
| } | ||||||
| }; | ||||||
|
|
||||||
| class FunctionIsIPv4String : public IFunction { | ||||||
| private: | ||||||
| Status execute_type(Block& block, const ColumnWithTypeAndName& argument, size_t result) const { | ||||||
| const ColumnPtr& column = argument.column; | ||||||
|
|
||||||
| if (const auto* col_src = typeid_cast<const ColumnString*>(column.get())) { | ||||||
| auto col_res = ColumnInt8::create(); | ||||||
|
|
||||||
| for (size_t i = 0; i < col_src->size(); ++i) { | ||||||
| auto ipv4_str = col_src->get_data_at(i).to_string(); | ||||||
| if (ipv4_str.size() > IPV4_MAX_TEXT_LENGTH || !IPv4Value::is_valid_string(ipv4_str)) { | ||||||
| col_res->insert_value(0); | ||||||
| } else { | ||||||
| col_res->insert_value(1); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| DCHECK_EQ(col_res->size(), col_src->size()); | ||||||
|
|
||||||
| block.replace_by_position( | ||||||
| result, ColumnNullable::create(std::move(col_res), ColumnUInt8::create(col_src->size(), 0))); | ||||||
| return Status::OK(); | ||||||
| } | ||||||
|
|
||||||
| return Status::RuntimeError("Illegal column {} of argument of function {}", | ||||||
| argument.column->get_name(), get_name()); | ||||||
| } | ||||||
|
|
||||||
| public: | ||||||
| static constexpr auto name = "isipv4string"; | ||||||
| static FunctionPtr create() { | ||||||
| return std::make_shared<FunctionIsIPv4String>(); | ||||||
| } | ||||||
|
|
||||||
| String get_name() const override { return name; } | ||||||
|
|
||||||
| size_t get_number_of_arguments() const override { return 1; } | ||||||
|
|
||||||
| DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: method 'get_return_type_impl' can be made static [readability-convert-member-functions-to-static]
Suggested change
|
||||||
| return make_nullable(std::make_shared<DataTypeInt8>()); | ||||||
| } | ||||||
|
|
||||||
| bool use_default_implementation_for_nulls() const override { return true; } | ||||||
|
|
||||||
| Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, | ||||||
| size_t result, size_t input_rows_count) const override { | ||||||
| ColumnWithTypeAndName& argument = block.get_by_position(arguments[0]); | ||||||
| DCHECK(argument.type->get_type_id() == TypeIndex::String); | ||||||
| return execute_type(block, argument, result); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| class FunctionIsIPv6String : public IFunction { | ||||||
| private: | ||||||
| Status execute_type(Block& block, const ColumnWithTypeAndName& argument, size_t result) const { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: method 'execute_type' can be made static [readability-convert-member-functions-to-static]
Suggested change
|
||||||
| const ColumnPtr& column = argument.column; | ||||||
|
|
||||||
| if (const auto* col_src = typeid_cast<const ColumnString*>(column.get())) { | ||||||
| auto col_res = ColumnInt8::create(); | ||||||
|
|
||||||
| for (size_t i = 0; i < col_src->size(); ++i) { | ||||||
| auto ipv6_str = col_src->get_data_at(i).to_string(); | ||||||
| if (ipv6_str.size() > IPV6_MAX_TEXT_LENGTH || !IPv6Value::is_valid_string(ipv6_str)) { | ||||||
| col_res->insert_value(0); | ||||||
| } else { | ||||||
| col_res->insert_value(1); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| DCHECK_EQ(col_res->size(), col_src->size()); | ||||||
|
|
||||||
| block.replace_by_position( | ||||||
| result, ColumnNullable::create(std::move(col_res), ColumnUInt8::create(col_src->size(), 0))); | ||||||
| return Status::OK(); | ||||||
| } | ||||||
|
|
||||||
| return Status::RuntimeError("Illegal column {} of argument of function {}", | ||||||
| argument.column->get_name(), get_name()); | ||||||
| } | ||||||
|
|
||||||
| public: | ||||||
| static constexpr auto name = "isipv6string"; | ||||||
| static FunctionPtr create() { | ||||||
| return std::make_shared<FunctionIsIPv6String>(); | ||||||
| } | ||||||
|
|
||||||
| String get_name() const override { return name; } | ||||||
|
|
||||||
| size_t get_number_of_arguments() const override { return 1; } | ||||||
|
|
||||||
| DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: method 'get_return_type_impl' can be made static [readability-convert-member-functions-to-static]
Suggested change
|
||||||
| return make_nullable(std::make_shared<DataTypeInt8>()); | ||||||
| } | ||||||
|
|
||||||
| bool use_default_implementation_for_nulls() const override { return true; } | ||||||
|
|
||||||
| Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, | ||||||
| size_t result, size_t input_rows_count) const override { | ||||||
| ColumnWithTypeAndName& argument = block.get_by_position(arguments[0]); | ||||||
| DCHECK(argument.type->get_type_id() == TypeIndex::String); | ||||||
| return execute_type(block, argument, result); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| } // namespace doris::vectorized | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // 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.AlwaysNullable; | ||
| import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; | ||
| import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; | ||
| import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
| import org.apache.doris.nereids.types.StringType; | ||
| import org.apache.doris.nereids.types.TinyIntType; | ||
| import org.apache.doris.nereids.types.VarcharType; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * scalar function IsIpv4String | ||
| */ | ||
| public class IsIpv4String extends ScalarFunction | ||
| implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { | ||
|
|
||
| public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
| FunctionSignature.ret(TinyIntType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT), | ||
| FunctionSignature.ret(TinyIntType.INSTANCE).args(StringType.INSTANCE)); | ||
|
|
||
| public IsIpv4String(Expression arg0) { | ||
| super("isipv4string", arg0); | ||
| } | ||
|
|
||
| @Override | ||
| public IsIpv4String withChildren(List<Expression> children) { | ||
| Preconditions.checkArgument(children.size() == 1, | ||
| "isipv4string accept 1 args, but got %s (%s)", | ||
| children.size(), | ||
| children); | ||
| return new IsIpv4String(children.get(0)); | ||
| } | ||
|
|
||
| @Override | ||
| public List<FunctionSignature> getSignatures() { | ||
| return SIGNATURES; | ||
| } | ||
|
|
||
| @Override | ||
| public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
| return visitor.visitIsIpv4String(this, context); | ||
| } | ||
| } |
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.
warning: method 'execute_type' can be made static [readability-convert-member-functions-to-static]