sql-formatter-org / sql-formatter-org/sql-formatter

Feature Request: Add support for linesBetweenQueries="preserve"

Open
#329 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
TypeScript
Stars
2.9k
Forks
456
Avg merge
3d 4h
Merged PRs (30d)
3

Description

Describe the Feature
This feature will help for SQL scripting. For example, I don't link putting too many lines between the DECLARE statements, if the total number of variables defined are too many. And sometimes, I like to group a few variables based on the purpose that they're defined for (no lines in between, but 1 or 2 lines between groups). But I like separating the actual queries with 1 or 2 lines.

Take the following script as an example:

DECLARE target_word STRING DEFAULT 'methinks';
DECLARE corpus_count INT64;
DECLARE word_count INT64;

SET (corpus_count, word_count) = (
  SELECT AS STRUCT COUNT(DISTINCT corpus), SUM(word_count)
  FROM bigquery-public-data.samples.shakespeare
  WHERE LOWER(word) = target_word
);

SELECT
  FORMAT('Found %d occurrences of "%s" across %d Shakespeare works',
         word_count, target_word, corpus_count) AS result;

The formatter would format it as:

DECLARE
  target_word STRING DEFAULT 'methinks';

DECLARE
  corpus_count INT64;

DECLARE
  word_count INT64;

SET
  (corpus_count, word_count) = (
    SELECT
      AS STRUCT COUNT(DISTINCT corpus),
      SUM(word_count)
    FROM
      bigquery-public-data.samples.shakespeare
    WHERE
      LOWER(word) = target_word
  );

SELECT
  FORMAT(
    'Found %d occurrences of "%s" across %d Shakespeare works',
    word_count,
    target_word,
    corpus_count
  ) AS result;

But I'd like it better if it were:

DECLARE
  target_word STRING DEFAULT 'methinks';
DECLARE
  corpus_count INT64;
DECLARE
  word_count INT64;

SET
  (corpus_count, word_count) = (
    SELECT
      AS STRUCT COUNT(DISTINCT corpus),
      SUM(word_count)
    FROM
      bigquery-public-data.samples.shakespeare
    WHERE
      LOWER(word) = target_word
  );

SELECT
  FORMAT(
    'Found %d occurrences of "%s" across %d Shakespeare works',
    word_count,
    target_word,
    corpus_count
  ) AS result;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by locating the handling of the linesBetweenQueries option and the formatter tests for blank lines between statements. Done means supporting the preserve value so declaration spacing matches the input while query boundaries retain the requested separation shown in the examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.