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

[FORMATTING] Space between type and options removed in nested BigQuery fields

Open
#619 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When formatting BigQuery DDL statement with OPTIONS on a Struct field, any space between the type definition and the Options definition is removed, resulting in an invalid statement.

Input data

CREATE TABLE `project.dataset.format_test`
(
 str STRING OPTIONS(description="A string field."),
 int INT64  OPTIONS(description="An int64 field."),
 record STRUCT<nested INT64 OPTIONS(description="a struct field")> OPTIONS(description="a struct")
)

Expected Output

CREATE TABLE
  `project.dataset.format_test` (
    str STRING OPTIONS(description = "A string field."),
    int INT64 OPTIONS(description = "An int64 field."),
    record STRUCT<nested INT64 OPTIONS(description ="a struct field")> OPTIONS(description = "a struct")
  )

Actual Output

CREATE TABLE
  `project.dataset.format_test` (
    str STRING OPTIONS(description = "A string field."),
    int INT64 OPTIONS(description = "An int64 field."),
    record STRUCT<nested INT64OPTIONS(description ="a struct field")> OPTIONS(description = "a struct")
  )

Usage

To run this I've stored the input in a file called example-sql.sql and am running:

> sql-formatter --v
12.2.3

> sql-formatter -l bigquery example-sql.sql
CREATE TABLE
  `project.dataset.format_test` (
    str STRING OPTIONS(description = "A string field."),
    int INT64 OPTIONS(description = "An int64 field."),
    record STRUCT<nested INT64OPTIONS(description ="a struct field")> OPTIONS(description = "a struct")
  )

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

Start by reproducing the issue with the BigQuery input in example-sql.sql, using the sql-formatter -l bigquery example-sql.sql command shown. Trace the BigQuery formatting path for nested STRUCT fields and compare its output with the expected statement. Done means the space before nested OPTIONS is preserved and the formatted DDL matches the expected structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.