-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Feature](datatype) add be ut codes for IPv4/v6 #26534
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||||
| #include <arrow/builder.h> | ||||||||||
|
|
||||||||||
| #include "vec/columns/column_const.h" | ||||||||||
| #include "vec/io/io_helper.h" | ||||||||||
|
|
||||||||||
| namespace doris { | ||||||||||
| namespace vectorized { | ||||||||||
|
|
@@ -61,5 +62,31 @@ Status DataTypeIPv4SerDe::write_column_to_mysql(const IColumn& column, | |||||||||
| return _write_column_to_mysql(column, row_buffer, row_idx, col_const); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Status DataTypeIPv4SerDe::serialize_one_cell_to_json(const IColumn& column, int row_num, | ||||||||||
|
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 'serialize_one_cell_to_json' can be made static [readability-convert-member-functions-to-static]
Suggested change
be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:66: - FormatOptions& options) const {
+ FormatOptions& options) { |
||||||||||
| BufferWritable& bw, | ||||||||||
| FormatOptions& options) const { | ||||||||||
| auto result = check_column_const_set_readability(column, row_num); | ||||||||||
| ColumnPtr ptr = result.first; | ||||||||||
| row_num = result.second; | ||||||||||
| IPv4 data = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num); | ||||||||||
| IPv4Value ipv4_value(data); | ||||||||||
| std::string ipv4_str = ipv4_value.to_string(); | ||||||||||
| bw.write(ipv4_str.c_str(), ipv4_str.length()); | ||||||||||
| return Status::OK(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Status DataTypeIPv4SerDe::deserialize_one_cell_from_json(IColumn& column, Slice& slice, | ||||||||||
| const FormatOptions& options) const { | ||||||||||
|
Comment on lines
+78
to
+79
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 'deserialize_one_cell_from_json' can be made static [readability-convert-member-functions-to-static]
Suggested change
|
||||||||||
| auto& column_data = reinterpret_cast<ColumnIPv4&>(column); | ||||||||||
| ReadBuffer rb(slice.data, slice.size); | ||||||||||
| IPv4 val = 0; | ||||||||||
| if (!read_ipv4_text_impl(val, rb)) { | ||||||||||
| return Status::InvalidArgument("parse ipv4 fail, string: '{}'", | ||||||||||
| std::string(rb.position(), rb.count()).c_str()); | ||||||||||
| } | ||||||||||
| column_data.insert_value(val); | ||||||||||
| return Status::OK(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } // namespace vectorized | ||||||||||
| } // namespace doris | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,10 @@ class DataTypeIPv4SerDe : public DataTypeNumberSerDe<IPv4> { | |
| int row_idx, bool col_const) const override; | ||
| Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer<false>& row_buffer, | ||
| int row_idx, bool col_const) const override; | ||
| Status serialize_one_cell_to_json(const IColumn& column, int row_num, BufferWritable& bw, | ||
|
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. why here has impl serialize_column_to_json/deserialize_column_from_json |
||
| FormatOptions& options) const override; | ||
| Status deserialize_one_cell_from_json(IColumn& column, Slice& slice, | ||
| const FormatOptions& options) const override; | ||
|
|
||
| private: | ||
| template <bool is_binary_format> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||||
| #include <arrow/builder.h> | ||||||||||
|
|
||||||||||
| #include "vec/columns/column_const.h" | ||||||||||
| #include "vec/io/io_helper.h" | ||||||||||
|
|
||||||||||
| namespace doris { | ||||||||||
| namespace vectorized { | ||||||||||
|
|
@@ -61,5 +62,31 @@ Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column, | |||||||||
| return _write_column_to_mysql(column, row_buffer, row_idx, col_const); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Status DataTypeIPv6SerDe::serialize_one_cell_to_json(const IColumn& column, int row_num, | ||||||||||
|
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 'serialize_one_cell_to_json' can be made static [readability-convert-member-functions-to-static]
Suggested change
be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:66: - FormatOptions& options) const {
+ FormatOptions& options) { |
||||||||||
| BufferWritable& bw, | ||||||||||
| FormatOptions& options) const { | ||||||||||
| auto result = check_column_const_set_readability(column, row_num); | ||||||||||
| ColumnPtr ptr = result.first; | ||||||||||
| row_num = result.second; | ||||||||||
| IPv6 data = assert_cast<const ColumnIPv6&>(*ptr).get_element(row_num); | ||||||||||
| IPv6Value ipv6_value(data); | ||||||||||
| std::string ipv6_str = ipv6_value.to_string(); | ||||||||||
| bw.write(ipv6_str.c_str(), ipv6_str.length()); | ||||||||||
| return Status::OK(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Status DataTypeIPv6SerDe::deserialize_one_cell_from_json(IColumn& column, Slice& slice, | ||||||||||
| const FormatOptions& options) const { | ||||||||||
|
Comment on lines
+78
to
+79
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 'deserialize_one_cell_from_json' can be made static [readability-convert-member-functions-to-static]
Suggested change
|
||||||||||
| auto& column_data = reinterpret_cast<ColumnIPv6&>(column); | ||||||||||
| ReadBuffer rb(slice.data, slice.size); | ||||||||||
| IPv6 val = 0; | ||||||||||
| if (!read_ipv6_text_impl(val, rb)) { | ||||||||||
| return Status::InvalidArgument("parse ipv6 fail, string: '{}'", | ||||||||||
| std::string(rb.position(), rb.count()).c_str()); | ||||||||||
| } | ||||||||||
| column_data.insert_value(val); | ||||||||||
| return Status::OK(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } // namespace vectorized | ||||||||||
| } // namespace doris | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,8 @@ | |
| #include "vec/data_types/data_type_date_time.h" | ||
| #include "vec/data_types/data_type_decimal.h" | ||
| #include "vec/data_types/data_type_hll.h" | ||
| #include "vec/data_types/data_type_ipv4.h" | ||
| #include "vec/data_types/data_type_ipv6.h" | ||
| #include "vec/data_types/data_type_map.h" | ||
| #include "vec/data_types/data_type_nullable.h" | ||
| #include "vec/data_types/data_type_number.h" | ||
|
|
@@ -98,6 +100,8 @@ void serialize_and_deserialize_arrow_test() { | |
| {"k5", FieldType::OLAP_FIELD_TYPE_DECIMAL32, 5, TYPE_DECIMAL32, false}, | ||
| {"k6", FieldType::OLAP_FIELD_TYPE_DECIMAL64, 6, TYPE_DECIMAL64, false}, | ||
| {"k12", FieldType::OLAP_FIELD_TYPE_DATETIMEV2, 12, TYPE_DATETIMEV2, false}, | ||
| {"k8", FieldType::OLAP_FIELD_TYPE_IPV4, 8, TYPE_IPV4, false}, | ||
|
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: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] {"k8", FieldType::OLAP_FIELD_TYPE_IPV4, 8, TYPE_IPV4, false},
^ |
||
| {"k9", FieldType::OLAP_FIELD_TYPE_IPV6, 9, TYPE_IPV6, false}, | ||
|
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: 9 is a magic number; consider replacing it with a named constant [readability-magic-numbers] {"k9", FieldType::OLAP_FIELD_TYPE_IPV6, 9, TYPE_IPV6, false},
^ |
||
| }; | ||
| } else { | ||
| cols = {{"a", FieldType::OLAP_FIELD_TYPE_ARRAY, 6, TYPE_ARRAY, true}, | ||
|
|
@@ -445,6 +449,34 @@ void serialize_and_deserialize_arrow_test() { | |
| block.insert(type_and_name); | ||
| } | ||
| break; | ||
| case TYPE_IPV4: | ||
| tslot.__set_slotType(type_desc.to_thrift()); | ||
| { | ||
| auto vec = vectorized::ColumnIPv4::create(); | ||
| auto& data = vec->get_data(); | ||
| for (int i = 0; i < row_num; ++i) { | ||
| data.push_back(i); | ||
| } | ||
| vectorized::DataTypePtr data_type(std::make_shared<vectorized::DataTypeIPv4>()); | ||
| vectorized::ColumnWithTypeAndName type_and_name(vec->get_ptr(), data_type, | ||
| col_name); | ||
| block.insert(std::move(type_and_name)); | ||
| } | ||
| break; | ||
| case TYPE_IPV6: | ||
| tslot.__set_slotType(type_desc.to_thrift()); | ||
| { | ||
| auto vec = vectorized::ColumnIPv6::create(); | ||
| auto& data = vec->get_data(); | ||
| for (int i = 0; i < row_num; ++i) { | ||
| data.push_back(i); | ||
| } | ||
| vectorized::DataTypePtr data_type(std::make_shared<vectorized::DataTypeIPv6>()); | ||
| vectorized::ColumnWithTypeAndName type_and_name(vec->get_ptr(), data_type, | ||
| col_name); | ||
| block.insert(std::move(type_and_name)); | ||
| } | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
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: 0xFFFFFFFF is a magic number; consider replacing it with a named constant [readability-magic-numbers]