Skip to content

Commit 1936b9e

Browse files
committed
Add new impl
1 parent 1933ace commit 1936b9e

File tree

22 files changed

+582
-217
lines changed

22 files changed

+582
-217
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# widely accepted by compilers. This may lead to strange behavior or compiler
2121
# errors in earlier compilers.
2222
build --cxxopt="-std=c++1z"
23+
build --sandbox_debug --verbose_failures
24+
build --cxxopt="-DNDEBUG"
25+
build --workspace_status_command "tools/workspace_status.sh"
2326
# By default, we don't suppress any warnings, to get clang-specific warning
2427
# suppression you can invoke with --config=clang
2528
build:clang --cxxopt=-Wno-deprecated-declarations

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0
1+
4.1.0

.github/workflows/build.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build
2+
on: push
3+
env:
4+
cache-version: v1.0.2
5+
jobs:
6+
linux:
7+
name: Test the repository on Linux
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout the repository
11+
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.ref }}
14+
fetch-depth: 0
15+
- name: Cache
16+
uses: pat-s/[email protected]
17+
with:
18+
path: ~/.cache/bazel
19+
key: ${{ env.cache-version }}-${{ runner.os }}-bazelisk-build-${{ hashFiles('./**') }}
20+
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-bazelisk-build-
21+
- name: Setup
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install --no-install-recommends -y gcc-9 g++-9
25+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 900 \
26+
--slave /usr/bin/g++ g++ /usr/bin/g++-9
27+
bazelisk test --test_output=errors //zetasql/public:sql_formatter_test
28+
bazelisk build //zetasql/tools/zetasql-formatter:format
29+
sudo cp bazel-bin/zetasql/tools/zetasql-formatter/format zetasql-formatter
30+
zip zetasql-formatter_linux_x86_64.zip zetasql-formatter
31+
- name: Test
32+
run: |
33+
cd zetasql/tools/zetasql-formatter
34+
ls example_tests | xargs -n1 -I {} sh -c 'cat example_tests/{} | ../../../zetasql-formatter > example_tests_formatted/{}'
35+
git diff --exit-code -- '*.sql'
36+
- name: Release
37+
uses: softprops/action-gh-release@v1
38+
if: startsWith(github.ref, 'refs/tags/')
39+
with:
40+
files: zetasql-formatter_linux_x86_64.zip
41+
prerelease: true
42+
generate_release_notes: true
43+
macos:
44+
name: Test the repository
45+
runs-on: macos-10.15
46+
steps:
47+
- name: Checkout the repository
48+
uses: actions/checkout@v2
49+
with:
50+
ref: ${{ github.ref }}
51+
fetch-depth: 0
52+
- name: Cache
53+
uses: pat-s/[email protected]
54+
with:
55+
path: ~/.cache/bazel
56+
key: ${{ env.cache-version }}-${{ runner.os }}-bazelisk-build-${{ hashFiles('./**') }}
57+
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-bazelisk-build-
58+
- name: Setup
59+
run: |
60+
export TEST_TMPDIR=~/.cache/bazel
61+
CC=g++ bazelisk test --test_output=errors //zetasql/public:sql_formatter_test
62+
CC=g++ bazelisk build //zetasql/tools/zetasql-formatter:format
63+
sudo cp bazel-bin/zetasql/tools/zetasql-formatter/format zetasql-formatter
64+
zip zetasql-formatter_darwin_amd64.zip zetasql-formatter
65+
- name: Test
66+
run: |
67+
cd zetasql/tools/zetasql-formatter
68+
ls example_tests | xargs -n1 -I {} sh -c 'cat example_tests/{} | ../../../zetasql-formatter > example_tests_formatted/{}'
69+
git diff --exit-code -- '*.sql'
70+
- name: Release
71+
uses: softprops/action-gh-release@v1
72+
if: startsWith(github.ref, 'refs/tags/')
73+
with:
74+
files: zetasql-formatter_darwin_amd64.zip
75+
prerelease: true
76+
generate_release_notes: true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/external
2+
/bazel-*
3+
/compile_commands.json
4+
/.cache/

README.md

