Skip to content
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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

KevinyhZou
Copy link
Contributor

@KevinyhZou KevinyhZou commented Aug 15, 2024

What changes were proposed in this pull request?

(Please fill in changes proposed in this fix)

(Fixes: #6856 #6916 )

  1. support function arrays_overlap
  2. fix array_join diff

How was this patch tested?

test by spark ut

(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)

@github-actions github-actions bot added CORE works for Gluten Core CLICKHOUSE labels Aug 15, 2024
Copy link

#6856

Copy link

Run Gluten Clickhouse CI

@KevinyhZou KevinyhZou changed the title [GLUTEN-6856][CH]Support arrays overlap [GLUTEN-6856][CH]Support arrays_overlap Aug 15, 2024
Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

@KevinyhZou KevinyhZou changed the title [GLUTEN-6856][CH]Support arrays_overlap [GLUTEN-6856][CH]Support arrays_overlap and fix array_join diff Aug 19, 2024
Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

@KevinyhZou
Copy link
Contributor Author

KevinyhZou commented Aug 22, 2024

The performance of arrays_overlap in gluten
image

The performance of arrays_overlap in valina
image

the performance compare: gluten 6.2s vs valina 37s

Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

@github-actions github-actions bot removed the CORE works for Gluten Core label Sep 19, 2024
Copy link

Run Gluten Clickhouse CI

2 similar comments
Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

Copy link

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; }
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@taiyang-li taiyang-li Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么clickhouse会替换const null? 没太理解

Copy link
Contributor Author

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());
Copy link
Contributor

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());
Copy link
Contributor

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)
Copy link
Contributor

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>;

Copy link
Contributor Author

@KevinyhZou KevinyhZou Sep 20, 2024

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中获取数据。不是一个通用的方法

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只是举个例子,如果上面的set不行还可以用std::unordered_set

Copy link
Contributor Author

@KevinyhZou KevinyhZou Sep 20, 2024

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
Copy link
Contributor

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; }
Copy link
Contributor

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的问题了,增加了很多不必要的麻烦

Copy link
Contributor Author

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。

Copy link
Contributor

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.

Copy link
Contributor Author

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))
Copy link
Contributor

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这里为什么不用?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处是多余逻辑,已经删除

Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

Copy link

Run Gluten Clickhouse CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CH] Support function arrays_overlap
2 participants