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

support query_max_size for insert_rows_method chunk #679

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion macros/utils/list_utils/split_list_to_chunks.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{% macro split_list_to_chunks(item_list, chunk_size=50) %}
{% set chunks = [] %}
{% set current_chunk = [] %}
{% set current_length = 0 %}
{% for item in item_list %}
{% set reminder = loop.index0 % chunk_size %}
{% if reminder == 0 and current_chunk %}
{% if (reminder == 0 and current_chunk) or (current_length + item | length) > elementary.get_config_var('query_max_size') %}
{% do chunks.append(current_chunk.copy()) %}
{% do current_chunk.clear() %}
{% set current_length = 0 %}
{% endif %}
{% do current_chunk.append(item) %}
{% do current_length + item | length %}
{% endfor %}
{% if current_chunk %}
{% do chunks.append(current_chunk) %}
Expand Down
Loading