Skip to content

Check sqllogictests for any dangling config settings(#17914)#20474

Closed
cj-zhukov wants to merge 3 commits intoapache:mainfrom
cj-zhukov:cj-zhukov/check-sqllogictests-for-any-dangling-config-settings
Closed

Check sqllogictests for any dangling config settings(#17914)#20474
cj-zhukov wants to merge 3 commits intoapache:mainfrom
cj-zhukov:cj-zhukov/check-sqllogictests-for-any-dangling-config-settings

Conversation

@cj-zhukov
Copy link
Copy Markdown
Contributor

@cj-zhukov cj-zhukov commented Feb 22, 2026

Which issue does this PR close?

Rationale for this change

This PR introduces a validation script to prevent dangling configuration settings in sqllogictest (.slt) files.

What changes are included in this PR?

  • A new shell script ci/scripts/check_slt_configs.sh that scans all .slt files and detects DataFusion configuration options that are set to: set datafusion.<config> = true but are never reset back to: set datafusion.<config> = false
  • Updates to existing .slt files where dangling boolean configs were found.
    All identified configs have been explicitly reset to false to ensure files restore the default session state.
  • A new CI job: sqllogictest-config-check that runs the validation script and fails the workflow if any abandoned boolean configuration is detected.

Are these changes tested?

Yes, these changes are tested.

Are there any user-facing changes?

No, there are no user-facing changes.

@github-actions github-actions bot added development-process Related to development process of DataFusion sqllogictest SQL Logic Tests (.slt) labels Feb 22, 2026
@cj-zhukov
Copy link
Copy Markdown
Contributor Author

High-Level Overview

This PR introduces a validation script to prevent dangling configuration settings in sqllogictest (.slt) files.

This PR Adds:

  • A new shell script ci/scripts/check_slt_configs.sh that scans all .slt files and detects DataFusion configuration options that are set to: set datafusion.<config> = true but are never reset back to: set datafusion.<config> = false
  • Updates to existing .slt files where dangling boolean configs were found.
    All identified configs have been explicitly reset to false to ensure files restore the default session state.
  • A new CI job: sqllogictest-config-check that runs the validation script and fails the workflow if any abandoned boolean configuration is detected.

Current Limitations:

  • Only checks boolean flags set to true and id does not validate non-boolean configuration changes (e.g. default_catalog, default_schema, etc.)
  • Does not respect ordering: It only verifies that a matching = false exists somewhere in the file and It does not ensure the reset occurs after the corresponding = true.
  • Does not validate toggle correctness: it does not verify correct pairing, nesting, or the number of enable/disable occurrence

Follow-Up Improvements:

  • Parse (.slt) files properly instead of relying on regex/grep.
  • Track configuration state transitions in order.
  • Validate correct pairing and restoration semantics.
  • Support non-boolean configuration values.
    This could be implemented in Rust using a proper parser (e.g., nom), similar to what is already used in datafusion-examples.
    I’m happy to work on a follow-up PR to evolve this validation into a more robust and structured implementation.

@cj-zhukov
Copy link
Copy Markdown
Contributor Author

@Jefffrey Since you originally opened this issue, could you please take a look at this PR?

# Any configuration set with:
# set datafusion.<config> = true
# must be reset in the same file with:
# set datafusion.<config> = false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if the setting's default is true and an .slt test needed to set it to false but forgot to unset it ?
It would be better to use the reset datafusion.***; command instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point - using RESET is semantically more correct since it restores the default value rather than assuming it is false. I'm going to update the script to accept RESET datafusion.<config> as a valid restoration mechanism.

return
fi

echo ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks strange.
Why not log the error from line 74 here and exit ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree with you - let's do it

# Process each match line-by-line
while IFS= read -r match; do
line_number=$(echo "$match" | cut -d: -f1)
line_content=$(echo "$match" | cut -d: -f2-)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: You could avoid starting a new process by using Bash-isms like:

line_number=${match%%:*}
line_content=${match#*:}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion

set datafusion.execution.collect_statistics = false;

statement ok
set datafusion.execution.parquet.pushdown_filters = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

duplicate of line 749

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for catching this - I missed that duplicate configuration in the push_down_filter.slt

datafusion.runtime.temp_directory

statement ok
set datafusion.catalog.information_schema = false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
set datafusion.catalog.information_schema = false
set datafusion.catalog.information_schema = false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I noticed that other SET statements in this file do not use semicolons.
Should we standardize on including ;, or keep the existing style for consistency?

needs: linux-build-lib
runs-on: ubuntu-latest
container:
image: amd64/rust
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason to use a container ?
The CI job just runs a Bash shell script

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's correct - no reason for a container. I'll run it directly on ubuntu-latest instead of using the Rust container so it runs earlier and fails fast.

fi

matches=$(grep -En \
'set[[:space:]]+datafusion\.[a-zA-Z0-9_.]+[[:space:]]*=[[:space:]]*true' \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch - I missed that SET can appear in uppercase.
I’ll update the script to perform case-insensitive matching so both set and SET are handled correctly.

drop table t3

statement ok
set datafusion.catalog.default_catalog = my_catalog;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The catalog and the schema below are never reset.
This is an example of non-boolean settings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out. You’re right - this is currently a limitation. The script only checks boolean settings enabled via = true and does not detect non-boolean configuration changes.

At this stage, I’d prefer to keep the script simple rather than significantly increasing its complexity in Bash. If we decide to expand the scope to cover all SET datafusion.* mutations (including non-boolean values), I think it would be better to address that in a follow-up by implementing a more robust solution in Rust (e.g., using nom). That would allow us to properly track configuration changes and ensure they are restored in a more reliable way. I'm ready to work on this.

Happy to hear your thoughts on whether we should keep this PR focused or broaden its scope.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed! Keep it simple for the first version!
Maybe add a comment/TODO to the new Bash script about this use case.


# Check if reset exists anywhere in file
if ! grep -Eq \
"set[[:space:]]+$config[[:space:]]*=[[:space:]]*false" \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"set[[:space:]]+$config[[:space:]]*=[[:space:]]*false" \
"set[[:space:]]+${config}[[:space:]]*=[[:space:]]*false" \

DROP TABLE t0;

statement ok
set datafusion.explain.logical_plan_only = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

Is there a way to do this check in the SLT runner test code itself? e.g. after it runs an SLT file it checks if the config state is dirty and reports it via a warning in test output? I'm not particularly sure of adding more and more bash scripts like this

@cj-zhukov
Copy link
Copy Markdown
Contributor Author

Is there a way to do this check in the SLT runner test code itself? e.g. after it runs an SLT file it checks if the config state is dirty and reports it via a warning in test output? I'm not particularly sure of adding more and more bash scripts like this

Thank you - that makes sense. I agree that enforcing this at the SLT runner level would be a cleaner and more robust solution than adding additional Bash-based checks in CI.

I initially considered implementing this directly in Rust, but the shell script felt like a simpler and less invasive first step. That said, I understand the concern about accumulating more CI scripting logic, and I agree that handling this inside the SLT runner is architecturally the better approach.

We can mark this PR as draft (without closing the root issue). I'm going to work on a follow-up PR that implements the check directly in the SLT runner - e.g., verifying after each SLT file execution that the configuration state matches the default and reporting it in the test output. That should give us a more complete and future-proof solution.

Let me know if that sounds like a good direction, and I’ll proceed accordingly.

@Jefffrey
Copy link
Copy Markdown
Contributor

That sounds good

@cj-zhukov cj-zhukov marked this pull request as draft February 26, 2026 05:44
github-merge-queue bot pushed a commit that referenced this pull request Mar 13, 2026
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->

- Closes ##17914.

## Rationale for this change
In a previous PR #20474, I
added a bash script that parsed the `SLT` files and checked whether any
DataFusion configuration options were modified without being reset.

While that approach worked, it relied on external scripting and
additional parsing logic. This PR introduces a simpler and more direct
solution implemented in Rust.

At the end of each `SLT` test file execution, the current configuration
is compared with the default configuration using a `Drop`
implementation. If any configuration values were modified and not
restored, a warning is printed.

This approach is easier to maintain and keeps the validation logic
within the Rust codebase rather than relying on an external bash script.

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

## What changes are included in this PR?
- Capture the default DataFusion configuration when the `SLT` runner is
initialized.
- Implement `Drop` for the DataFusion SLT engine.
- When an `SLT` file finishes executing, compare the current
configuration with the default configuration.
- If differences are detected, print a warning showing which
configuration options were modified.

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

## Are these changes tested?
This behavior is exercised by the existing `SLT` test suite. The
configuration check runs automatically when each `SLT` file completes
execution.

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

## Are there any user-facing changes?
No. This change only affects internal `SLT` test infrastructure and does
not modify any public APIs.

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->

---------

Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
@cj-zhukov
Copy link
Copy Markdown
Contributor Author

I'm closing this PR as all the work was completed and merged in #20838

@cj-zhukov cj-zhukov closed this Mar 13, 2026
@cj-zhukov cj-zhukov deleted the cj-zhukov/check-sqllogictests-for-any-dangling-config-settings branch March 13, 2026 11:56
de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
…pache#20838)

## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- Closes #apache#17914.

## Rationale for this change
In a previous PR apache#20474, I
added a bash script that parsed the `SLT` files and checked whether any
DataFusion configuration options were modified without being reset.

While that approach worked, it relied on external scripting and
additional parsing logic. This PR introduces a simpler and more direct
solution implemented in Rust.

At the end of each `SLT` test file execution, the current configuration
is compared with the default configuration using a `Drop`
implementation. If any configuration values were modified and not
restored, a warning is printed.

This approach is easier to maintain and keeps the validation logic
within the Rust codebase rather than relying on an external bash script.

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

## What changes are included in this PR?
- Capture the default DataFusion configuration when the `SLT` runner is
initialized.
- Implement `Drop` for the DataFusion SLT engine.
- When an `SLT` file finishes executing, compare the current
configuration with the default configuration.
- If differences are detected, print a warning showing which
configuration options were modified.

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

## Are these changes tested?
This behavior is exercised by the existing `SLT` test suite. The
configuration check runs automatically when each `SLT` file completes
execution.

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

## Are there any user-facing changes?
No. This change only affects internal `SLT` test infrastructure and does
not modify any public APIs.

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->

---------

Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development-process Related to development process of DataFusion sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants