-
Notifications
You must be signed in to change notification settings - Fork 444
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
[GLUTEN-6856][CH]Support arrays_overlap and fix array_join diff #6857
Conversation
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
0039b63
to
d4fd958
Compare
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
d2e4c2b
to
df7331a
Compare
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
2 similar comments
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
d552874
to
a2a58c3
Compare
Run Gluten Clickhouse CI |
size_t getNumberOfArguments() const override { return 2; } | ||
String getName() const override { return name; } | ||
bool useDefaultImplementationForNulls() const override { return false; } | ||
bool useDefaultImplementationForConstants() const override { return false; } |
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.
why is it false? if it is false, we need to handle the case that all input arguments are constant, which could be avoided by setting it to true.
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.
if set to true, the input maybe const null, and clickhouse will replace this value , which would lead to differrent result
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.
为什么clickhouse会替换const null? 没太理解
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.
测试了下可以设置为true,代码已经修改。应该是之前的测试有问题
return ColumnNullable::create(std::move(res), std::move(null_map)); | ||
} | ||
if (const_col_1) | ||
array_col_1 = checkAndGetColumn<ColumnArray>(const_col_1->getDataColumnPtr().get()); |
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.
const里包的有可能是nullable array或array, 两种情况都需要考虑
array_col_1 = checkAndGetColumn<ColumnArray>(const_col_1->getDataColumnPtr().get()); | ||
else | ||
{ | ||
const auto * null_col_1 = checkAndGetColumn<ColumnNullable>(arguments[0].column.get()); |
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.
arguments[0]也许是nullable array或array, 两种情况都需要考虑。arguments[1]也一样
size_t array_size_2 = array_offsets_2[i] - current_offset_2; | ||
auto executeCompare = [&](const IColumn & col1, const IColumn & col2, const ColumnUInt8 * null_map1, const ColumnUInt8 * null_map2) -> void | ||
{ | ||
for (size_t j = 0; j < array_size_1 && !res_data[i]; ++j) |
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.
两个for循环性能会比较差,可以用这个数据结构:
using Set = HashSetWithStackMemory<StringRef, StringRefHash, 4>;
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.
使用HashSetWithStackMemory,考虑到多层array,struct,map的复杂嵌套,会导致代码逻辑十分复杂,并且无法通过getDataAt(i) 从array(string) 的column中获取数据。不是一个通用的方法
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.
只是举个例子,如果上面的set不行还可以用std::unordered_set
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.
使用std::unordered_set 也是一样,对于复杂类型来说,需要判断是否有column 嵌套,然后再递归比较。相比较于两次for循环,可以直接使用ch 内置的column.compare 函数,直接在ch内部实现了复杂类型column的比较。使用set,也只是空间换时间。
return makeNullable(data_type); | ||
} | ||
|
||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override |
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.
尽量不要把所有的逻辑放在一个大函数里。参考src/Functions/regexpExtract.cpp的实现,按照两个参数是否为constant分成若干种情况,每种情况对应一个函数。
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo &) const override { return true; } | ||
size_t getNumberOfArguments() const override { return 2; } | ||
String getName() const override { return name; } | ||
bool useDefaultImplementationForNulls() const override { return false; } |
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.
这里设置成false的话,就必须自己处理arr1[i] = null或arr2[i] = null的问题了,增加了很多不必要的麻烦
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.
如果设置为true,ch 自己处理null 相关的逻辑,会导致两边的结果不一样。arrays_overlap里面如果有一个array含有null,就需要返回null。而ch里面,会返回true,因为两边同时含有NULL。
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.
上面写的不是很清楚,设置成true的话,ch会处理arr1 = null or arr2 = null的逻辑, 不影响其他case.
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.
已经设置为true
size_t array_pos_1 = 0, array_pos_2 = 0; | ||
for (size_t i = 0; i < array_col_1->size(); ++i) | ||
{ | ||
if (arguments[0].column->isNullAt(i) || arguments[1].column->isNullAt(i)) |
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.
for循环中高频调用虚函数 isNullAt会影响性能。既然拿到了null_map_data这里为什么不用?
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.
此处是多余逻辑,已经删除
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
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.
LGTM
…he#6857) * Fix orc timezone read * on test * fix ci * fix ci * ci build error * support arrays_overlap * remove useless code * fix ci * fix ci * fix array_join diff * remove useless code * remove useless code * solve conflict * ci fix * remove useless code * use default impl for array join * remove useless code
What changes were proposed in this pull request?
(Please fill in changes proposed in this fix)
(Fixes: #6856 #6916 )
How was this patch tested?
test by spark ut
(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)