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

fix: index out-of-bounds issue in the LT05 rule when trying to remove elements from a sequence #1038

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion crates/lib/src/rules/layout/lt05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ FROM my_table"#
}

for idx in to_remove {
results.remove(idx);
if idx < results.len() {
results.remove(idx);
} else {
println!(
"Attempted to remove index {} from results with length {}",
idx,
results.len()
);
}
}

results
Expand Down
29 changes: 29 additions & 0 deletions crates/lib/test/fixtures/rules/std_rule_cases/LT05.yml
Original file line number Diff line number Diff line change
Expand Up @@ -713,3 +713,32 @@ test_pass_window_function:
order by d desc
) as rnk
from foo

test_long_line_with_jinja_template:
# Test handling of long lines with Jinja templates to avoid index out of bounds
pass_str: |
{{ config(
materialized = 'table',
tags = ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag10"]
) }}

WITH date_series AS (
SELECT DATE(DATEADD(month,
ROW_NUMBER() OVER (
PARTITION BY cm.customer_external_id,
cm.subscription_external_id,
cm.uuid
ORDER BY cm.date
) - 1,
cm.date
) AS calendar_date
FROM {{ source("some_schema", "some_table") }} AS cm
)
SELECT * FROM date_series
configs:
core:
max_line_length: 80
templater:
jinja:
context:
source: my_source