Skip to content

Commit

Permalink
update ipvalue with int128
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan committed Nov 4, 2024
1 parent b40e54a commit 5d14451
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions be/src/http/action/compaction_score_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ constexpr std::string_view TABLET_ID = "tablet_id";

template <typename T>
concept CompactionScoreAccessble = requires(T t) {
{ t.get_real_compaction_score() } -> std::same_as<uint32_t>;
};
{ t.get_real_compaction_score() } -> std::same_as<uint32_t>;
};

template <CompactionScoreAccessble T>
std::vector<CompactionScoreResult> calculate_compaction_scores(
Expand Down
19 changes: 4 additions & 15 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,28 +69,17 @@ 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 ip_value = static_cast<const JsonbInt128Val*>(arg)->val();
const IPv6* ip_val = reinterpret_cast<const IPv6*>(&ip_value);
assert_cast<ColumnIPv6&>(column).insert_value(*ip_val);
}

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
result.writeKey(col_id);
IPv6 data = assert_cast<const ColumnIPv6&>(column).get_element(row_num);
IPv6Value ipv6_value(data);
std::string ipv6_str = ipv6_value.to_string();
result.writeStartString();
result.writeString(ipv6_str.c_str(), ipv6_str.size());
result.writeEndString();
result.writeInt128(int128_t(data));
}

Status DataTypeIPv6SerDe::serialize_one_cell_to_json(const IColumn& column, int row_num,
Expand Down
5 changes: 5 additions & 0 deletions be/src/vec/exec/format/json/new_json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ Status NewJsonReader::get_parsed_schema(std::vector<std::string>* col_names,
objectValue = _json_doc;
}

if (!objectValue->IsObject()) {
return Status::DataQualityError("JSON data is not an object. but: {}",
objectValue->GetType());
}

// use jsonpaths to col_names
if (!_parsed_jsonpaths.empty()) {
for (auto& _parsed_jsonpath : _parsed_jsonpaths) {
Expand Down
4 changes: 2 additions & 2 deletions regression-test/suites/datatype_p0/ip/test_ip_basic.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ suite("test_ip_basic") {
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 """
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 """
qt_sql """ select * from table_ip where col0 = 1"""
}

0 comments on commit 5d14451

Please sign in to comment.