Lines changed: 65 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,70 @@
1-
## ZetaSQL - Analyzer Framework for SQL
2-
3-
ZetaSQL defines a language (grammar, types, data model, and semantics) as well
4-
as a parser and analyzer. It is not itself a database or query engine. Instead
5-
it is intended to be used by multiple engines wanting to provide consistent
6-
behavior for all semantic analysis, name resolution, type checking, implicit
7-
casting, etc. Specific query engines may not implement all features in the
8-
ZetaSQL language and may give errors if specific features are not supported. For
9-
example, engine A may not support any updates and engine B may not support
10-
analytic functions.
11-
12-
[ZetaSQL Language Guide](docs/README.md)
13-
14-
[ZetaSQL ResolvedAST API](docs/resolved_ast.md)
15-
16-
## Status of Project and Roadmap
17-
18-
This codebase is being open sourced in multiple phases:
19-
20-
1. Parser and Analyzer **Complete**
21-
- Initial release includes only a subset of tests
22-
2. Reference Implementation **In Progress**
23-
- Base capability **Complete**
24-
- Function library **In Progress**
25-
3. Compliance Tests **Complete**
26-
- includes framework for validating compliance of arbitrary engines
27-
4. Misc tooling
28-
- Improved Formatter **In Progress**
29-
30-
Multiplatform support is planned for the following platforms:
31-
32-
- Linux (Ubuntu 1804 _with gcc8_ is our reference platform, but others may work).
33-
- MacOS (Experimental)
34-
- Windows (version TDB)
35-
36-
Until all this code is released, we cannot provide any guarantees of API
37-
stability and cannot accept contributions. We will also be releasing more
38-
documentation over time, particular related to developing engines with this
39-
framework. Documentation on the [language](docs/) itself is fairly
40-
complete.
41-
42-
43-
## Flags
44-
ZetaSQL uses the Abseil [Flags](https://abseil.io/blog/20190509-flags) library
45-
to handle commandline flags. Unless otherwise documented, all flags are for
46-
debugging purposes only and may change, stop working or be removed at any time.
47-
48-
49-
## How to Build
50-
51-
ZetaSQL uses [bazel](https://bazel.build) for building and dependency
52-
resolution. After installing bazel (we maintain support for 1.0,
53-
but other versions may work), simply run:
54-
55-
```bazel build ...```
56-
57-
## How to add as a Dependency in bazel
58-
See the (WORKSPACE) file, as it is a little unusual.
59-
60-
### With docker
61-
TODO: Add docker build script.
62-
63-
## Example Usage
64-
A very basic command line tool is available to run simple queries with the
65-
reference implementation:
66-
```bazel run //zetasql/tools/execute_query:execute_query -- "select 1 + 1;"```
67-
68-
The reference implementation is not yet completely released and currently
69-
supports only a subset of functions and types.
70-
71-
## Differential Privacy
72-
For questions, documentation and examples of ZetaSQLs implementation of
73-
Differential Privacy, please check out
74-
(https://github.com/google/differential-privacy).
75-
76-
## Versions
77-
78-
ZetaSQL makes no guarantees regarding compatibility between releases.
79-
Breaking changes may be made at any time. Our releases are numbered based
80-
on the date of the commit the release is cut from. The number format is
81-
YYYY.MM.n, where YYYY is the year, MM is the two digit month, and n is a
82-
sequence number within the time period.
1+
## ZetaSQL Formatter
2+
3+
[![build](https://github.com/Matts966/zetasql-formatter/workflows/Build/badge.svg?branch=main)](https://github.com/Matts966/zetasql-formatter/actions?query=branch%main+workflow%3ABuild+)
4+
5+
<p align="center">
6+
<img src="./docs/changes.png">
7+
</p>
8+
9+
This repository is forked from [google/zetasql](https://github.com/google/zetasql) and provides SQL formatter with preserved comments. This formatter can be applied to mainly BigQuery and SpanSQL.
10+
11+
## Quick Start
12+
13+
```bash
14+
# To install for MacOSX
15+
wget https://github.com/Matts966/zetasql-formatter/releases/latest/download/zetasql-formatter_darwin_amd64.zip \
16+
&& sudo unzip zetasql-formatter_darwin_amd64.zip -d /usr/local/bin
17+
```
18+
19+
```bash
20+
# To install for Linux
21+
wget https://github.com/Matts966/zetasql-formatter/releases/latest/download/zetasql-formatter_linux_x86_64.zip \
22+
&& sudo unzip zetasql-formatter_linux_x86_64.zip -d /usr/local/bin
23+
```
24+
25+
```bash
26+
# To apply formatter for files
27+
$ zetasql-formatter [files and directories]
28+
29+
# Format stdin
30+
$ echo "select * from test" | zetasql-formatter
31+
SELECT
32+
*
33+
FROM
34+
test;
35+
36+
$ zetasql-formatter
37+
select * from ok;
38+
-- CTRL-D
39+
SELECT
40+
*
41+
FROM
42+
ok;
43+
-- CTRL-D
44+
```
45+
46+
## Integration with [efm-langserver](https://github.com/mattn/efm-langserver)
47+
48+
- Install efm-langserver
49+
- Locate [`config.yaml`](https://github.com/mattn/efm-langserver#example-for-configyaml) like below
50+
51+
```yaml
52+
version: 2
53+
tools:
54+
zetasql-formatter: &zetasql-formatter
55+
format-command: zetasql-formatter
56+
format-stdin: true
57+
languages:
58+
sql:
59+
- <<: *zetasql-formatter
60+
sql-bigquery:
61+
- <<: *zetasql-formatter
62+
```
8363
8464
## License
8565
8666
[Apache License 2.0](LICENSE)
8767
88-
## Support Disclaimer
89-
This is not an officially supported Google product.
68+
## Sponsors
69+
70+
The development of this formatter is sponsored by the Japan Data Science Consortium.

WORKSPACE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,25 @@ load("@com_google_zetasql//bazel:zetasql_deps_step_4.bzl", "zetasql_deps_step_4"
9292

9393
zetasql_deps_step_4()
9494

95+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
96+
git_repository(
97+
name = "com_github_gflags_gflags",
98+
remote = "https://github.com/gflags/gflags.git",
99+
tag = "v2.2.2"
100+
)
101+
102+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
103+
104+
# Hedron's Compile Commands Extractor for Bazel
105+
# https://github.com/hedronvision/bazel-compile-commands-extractor
106+
http_archive(
107+
name = "hedron_compile_commands",
108+
109+
# Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
110+
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
111+
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/af9af15f7bc16fc3e407e2231abfcb62907d258f.tar.gz",
112+
strip_prefix = "bazel-compile-commands-extractor-af9af15f7bc16fc3e407e2231abfcb62907d258f",
113+
# When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
114+
)
115+
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
116+
hedron_compile_commands_setup()

docs/changes.png

511 KB
Loading

tools/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package(
2424

2525
exports_files([
2626
"pom-template.xml",
27+
"workspace_status.sh",
2728
])
2829

2930
bzl_library(

tools/workspace_status.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "STABLE_BUILD_GIT_DESCRIBE $(git describe --tags)"

zetasql/parser/gen_extra_files.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class ParseTreeVisitor {
7070
public:
7171
virtual ~ParseTreeVisitor() {}
7272
virtual void visit(const ASTNode *node, void* data) = 0;
73+
virtual void visitStart(const ASTNode *node, void* data) {};
74+
virtual void visitEnd(const ASTNode *node, void* data) {};
7375
''')
7476
for cls in concrete_classes:
7577
yield (' virtual void visit{0}(const {0}* node, void* data) = 0;\n\n'
@@ -153,7 +155,9 @@ def GeneerateParseTreeAcceptMethods(
153155
for cls in concrete_classes:
154156
yield textwrap.dedent('''\
155157
void {0}::Accept(ParseTreeVisitor* visitor, void* data) const {{
158+
visitor->visitStart(this, data);
156159
visitor->visit{0}(this, data);
160+
visitor->visitEnd(this, data);
157161
}}
158162
159163
''').format(cls)

0 commit comments

Comments
 (0)