-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(small): Support <slt:ignore> marker in sqllogictest for non-deterministic expected parts
#18857
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
feat(small): Support <slt:ignore> marker in sqllogictest for non-deterministic expected parts
#18857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,13 +82,43 @@ pub fn df_value_validator( | |
| actual: &[Vec<String>], | ||
| expected: &[String], | ||
| ) -> bool { | ||
| // Support ignore marker <slt:ignore> to skip volatile parts of output. | ||
| const IGNORE_MARKER: &str = "<slt:ignore>"; | ||
| let contains_ignore_marker = expected.iter().any(|line| line.contains(IGNORE_MARKER)); | ||
|
|
||
| let normalized_expected = expected.iter().map(normalizer).collect::<Vec<_>>(); | ||
| let normalized_actual = actual | ||
| .iter() | ||
| .map(|strs| strs.iter().join(" ")) | ||
| .map(|str| str.trim_end().to_string()) | ||
| .collect_vec(); | ||
|
|
||
| // If ignore marker present, perform fragment-based matching on the full snapshot. | ||
| if contains_ignore_marker { | ||
| let expected_snapshot = normalized_expected.join("\n"); | ||
| let actual_snapshot = normalized_actual.join("\n"); | ||
| let fragments: Vec<&str> = expected_snapshot.split(IGNORE_MARKER).collect(); | ||
| let mut pos = 0; | ||
| for (i, frag) in fragments.iter().enumerate() { | ||
| if frag.is_empty() { | ||
| continue; | ||
| } | ||
| if let Some(idx) = actual_snapshot[pos..].find(frag) { | ||
| // Edge case: The following example is expected to fail | ||
| // Actual - 'foo bar baz' | ||
| // Expected - 'bar <slt:ignore>' | ||
| if (i == 0) && (idx != 0) { | ||
| return false; | ||
| } | ||
|
|
||
| pos += idx + frag.len(); | ||
| } else { | ||
| return false; | ||
|
Member
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. This early return would make it hard to debug. It would be nice to log a warning with the reason, as done below (line 116+).
Contributor
Author
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. Honestly, I don't know what those log are used for. I think the error message is generated elsewhere, and I want to make sure they're developer-friendly. It looks okay now, but with false positives I have filed #18878 for improvement. |
||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if log_enabled!(Warn) && normalized_actual != normalized_expected { | ||
| warn!("df validation failed. actual vs expected:"); | ||
| for i in 0..normalized_actual.len() { | ||
|
|
@@ -110,3 +140,20 @@ pub fn df_value_validator( | |
| pub fn is_spark_path(relative_path: &Path) -> bool { | ||
| relative_path.starts_with("spark/") | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| // Validation should fail for the below case: | ||
| // Actual - 'foo bar baz' | ||
| // Expected - 'bar <slt:ignore>' | ||
| #[test] | ||
| fn ignore_marker_does_not_skip_leading_text() { | ||
| // Actual snapshot contains unexpected prefix before the expected fragment. | ||
| let actual = vec![vec!["foo bar baz".to_string()]]; | ||
| let expected = vec!["bar <slt:ignore>".to_string()]; | ||
|
|
||
| assert!(!df_value_validator(value_normalizer, &actual, &expected)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| statement ok | ||
| set datafusion.explain.analyze_level = summary; | ||
|
|
||
| query TT | ||
| EXPLAIN ANALYZE SELECT * FROM generate_series(100); | ||
| ---- | ||
| Plan with Metrics LazyMemoryExec: partitions=1, batch_generators=[generate_series: start=0, end=100, batch_size=8192], metrics=[output_rows=101, elapsed_compute=<slt:ignore>, output_bytes=<slt:ignore>] | ||
|
|
||
| statement ok | ||
| reset datafusion.explain.analyze_level; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # ================================= | ||
| # Test sqllogictest runner features | ||
| # ================================= | ||
|
|
||
| # -------------------------- | ||
| # Test `<slt:ignore>` marker | ||
| # -------------------------- | ||
| query T | ||
| select 'DataFusion' | ||
| ---- | ||
| <slt:ignore> | ||
|
|
||
| query T | ||
| select 'DataFusion' | ||
| ---- | ||
| Data<slt:ignore> | ||
|
|
||
| query T | ||
| select 'DataFusion' | ||
| ---- | ||
| <slt:ignore>Fusion | ||
|
|
||
| query T | ||
| select 'Apache DataFusion'; | ||
| ---- | ||
| <slt:ignore>Data<slt:ignore> | ||
|
|
||
| query T | ||
| select 'DataFusion' | ||
| ---- | ||
| DataFusion<slt:ignore> | ||
|
|
||
| query T | ||
| select 'DataFusion' | ||
| ---- | ||
| <slt:ignore>DataFusion | ||
|
|
||
| query T | ||
| select 'DataFusion' | ||
| ---- | ||
| <slt:ignore>DataFusion<slt:ignore> | ||
|
|
||
| query I | ||
| select * from generate_series(3); | ||
| ---- | ||
| 0 | ||
| 1 | ||
| <slt:ignore> | ||
| 3 | ||
|
|
||
| query I | ||
| select * from generate_series(3); | ||
| ---- | ||
| <slt:ignore> | ||
| 1 | ||
| <slt:ignore> | ||
| <slt:ignore> |
Uh oh!
There was an error while loading. Please reload this page.
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.
I think this logic won't detect a prefix in the actual_snapshot.
Let's say the first expected fragment is "Hello" but the actual_snapshot starts with "Anything here before Hello". The
find()will set the position to the correct index butAnything here beforewill be ignored and assumed as matching.Similar issue with a suffix in actual_snapshot.
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.
This is a good catch. I fixed it in a3154e7 and added more tests.