Skip to content

Commit

Permalink
[minor](serde) 'null' in the serde should be represented by constants…
Browse files Browse the repository at this point in the history
…, instead of a string variable (#26301)
  • Loading branch information
BePPPower committed Nov 14, 2023
1 parent 52c311c commit 4000de1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion be/src/vec/data_types/serde/data_type_array_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ Status DataTypeArraySerDe::_write_column_to_mysql(const IColumn& column,
}
}
if (data.is_null_at(j)) {
if (0 != result.push_string("null", strlen("null"))) {
if (0 != result.push_string(NULL_IN_COMPLEX_TYPE.c_str(),
strlen(NULL_IN_COMPLEX_TYPE.c_str()))) {
return Status::InternalError("pack mysql buffer failed.");
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions be/src/vec/data_types/serde/data_type_map_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ Status DataTypeMapSerDe::_write_column_to_mysql(const IColumn& column,
}
}
if (nested_keys_column.is_null_at(j)) {
if (0 != result.push_string("null", strlen("null"))) {
if (0 != result.push_string(NULL_IN_COMPLEX_TYPE.c_str(),
strlen(NULL_IN_COMPLEX_TYPE.c_str()))) {
return Status::InternalError("pack mysql buffer failed.");
}
} else {
Expand All @@ -434,7 +435,8 @@ Status DataTypeMapSerDe::_write_column_to_mysql(const IColumn& column,
return Status::InternalError("pack mysql buffer failed.");
}
if (nested_values_column.is_null_at(j)) {
if (0 != result.push_string("null", strlen("null"))) {
if (0 != result.push_string(NULL_IN_COMPLEX_TYPE.c_str(),
strlen(NULL_IN_COMPLEX_TYPE.c_str()))) {
return Status::InternalError("pack mysql buffer failed.");
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/data_types/serde/data_type_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ DataTypeSerDeSPtrs create_data_type_serdes(const std::vector<SlotDescriptor*>& s
}
return serdes;
}

const std::string DataTypeSerDe::NULL_IN_COMPLEX_TYPE = "null";
const std::string DataTypeSerDe::NULL_IN_CSV_FOR_ORDINARY_TYPE = "\\N";
} // namespace vectorized
} // namespace doris
6 changes: 6 additions & 0 deletions be/src/vec/data_types/serde/data_type_serde.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ class DataTypeSerDe {
}
};

// For the NULL value in the complex type, we use the `null` of the lowercase
static const std::string NULL_IN_COMPLEX_TYPE;

// For the NULL value in the ordinary type in csv file format, we use `\N`
static const std::string NULL_IN_CSV_FOR_ORDINARY_TYPE;

public:
DataTypeSerDe(int nesting_level = 1) : _nesting_level(nesting_level) {};
virtual ~DataTypeSerDe();
Expand Down
6 changes: 4 additions & 2 deletions be/src/vec/data_types/serde/data_type_struct_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ Status DataTypeStructSerDe::deserialize_one_cell_from_json(IColumn& column, Slic
continue;
}
// handle null element
if (field_rb.count() == 4 && strncmp(field_rb.position(), "null", 4) == 0) {
if (field_rb.count() == 4 && strncmp(field_rb.position(), NULL_IN_COMPLEX_TYPE.c_str(),
strlen(NULL_IN_COMPLEX_TYPE.c_str())) == 0) {
auto& nested_null_col =
reinterpret_cast<ColumnNullable&>(struct_column.get_column(idx));
nested_null_col.insert_null_elements(1);
Expand Down Expand Up @@ -305,7 +306,8 @@ Status DataTypeStructSerDe::_write_column_to_mysql(const IColumn& column,
}

if (col.get_column_ptr(j)->is_null_at(col_index)) {
if (0 != result.push_string("null", strlen("null"))) {
if (0 != result.push_string(NULL_IN_COMPLEX_TYPE.c_str(),
strlen(NULL_IN_COMPLEX_TYPE.c_str()))) {
return Status::InternalError("pack mysql buffer failed.");
}
} else {
Expand Down

0 comments on commit 4000de1

Please sign in to comment.