-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Change strategy of incorrect data #1255
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbb84c5
* Change strategy of incorrect data
EmmyMiao87 6b77052
Change has_expr_column_list to transform_columns
EmmyMiao87 c6d9e32
Follow the java naming conventions
EmmyMiao87 68657bd
Fix error of ut
EmmyMiao87 736d060
Add map of dest id to src id
EmmyMiao87 cf52e6f
Save slot desc pointer in broker scanner
EmmyMiao87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ BrokerScanner::BrokerScanner(RuntimeState* state, | |
// _splittable(params.splittable), | ||
_value_separator(static_cast<char>(params.column_separator)), | ||
_line_delimiter(static_cast<char>(params.line_delimiter)), | ||
_strict_mode(false), | ||
_cur_file_reader(nullptr), | ||
_cur_line_reader(nullptr), | ||
_cur_decompressor(nullptr), | ||
|
@@ -117,6 +118,7 @@ Status BrokerScanner::init_expr_ctxes() { | |
return Status(ss.str()); | ||
} | ||
|
||
bool has_transform_slot_ids = _params.__isset.transform_slot_ids; | ||
for (auto slot_desc : _dest_tuple_desc->slots()) { | ||
if (!slot_desc->is_materialized()) { | ||
continue; | ||
|
@@ -133,6 +135,15 @@ Status BrokerScanner::init_expr_ctxes() { | |
RETURN_IF_ERROR(ctx->prepare(_state, *_row_desc.get(), _mem_tracker.get())); | ||
RETURN_IF_ERROR(ctx->open(_state)); | ||
_dest_expr_ctx.emplace_back(ctx); | ||
if (has_transform_slot_ids) { | ||
auto it = _params.transform_slot_ids.find(slot_desc->id()); | ||
if (it == std::end(_params.transform_slot_ids)) { | ||
_has_expr_columns.emplace_back(false); | ||
} | ||
else { | ||
_has_expr_columns.emplace_back(true); | ||
} | ||
} | ||
} | ||
|
||
return Status::OK; | ||
|
@@ -148,6 +159,12 @@ Status BrokerScanner::open() { | |
_rows_read_counter = ADD_COUNTER(_profile, "RowsRead", TUnit::UNIT); | ||
_read_timer = ADD_TIMER(_profile, "TotalRawReadTime(*)"); | ||
_materialize_timer = ADD_TIMER(_profile, "MaterializeTupleTime(*)"); | ||
if (_params.__isset.strict_mode) { | ||
_strict_mode = _params.strict_mode; | ||
} | ||
if (_strict_mode && !_params.__isset.transform_slot_ids) { | ||
return Status("Expr column list must be set in strict mode"); | ||
} | ||
|
||
return Status::OK; | ||
} | ||
|
@@ -585,24 +602,37 @@ bool BrokerScanner::fill_dest_tuple(const Slice& line, Tuple* dest_tuple, MemPoo | |
continue; | ||
} | ||
|
||
ExprContext* ctx = _dest_expr_ctx[ctx_idx++]; | ||
ExprContext* ctx = _dest_expr_ctx[ctx_idx]; | ||
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. cid = ctx_idx++; |
||
void* value = ctx->get_value(_src_tuple_row); | ||
if (value == nullptr) { | ||
if (slot_desc->is_nullable()) { | ||
dest_tuple->set_null(slot_desc->null_indicator_offset()); | ||
continue; | ||
} else { | ||
if (_strict_mode && !_src_tuple->is_null(slot_desc->null_indicator_offset()) | ||
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. slot_desc is dest tuple descriptor, what you need is a src tuple descriptor |
||
&& !_has_expr_columns[ctx_idx]) { | ||
std::stringstream error_msg; | ||
error_msg << "column(" << slot_desc->col_name() << ") value is null"; | ||
error_msg << "column(" << slot_desc->col_name() << ") value is incorrect " | ||
<< "while strict mode is " << std::boolalpha << _strict_mode; | ||
_state->append_error_msg_to_file( | ||
std::string(line.data, line.size), error_msg.str()); | ||
_counter->num_rows_filtered++; | ||
return false; | ||
} | ||
if (!slot_desc->is_nullable()) { | ||
std::stringstream error_msg; | ||
error_msg << "column(" << slot_desc->col_name() << ") value is null " | ||
<< "while columns is not nullable"; | ||
_state->append_error_msg_to_file( | ||
std::string(line.data, line.size), error_msg.str()); | ||
_counter->num_rows_filtered++; | ||
return false; | ||
} | ||
dest_tuple->set_null(slot_desc->null_indicator_offset()); | ||
ctx_idx++; | ||
continue; | ||
} | ||
dest_tuple->set_not_null(slot_desc->null_indicator_offset()); | ||
void* slot = dest_tuple->get_slot(slot_desc->tuple_offset()); | ||
RawValue::write(value, slot, slot_desc->type(), mem_pool); | ||
ctx_idx++; | ||
continue; | ||
} | ||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
docs/documentation/cn/administrator-guide/load-data/broker-load-manual.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# broker load 使用说明 | ||
|
||
## properties | ||
|
||
### strict mode | ||
broker load导入可以开启strict mode模式。开启方式为 ```properties ("strict_mode" = "true")``` 。默认的 strict mode为开启。 | ||
|
||
*注意:strict mode 功能仅在新版本的broker load中有效,如果导入明确指定 ```"version" = "v1"``` 则没有此功能。* | ||
|
||
strict mode模式的意思是:对于导入过程中的列类型转换进行严格过滤。严格过滤的策略如下: | ||
|
||
对于列类型转换来说,如果 strict\_mode 为true,则错误的数据将被filter。这里的错误数据是指:原始数据并不为空值,在参与列类型转换后结果为空值的这一类数据。 | ||
|
||
对于导入的某列包含函数变换的,导入的值和函数的结果一致,strict 对其不产生影响。(其中 strftime 等 broker 系统支持的函数也属于这类)。 | ||
|
||
### strict mode 与 source data 的导入关系 | ||
|
||
这里以列类型为 int 来举例 | ||
注:当表中的列允许导入空值时 | ||
|
||
source data | source data example | string to int | strict_mode | load_data | ||
------------|---------------------|-----------------|--------------------|--------- | ||
空值 | \N | N/A | true or false | NULL | ||
not null | aaa | NULL | true | filtered | ||
not null | aaa | NULL | false | NULL | ||
not null | 1 | 1 | true or false | correct data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
} else {