Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions be/src/vec/data_types/serde/data_type_ipv6_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,21 @@ Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column,
}

void DataTypeIPv6SerDe::read_one_cell_from_jsonb(IColumn& column, const JsonbValue* arg) const {
IPv6 val = 0;
const auto* str_value = static_cast<const JsonbStringVal*>(arg);
ReadBuffer rb(reinterpret_cast<const unsigned char*>(str_value->getBlob()),
str_value->getBlobLen());
if (!read_ipv6_text_impl(val, rb)) {
throw doris::Exception(ErrorCode::INVALID_ARGUMENT, "parse ipv6 fail, string: '{}'",
rb.to_string());
}
assert_cast<ColumnIPv6&>(column).insert_value(val);
const auto* str_value = static_cast<const JsonbBinaryVal*>(arg);
column.deserialize_and_insert_from_arena(str_value->getBlob());
}

void DataTypeIPv6SerDe::write_one_cell_to_jsonb(const IColumn& column,
JsonbWriterT<JsonbOutStream>& result,
Arena* mem_pool, int col_id, int row_num) const {
// we make ipv6 as string in jsonb
// we make ipv6 as BinaryValue in jsonb
result.writeKey(col_id);
IPv6 data = assert_cast<const ColumnIPv6&>(column).get_element(row_num);
IPv6Value ipv6_value(data);
result.writeString(ipv6_value.to_string());
const char* begin = nullptr;
// maybe serialize_value_into_arena should move to here later.
StringRef value = column.serialize_value_into_arena(row_num, *mem_pool, begin);
result.writeStartBinary();
result.writeBinary(value.data, value.size);
result.writeEndBinary();
}

Status DataTypeIPv6SerDe::serialize_one_cell_to_json(const IColumn& column, int row_num,
Expand Down
62 changes: 62 additions & 0 deletions be/test/vec/data_types/serde/data_type_serde_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,66 @@ TEST(DataTypeSerDeTest, DataTypeScalaSerDeTest) {
serialize_and_deserialize_pb_test();
}

TEST(DataTypeSerDeTest, DataTypeRowStoreSerDeTest) {
// ipv6
{
std::string ip = "5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b";
auto vec = vectorized::ColumnVector<IPv6>::create();
IPv6Value ipv6;
EXPECT_TRUE(ipv6.from_string(ip));
vec->insert(ipv6.value());

vectorized::DataTypePtr data_type(std::make_shared<vectorized::DataTypeIPv6>());
auto serde = data_type->get_serde(0);
JsonbWriterT<JsonbOutStream> jsonb_writer;
Arena pool;
jsonb_writer.writeStartObject();
serde->write_one_cell_to_jsonb(*vec, jsonb_writer, &pool, 0, 0);
jsonb_writer.writeEndObject();
auto jsonb_column = ColumnString::create();
jsonb_column->insert_data(jsonb_writer.getOutput()->getBuffer(),
jsonb_writer.getOutput()->getSize());
StringRef jsonb_data = jsonb_column->get_data_at(0);
auto pdoc = JsonbDocument::createDocument(jsonb_data.data, jsonb_data.size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'auto pdoc' can be declared as 'auto *pdoc' [readability-qualified-auto]

Suggested change
auto pdoc = JsonbDocument::createDocument(jsonb_data.data, jsonb_data.size);
auto *pdoc = JsonbDocument::createDocument(jsonb_data.data, jsonb_data.size);

JsonbDocument& doc = *pdoc;
for (auto it = doc->begin(); it != doc->end(); ++it) {
serde->read_one_cell_from_jsonb(*vec, it->value());
}
EXPECT_TRUE(vec->size() == 2);
IPv6 data = vec->get_element(1);
IPv6Value ipv6_value(data);
EXPECT_EQ(ipv6_value.to_string(), ip);
}

// ipv4
{
std::string ip = "192.0.0.1";
auto vec = vectorized::ColumnVector<IPv4>::create();
IPv4Value ipv4;
EXPECT_TRUE(ipv4.from_string(ip));
vec->insert(ipv4.value());

vectorized::DataTypePtr data_type(std::make_shared<vectorized::DataTypeIPv4>());
auto serde = data_type->get_serde(0);
JsonbWriterT<JsonbOutStream> jsonb_writer;
Arena pool;
jsonb_writer.writeStartObject();
serde->write_one_cell_to_jsonb(*vec, jsonb_writer, &pool, 0, 0);
jsonb_writer.writeEndObject();
auto jsonb_column = ColumnString::create();
jsonb_column->insert_data(jsonb_writer.getOutput()->getBuffer(),
jsonb_writer.getOutput()->getSize());
StringRef jsonb_data = jsonb_column->get_data_at(0);
auto pdoc = JsonbDocument::createDocument(jsonb_data.data, jsonb_data.size);
JsonbDocument& doc = *pdoc;
for (auto it = doc->begin(); it != doc->end(); ++it) {
serde->read_one_cell_from_jsonb(*vec, it->value());
}
EXPECT_TRUE(vec->size() == 2);
IPv4 data = vec->get_element(1);
IPv4Value ipv4_value(data);
EXPECT_EQ(ipv4_value.to_string(), ip);
}
}

} // namespace doris::vectorized
12 changes: 12 additions & 0 deletions regression-test/data/datatype_p0/ip/test_ip_basic.out
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,15 @@ ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 4
121.25.82.29 2620:44:a000::1
121.25.160.80 2001:418:0:5000::c2d

-- !sql --
1 true 255.255.255.255 5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b

-- !sql --
1 false 255.255.255.255 5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b

-- !sql --
1 false 127.0.0.1 5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b

-- !sql --
1 false 127.0.0.1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff

14 changes: 14 additions & 0 deletions regression-test/suites/datatype_p0/ip/test_ip_basic.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,18 @@ suite("test_ip_basic") {
sql "DROP TABLE t0"
sql "DROP TABLE t1"
sql "DROP TABLE t2"

// test ip with rowstore
sql """ SET enable_nereids_planner=true """
sql """ SET enable_fallback_to_original_planner=false """
sql """ DROP TABLE IF EXISTS table_ip """
sql """ CREATE TABLE IF NOT EXISTS `table_ip` (`col0` bigint NOT NULL,`col1` boolean NOT NULL, `col24` ipv4 NOT NULL, `col25` ipv6 NOT NULL,INDEX col1 (`col1`) USING INVERTED, INDEX col25 (`col25`) USING INVERTED ) ENGINE=OLAP UNIQUE KEY(`col0`) DISTRIBUTED BY HASH(`col0`) BUCKETS 4 PROPERTIES ("replication_allocation" = "tag.location.default: 1", "store_row_column" = "true") """
sql """ insert into table_ip values (1, true, '255.255.255.255', "5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b") """
qt_sql """ select * from table_ip """
sql """ Update table_ip set col1 = false where col0 = 1 """
qt_sql """ select * from table_ip """
sql """ Update table_ip set col24 = '127.0.0.1' where col0 = 1 """
qt_sql """ select * from table_ip where col0 = 1"""
sql """ Update table_ip set col25 = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' where col0 = 1 """
qt_sql """ select * from table_ip where col0 = 1"""
}