Skip to content

Conversation

phant0mw0lf
Copy link
Contributor

Brief summary of the change made

This PR adds support for Databricks single-line magics (e.g., -- MAGIC %run ./Notebook) to the Databricks dialect.

  • Introduces a new magic_single_line regex lexer and grammar to correctly parse single-line magics as their own segment type.
  • Updates the MagicCellStatementSegment to allow either multi-line or single-line magics.
  • Adds test fixtures for single-line magics to ensure correct parsing and linting.

fixes #6998

Are there any other side effects of this change that we should be aware of?

No known side effects. This change is isolated to the Databricks dialect and only affects parsing of magic lines.

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Enhanced the Databricks dialect to support single-line magic commands by adding new lexer and grammar rules.

  • Added support for single-line magic commands (e.g., -- MAGIC %run ./Notebook) in src/sqlfluff/dialects/dialect_databricks.py
  • Created new test fixture test/fixtures/dialects/databricks/magic_single_line.sql demonstrating both multi-line and single-line magic command usage
  • Added corresponding YAML test fixtures in test/fixtures/dialects/databricks/magic_single_line.yml to validate parsing behavior
  • Implementation maintains compatibility with existing magic cell functionality while adding distinct segment type for single-line commands

3 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@WittierDinosaur WittierDinosaur left a comment

Choose a reason for hiding this comment

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

LGTM

@WittierDinosaur WittierDinosaur added this pull request to the merge queue Jul 10, 2025
Copy link
Contributor

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   19870      0   100%

253 files skipped due to complete coverage.

Merged via the queue into sqlfluff:main with commit 163858b Jul 10, 2025
28 checks passed
@phant0mw0lf phant0mw0lf deleted the users/phant0mw0lf/fixSingleLineMagicCommandParsing branch July 10, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Databricks: Support for single-line magics
2 participants