Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 4ceb984

Browse files
trzysiekavelanariusnablaonepdelewski
authored
[WIP] Transpiler 😎 (#1384)
<!-- A note on testing your PR --> <!-- Basic unit test run is executed against each commit in the PR. If you want to run a full integration test suite, you can trigger it by commenting with '/run-integration-tests' or '/run-it' --> --------- Signed-off-by: RafaΕ‚ StrzaliΕ„ski <[email protected]> Co-authored-by: Piotr Grabowski <[email protected]> Co-authored-by: RafaΕ‚ StrzaliΕ„ski <[email protected]> Co-authored-by: Przemek Delewski <[email protected]>
1 parent 867d2fe commit 4ceb984

File tree

23 files changed

+3272
-1
lines changed

23 files changed

+3272
-1
lines changed

β€Žplatform/go.modβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ require (
1919
github.com/gorilla/sessions v1.4.0
2020
github.com/hashicorp/go-multierror v1.1.1
2121
github.com/hashicorp/golang-lru/v2 v2.0.7
22+
github.com/huandu/go-clone v1.7.2
23+
github.com/ip2location/ip2location-go/v9 v9.7.1
2224
github.com/jackc/pgx/v5 v5.7.2
2325
github.com/k0kubun/pp v3.0.1+incompatible
2426
github.com/knadh/koanf/parsers/json v0.1.0
@@ -68,6 +70,7 @@ require (
6870
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
6971
google.golang.org/grpc v1.66.2 // indirect
7072
google.golang.org/protobuf v1.36.1 // indirect
73+
lukechampine.com/uint128 v1.2.0 // indirect
7174
)
7275

7376
require (

β€Žplatform/go.sumβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
7070
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
7171
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
7272
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
73+
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
74+
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
75+
github.com/huandu/go-clone v1.7.2 h1:3+Aq0Ed8XK+zKkLjE2dfHg0XrpIfcohBE1K+c8Usxoo=
76+
github.com/huandu/go-clone v1.7.2/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE=
77+
github.com/ip2location/ip2location-go/v9 v9.7.1 h1:eXu/DqS13QE0h1Yrc9oji+6/anLD9KDf6Ulf5GdIQs8=
78+
github.com/ip2location/ip2location-go/v9 v9.7.1/go.mod h1:MPLnsKxwQlvd2lBNcQCsLoyzJLDBFizuO67wXXdzoyI=
7379
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
7480
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
7581
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
@@ -166,6 +172,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
166172
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
167173
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
168174
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
175+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
169176
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
170177
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
171178
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
@@ -272,8 +279,11 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
272279
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
273280
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
274281
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
282+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
275283
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
276284
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
277285
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
286+
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
287+
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
278288
vitess.io/vitess v0.21.2 h1:SbMdGngyhYurvh2KTZ92VkR5DH5taib+HH4xTkftUWU=
279289
vitess.io/vitess v0.21.2/go.mod h1:n37n5rmIBHYWnoPZod9umrtExlUR/9SbR3VGmanYNMU=

β€Žplatform/parsers/sql/NOTICE.MDβ€Ž

Lines changed: 210 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,213 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6868
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
6969
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7070
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
71-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72+
73+
#### Project: github.com/google/zetasql
74+
Version : a516c6b26d183efc4f56293256bba92e243b7a61
75+
Time : 2024-11-12T20:14:11Z
76+
Licence : Apache-2.0
77+
78+
Contents of licence file https://github.com/google/zetasql/blob/a516c6b26d183efc4f56293256bba92e243b7a61/LICENSE:
79+
80+
Apache License
81+
Version 2.0, January 2004
82+
http://www.apache.org/licenses/
83+
84+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
85+
86+
1. Definitions.
87+
88+
"License" shall mean the terms and conditions for use, reproduction,
89+
and distribution as defined by Sections 1 through 9 of this document.
90+
91+
"Licensor" shall mean the copyright owner or entity authorized by
92+
the copyright owner that is granting the License.
93+
94+
"Legal Entity" shall mean the union of the acting entity and all
95+
other entities that control, are controlled by, or are under common
96+
control with that entity. For the purposes of this definition,
97+
"control" means (i) the power, direct or indirect, to cause the
98+
direction or management of such entity, whether by contract or
99+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
100+
outstanding shares, or (iii) beneficial ownership of such entity.
101+
102+
"You" (or "Your") shall mean an individual or Legal Entity
103+
exercising permissions granted by this License.
104+
105+
"Source" form shall mean the preferred form for making modifications,
106+
including but not limited to software source code, documentation
107+
source, and configuration files.
108+
109+
"Object" form shall mean any form resulting from mechanical
110+
transformation or translation of a Source form, including but
111+
not limited to compiled object code, generated documentation,
112+
and conversions to other media types.
113+
114+
"Work" shall mean the work of authorship, whether in Source or
115+
Object form, made available under the License, as indicated by a
116+
copyright notice that is included in or attached to the work
117+
(an example is provided in the Appendix below).
118+
119+
"Derivative Works" shall mean any work, whether in Source or Object
120+
form, that is based on (or derived from) the Work and for which the
121+
editorial revisions, annotations, elaborations, or other modifications
122+
represent, as a whole, an original work of authorship. For the purposes
123+
of this License, Derivative Works shall not include works that remain
124+
separable from, or merely link (or bind by name) to the interfaces of,
125+
the Work and Derivative Works thereof.
126+
127+
"Contribution" shall mean any work of authorship, including
128+
the original version of the Work and any modifications or additions
129+
to that Work or Derivative Works thereof, that is intentionally
130+
submitted to Licensor for inclusion in the Work by the copyright owner
131+
or by an individual or Legal Entity authorized to submit on behalf of
132+
the copyright owner. For the purposes of this definition, "submitted"
133+
means any form of electronic, verbal, or written communication sent
134+
to the Licensor or its representatives, including but not limited to
135+
communication on electronic mailing lists, source code control systems,
136+
and issue tracking systems that are managed by, or on behalf of, the
137+
Licensor for the purpose of discussing and improving the Work, but
138+
excluding communication that is conspicuously marked or otherwise
139+
designated in writing by the copyright owner as "Not a Contribution."
140+
141+
"Contributor" shall mean Licensor and any individual or Legal Entity
142+
on behalf of whom a Contribution has been received by Licensor and
143+
subsequently incorporated within the Work.
144+
145+
2. Grant of Copyright License. Subject to the terms and conditions of
146+
this License, each Contributor hereby grants to You a perpetual,
147+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
148+
copyright license to reproduce, prepare Derivative Works of,
149+
publicly display, publicly perform, sublicense, and distribute the
150+
Work and such Derivative Works in Source or Object form.
151+
152+
3. Grant of Patent License. Subject to the terms and conditions of
153+
this License, each Contributor hereby grants to You a perpetual,
154+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
155+
(except as stated in this section) patent license to make, have made,
156+
use, offer to sell, sell, import, and otherwise transfer the Work,
157+
where such license applies only to those patent claims licensable
158+
by such Contributor that are necessarily infringed by their
159+
Contribution(s) alone or by combination of their Contribution(s)
160+
with the Work to which such Contribution(s) was submitted. If You
161+
institute patent litigation against any entity (including a
162+
cross-claim or counterclaim in a lawsuit) alleging that the Work
163+
or a Contribution incorporated within the Work constitutes direct
164+
or contributory patent infringement, then any patent licenses
165+
granted to You under this License for that Work shall terminate
166+
as of the date such litigation is filed.
167+
168+
4. Redistribution. You may reproduce and distribute copies of the
169+
Work or Derivative Works thereof in any medium, with or without
170+
modifications, and in Source or Object form, provided that You
171+
meet the following conditions:
172+
173+
(a) You must give any other recipients of the Work or
174+
Derivative Works a copy of this License; and
175+
176+
(b) You must cause any modified files to carry prominent notices
177+
stating that You changed the files; and
178+
179+
(c) You must retain, in the Source form of any Derivative Works
180+
that You distribute, all copyright, patent, trademark, and
181+
attribution notices from the Source form of the Work,
182+
excluding those notices that do not pertain to any part of
183+
the Derivative Works; and
184+
185+
(d) If the Work includes a "NOTICE" text file as part of its
186+
distribution, then any Derivative Works that You distribute must
187+
include a readable copy of the attribution notices contained
188+
within such NOTICE file, excluding those notices that do not
189+
pertain to any part of the Derivative Works, in at least one
190+
of the following places: within a NOTICE text file distributed
191+
as part of the Derivative Works; within the Source form or
192+
documentation, if provided along with the Derivative Works; or,
193+
within a display generated by the Derivative Works, if and
194+
wherever such third-party notices normally appear. The contents
195+
of the NOTICE file are for informational purposes only and
196+
do not modify the License. You may add Your own attribution
197+
notices within Derivative Works that You distribute, alongside
198+
or as an addendum to the NOTICE text from the Work, provided
199+
that such additional attribution notices cannot be construed
200+
as modifying the License.
201+
202+
You may add Your own copyright statement to Your modifications and
203+
may provide additional or different license terms and conditions
204+
for use, reproduction, or distribution of Your modifications, or
205+
for any such Derivative Works as a whole, provided Your use,
206+
reproduction, and distribution of the Work otherwise complies with
207+
the conditions stated in this License.
208+
209+
5. Submission of Contributions. Unless You explicitly state otherwise,
210+
any Contribution intentionally submitted for inclusion in the Work
211+
by You to the Licensor shall be under the terms and conditions of
212+
this License, without any additional terms or conditions.
213+
Notwithstanding the above, nothing herein shall supersede or modify
214+
the terms of any separate license agreement you may have executed
215+
with Licensor regarding such Contributions.
216+
217+
6. Trademarks. This License does not grant permission to use the trade
218+
names, trademarks, service marks, or product names of the Licensor,
219+
except as required for reasonable and customary use in describing the
220+
origin of the Work and reproducing the content of the NOTICE file.
221+
222+
7. Disclaimer of Warranty. Unless required by applicable law or
223+
agreed to in writing, Licensor provides the Work (and each
224+
Contributor provides its Contributions) on an "AS IS" BASIS,
225+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
226+
implied, including, without limitation, any warranties or conditions
227+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
228+
PARTICULAR PURPOSE. You are solely responsible for determining the
229+
appropriateness of using or redistributing the Work and assume any
230+
risks associated with Your exercise of permissions under this License.
231+
232+
8. Limitation of Liability. In no event and under no legal theory,
233+
whether in tort (including negligence), contract, or otherwise,
234+
unless required by applicable law (such as deliberate and grossly
235+
negligent acts) or agreed to in writing, shall any Contributor be
236+
liable to You for damages, including any direct, indirect, special,
237+
incidental, or consequential damages of any character arising as a
238+
result of this License or out of the use or inability to use the
239+
Work (including but not limited to damages for loss of goodwill,
240+
work stoppage, computer failure or malfunction, or any and all
241+
other commercial damages or losses), even if such Contributor
242+
has been advised of the possibility of such damages.
243+
244+
9. Accepting Warranty or Additional Liability. While redistributing
245+
the Work or Derivative Works thereof, You may choose to offer,
246+
and charge a fee for, acceptance of support, warranty, indemnity,
247+
or other liability obligations and/or rights consistent with this
248+
License. However, in accepting such obligations, You may act only
249+
on Your own behalf and on Your sole responsibility, not on behalf
250+
of any other Contributor, and only if You agree to indemnify,
251+
defend, and hold each Contributor harmless for any liability
252+
incurred by, or claims asserted against, such Contributor by reason
253+
of your accepting any such warranty or additional liability.
254+
255+
END OF TERMS AND CONDITIONS
256+
257+
APPENDIX: How to apply the Apache License to your work.
258+
259+
To apply the Apache License to your work, attach the following
260+
boilerplate notice, with the fields enclosed by brackets "[]"
261+
replaced with your own identifying information. (Don't include
262+
the brackets!) The text should be enclosed in the appropriate
263+
comment syntax for the file format. We also recommend that a
264+
file or class name and description of purpose be included on the
265+
same "printed page" as the copyright notice for easier
266+
identification within third-party archives.
267+
268+
Copyright [yyyy] [name of copyright owner]
269+
270+
Licensed under the Apache License, Version 2.0 (the "License");
271+
you may not use this file except in compliance with the License.
272+
You may obtain a copy of the License at
273+
274+
http://www.apache.org/licenses/LICENSE-2.0
275+
276+
Unless required by applicable law or agreed to in writing, software
277+
distributed under the License is distributed on an "AS IS" BASIS,
278+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
279+
See the License for the specific language governing permissions and
280+
limitations under the License.

β€Žplatform/parsers/sql/lexer/dialect_sqlparse/rule.goβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ var SQL_REGEX = []core.Rule{
138138

139139
core.NewRegexRule(`[;:()\[\],\.]`, &PunctuationTokenType),
140140

141+
// MODIFICATION: New rule for SQL with pipe syntax (|>)
142+
// Negative lookahead rule to make sure this doesn't match |>>
143+
// (PostGIS |>> operator: https://postgis.net/docs/ST_Geometry_Above.html)
144+
// FIXME: this shouldn't be in "vanilla" dialect_sqlparse, but in a separate dialect
145+
NewNegativeLookaheadRule(`\|>`, `>`, &PipeTokenType),
146+
141147
core.NewRegexRule(`(\->>?|#>>?|@>|<@|\?\|?|\?&|\-|#\-)`, &OperatorTokenType),
142148
core.NewRegexRule(`[<>=~!]+`, &ComparisonOperatorTokenType),
143149
core.NewRegexRule(`[+/@#%^&|^-]+`, &OperatorTokenType),

β€Žplatform/parsers/sql/lexer/dialect_sqlparse/token.goβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ var ErrorTokenType = core.TokenType{
158158
Name: "Token.Error",
159159
Description: "Error token. The input at this position did not match any rule, so this character was skipped",
160160
}
161+
162+
var PipeTokenType = core.TokenType{
163+
Name: "Token.Keyword.Pipe",
164+
Description: "SQL with pipe syntax operator |>",
165+
}

β€Žplatform/parsers/sql/lexer/dialects_sqlfluff/ansi/rule.goβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ var ansiRules = []core.Rule{
4646
// core.NewRegexRule(`\r\n|\n`, &NewlineTokenType),
4747
core.NewRegexRule(`(\r\n|\r|\n)`, &NewlineTokenType),
4848

49+
// MODIFICATION: New rule for SQL with pipe syntax (|>)
50+
// Negative lookahead rule to make sure this doesn't match |>>
51+
// (PostGIS |>> operator: https://postgis.net/docs/ST_Geometry_Above.html)
52+
// FIXME: this shouldn't be in "vanilla" dialect_sqlfluff, but in a separate dialect
53+
dialect_sqlparse.NewNegativeLookaheadRule(`\|>`, `>`, &PipeTokenType),
54+
4955
core.NewStringRule(`::`, &CodeTokenType),
5056
core.NewStringRule(`=`, &CodeTokenType),
5157
core.NewStringRule(`>`, &CodeTokenType),

β€Žplatform/parsers/sql/lexer/dialects_sqlfluff/ansi/token.goβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ var WordTokenType = core.TokenType{
4848
Name: "WordSegment",
4949
Description: "Word segment",
5050
}
51+
52+
var PipeTokenType = core.TokenType{
53+
Name: "PipeKeywordSegment",
54+
Description: "SQL with pipe syntax operator |>",
55+
}

0 commit comments

Comments
Β (0)