Skip to content
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

PoC of pretty printing #227

Closed

Conversation

apstndb
Copy link
Contributor

@apstndb apstndb commented Dec 17, 2024

$ go run ./tools/parse --mode query 'WITH CTE AS (SELECT 2 AS n) SELECT * FROM (SELECT * FROM (SELECT 1, 2, 3) CROSS JOIN (SELECT 4, 5, 6)) CROSS JOIN CTE'
...
--- SQL
WITH CTE AS (SELECT 2 AS n) SELECT * FROM (SELECT * FROM (SELECT 1, 2, 3) CROSS JOIN (SELECT 4, 5, 6)) CROSS JOIN CTE
--- SQL with indentation
WITH CTE AS (
  SELECT 2 AS n
)
SELECT *
FROM (
  SELECT *
  FROM (
    SELECT
      1,
      2,
      3
  )
  CROSS JOIN (
    SELECT
      4,
      5,
      6
  )
)
CROSS JOIN CTE


$ go run ./tools/parse --mode ddl 'CREATE TABLE foo (foo INT64, bar FLOAT64 NOT NULL, baz STRING(255) NOT NULL OPTIONS (allow_commit_timestamp = null), qux STRING(255) NOT NULL AS (concat(baz, "a")) STORED, quux JSON, corge TIMESTAMP NOT NULL DEFAULT (current_timestamp()), FOREIGN KEY (foo) REFERENCES t2 (t2key1), FOREIGN KEY (bar) REFERENCES t2 (t2key2) ON DELETE CASCADE, FOREIGN KEY (baz) REFERENCES t2 (t2key3) ON DELETE NO ACTION, CONSTRAINT fkname FOREIGN KEY (foo, bar) REFERENCES t2 (t2key1, t2key2), CHECK (foo > 0), CONSTRAINT cname CHECK (bar > 0)) PRIMARY KEY (foo, bar)'
...
--- SQL
CREATE TABLE foo (foo INT64, bar FLOAT64 NOT NULL, baz STRING(255) NOT NULL OPTIONS (allow_commit_timestamp = null), qux STRING(255) NOT NULL AS (concat(baz, "a")) STORED, quux JSON, corge TIMESTAMP NOT NULL DEFAULT (current_timestamp()), FOREIGN KEY (foo) REFERENCES t2 (t2key1), FOREIGN KEY (bar) REFERENCES t2 (t2key2) ON DELETE CASCADE, FOREIGN KEY (baz) REFERENCES t2 (t2key3) ON DELETE NO ACTION, CONSTRAINT fkname FOREIGN KEY (foo, bar) REFERENCES t2 (t2key1, t2key2), CHECK (foo > 0), CONSTRAINT cname CHECK (bar > 0)) PRIMARY KEY (foo, bar)
--- SQL with indentation
CREATE TABLE foo (
  foo INT64,
  bar FLOAT64 NOT NULL,
  baz STRING(255) NOT NULL OPTIONS (allow_commit_timestamp = null),
  qux STRING(255) NOT NULL AS (concat(baz, "a")) STORED,
  quux JSON,
  corge TIMESTAMP NOT NULL DEFAULT (current_timestamp()),
  FOREIGN KEY (foo) REFERENCES t2 (t2key1),
  FOREIGN KEY (bar) REFERENCES t2 (t2key2) ON DELETE CASCADE,
  FOREIGN KEY (baz) REFERENCES t2 (t2key3) ON DELETE NO ACTION,
  CONSTRAINT fkname FOREIGN KEY (foo, bar) REFERENCES t2 (t2key1, t2key2),
  CHECK (foo > 0),
  CONSTRAINT cname CHECK (bar > 0)
) PRIMARY KEY (foo, bar)

@apstndb apstndb changed the title WIP pretty printing PoC pretty printing Dec 18, 2024
@apstndb apstndb changed the title PoC pretty printing PoC of pretty printing Dec 18, 2024
@apstndb apstndb closed this Dec 19, 2024
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.

1 participant