Skip to content

Commit d85fed8

Browse files
committed
return null for wrong array
1 parent aae4f6f commit d85fed8

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

be/src/vec/data_types/data_type_array.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
#include "vec/data_types/data_type_array.h"
2222

2323
#include "gen_cpp/data.pb.h"
24+
#include "util/stack_util.h"
2425
#include "vec/columns/column_array.h"
2526
#include "vec/columns/column_nullable.h"
2627
#include "vec/data_types/data_type_nullable.h"
27-
#include "util/stack_util.h"
2828

2929
namespace doris::vectorized {
3030

@@ -185,10 +185,13 @@ Status DataTypeArray::from_string(ReadBuffer& rb, IColumn* column) const {
185185
return Status::InvalidArgument("Array does not start with '[' character, found '{}'",
186186
*rb.position());
187187
}
188+
if (*(rb.end() - 1) != ']') {
189+
return Status::InvalidArgument("Array does not end with ']' character, found '{}'",
190+
*(rb.end() - 1));
191+
}
188192
++rb.position();
189193
bool first = true;
190194
size_t size = 0;
191-
bool find_end = false;
192195
while (!rb.eof() && *rb.position() != ']') {
193196
if (!first) {
194197
if (*rb.position() == ',') {
@@ -201,7 +204,6 @@ Status DataTypeArray::from_string(ReadBuffer& rb, IColumn* column) const {
201204
}
202205
first = false;
203206
if (*rb.position() == ']') {
204-
find_end = true;
205207
break;
206208
}
207209
size_t nested_str_len = 0;
@@ -257,9 +259,6 @@ Status DataTypeArray::from_string(ReadBuffer& rb, IColumn* column) const {
257259
DCHECK_LE(rb.position(), rb.end());
258260
++size;
259261
}
260-
if (!(!rb.eof() && *rb.position() != ']') && !find_end) {
261-
return Status::InvalidArgument("Array does not start with ']' character");
262-
}
263262
offsets.push_back(offsets.back() + size);
264263
return Status::OK();
265264
}

be/src/vec/exec/format/parquet/schema_desc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ TypeDescriptor FieldDescriptor::get_doris_type(const tparquet::SchemaElement& ph
164164
type = convert_to_doris_type(physical_schema.converted_type);
165165
}
166166
// use physical type instead
167-
if (type.type ==INVALID_TYPE) {
167+
if (type.type == INVALID_TYPE) {
168168
switch (physical_schema.type) {
169169
case tparquet::Type::BOOLEAN:
170170
type.type = TYPE_BOOLEAN;

be/src/vec/functions/function_cast.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ struct ConvertImplGenericFromString {
320320
check_and_get_column<StringColumnType>(&col_from)) {
321321
auto col_to = data_type_to->create_column();
322322

323-
//IColumn & col_to = *res;
324323
size_t size = col_from.size();
325324
col_to->reserve(size);
326325

326+
ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(size);
327+
ColumnUInt8::Container* vec_null_map_to = &col_null_map_to->get_data();
328+
327329
for (size_t i = 0; i < size; ++i) {
328330
const auto& val = col_from_string->get_data_at(i);
329331
// Note: here we should handle the null element
@@ -332,9 +334,16 @@ struct ConvertImplGenericFromString {
332334
continue;
333335
}
334336
ReadBuffer read_buffer((char*)(val.data), val.size);
335-
RETURN_IF_ERROR(data_type_to->from_string(read_buffer, col_to));
337+
Status st = data_type_to->from_string(read_buffer, col_to);
338+
// if parsing failed, will return null
339+
(*vec_null_map_to)[i] = !st.ok();
340+
if (!st.ok()) {
341+
col_to->insert_default();
342+
}
336343
}
337-
block.replace_by_position(result, std::move(col_to));
344+
// block.replace_by_position(result, std::move(col_to));
345+
block.get_by_position(result).column =
346+
ColumnNullable::create(std::move(col_to), std::move(col_null_map_to));
338347
} else {
339348
return Status::RuntimeError(
340349
"Illegal column {} of first argument of conversion function from string",
@@ -870,8 +879,9 @@ struct ConvertThroughParsing {
870879
if constexpr (IsDataTypeDecimal<ToDataType>) {
871880
UInt32 scale = additions;
872881
col_to = ColVecTo::create(size, scale);
873-
} else
882+
} else {
874883
col_to = ColVecTo::create(size);
884+
}
875885

876886
typename ColVecTo::Container& vec_to = col_to->get_data();
877887

0 commit comments

Comments
 (0)