Skip to content

Commit 8c80fe2

Browse files
authored
build: switch to substrait-antlr (#153)
Generated ANTLR code can now be found in the substrait-antlr package BREAKING CHANGE: module substrait.gen.antlr has been removed
1 parent 2424f2c commit 8c80fe2

13 files changed

Lines changed: 328 additions & 5356 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Substrait Package Version Checks
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
substrait-package-version-checks:
11+
name: Verify substrait-* Package Versions
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v6
16+
with:
17+
submodules: recursive
18+
19+
- name: Install uv with python
20+
uses: astral-sh/setup-uv@v7
21+
22+
- name: Verify substrait-* versions
23+
run: ./check_substrait_package_versions.sh
24+

CONTRIBUTING.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ Copy the core function extensions into substrait-python
4545
pixi run copy-extensions
4646
```
4747

48-
## Antlr grammar
49-
50-
Substrait uses antlr grammar to derive output types of extension functions. Make sure java is installed and ANTLR_JAR environment variable is set. Take a look at .devcontainer/Dockerfile for example setup.
51-
52-
```
53-
pixi run antlr
54-
```
55-
5648
## Extensions stubs
5749

5850
Substrait uses jsonschema to describe the data model for extension files.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Check that all substrait-* packages have the same version
5+
uv sync
6+
7+
protobuf_version=$(uv pip show substrait-protobuf | grep '^Version:' | awk '{print $2}')
8+
antlr_version=$(uv pip show substrait-antlr | grep '^Version:' | awk '{print $2}')
9+
10+
if [ "$protobuf_version" != "$antlr_version" ]; then
11+
echo "error: substrait-protobuf ($protobuf_version) and substrait-antlr ($antlr_version) versions do not match"
12+
exit 1
13+
fi

pixi.lock

Lines changed: 22 additions & 1697 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ dynamic = ["version"]
1515
write_to = "src/substrait/_version.py"
1616

1717
[project.optional-dependencies]
18-
extensions = ["antlr4-python3-runtime", "pyyaml"]
18+
extensions = ["antlr4-python3-runtime", "substrait-antlr==0.79.0", "pyyaml"]
1919
sql = ["sqloxide; python_version < '3.14'", "deepdiff"]
2020

2121
[dependency-groups]
22-
dev = ["pytest >= 7.0.0", "antlr4-python3-runtime", "pyyaml", "sqloxide; python_version < '3.14'", "deepdiff", "duckdb<=1.2.2; python_version < '3.14'", "datafusion"]
22+
dev = ["pytest >= 7.0.0", "antlr4-python3-runtime", "substrait-antlr==0.79.0", "pyyaml", "sqloxide; python_version < '3.14'", "deepdiff", "duckdb<=1.2.2; python_version < '3.14'", "datafusion"]
2323

2424
[tool.pytest.ini_options]
2525
pythonpath = "src"
@@ -56,19 +56,12 @@ update-substrait = [ { task = "update-submodule" }, { task = "codegen" }]
5656

5757
update-submodule = "./update_submodule.sh"
5858

59-
codegen = [{ task = "antlr" }, { task = "copy-extensions" }, { task = "codegen-extensions" }]
59+
codegen = [{ task = "copy-extensions" }, { task = "codegen-extensions" }]
6060

6161
check-codegen = "./check_codegen.sh"
6262

6363
copy-extensions = "./copy_extension_yamls.sh"
6464

65-
antlr = """
66-
cd third_party/substrait/grammar \
67-
&& antlr4 -o ../../../src/substrait/gen/antlr -Dlanguage=Python3 SubstraitType.g4 \
68-
&& rm ../../../src/substrait/gen/antlr/*.tokens \
69-
&& rm ../../../src/substrait/gen/antlr/*.interp
70-
"""
71-
7265
codegen-extensions = """
7366
datamodel-codegen \
7467
--input-file-type jsonschema \
@@ -81,7 +74,5 @@ codegen-extensions = """
8174
"""
8275

8376
[tool.pixi.dependencies]
84-
antlr = ">=4.13.2,<5"
85-
buf = ">=1.62.1,<2"
8677
datamodel-code-generator = ">=0.52.0,<0.53"
8778
ruff = ">=0.14.10,<0.15"

src/substrait/derivation_expression.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
from antlr4 import CommonTokenStream, InputStream
44
from substrait.type_pb2 import NamedStruct, Type
5-
6-
from substrait.gen.antlr.SubstraitTypeLexer import SubstraitTypeLexer
7-
from substrait.gen.antlr.SubstraitTypeParser import SubstraitTypeParser
5+
from substrait_antlr.substrait_type.SubstraitTypeLexer import SubstraitTypeLexer
6+
from substrait_antlr.substrait_type.SubstraitTypeParser import SubstraitTypeParser
87

98

109
def _evaluate(x, values: dict):

src/substrait/extension_registry/signature_checker_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from typing import Dict
44

55
from substrait.type_pb2 import Type
6+
from substrait_antlr.substrait_type.SubstraitTypeParser import SubstraitTypeParser
67

78
from substrait.derivation_expression import _evaluate
8-
from substrait.gen.antlr.SubstraitTypeParser import SubstraitTypeParser
99

1010
from .exceptions import UnhandledParameterizedTypeError, UnrecognizedSubstraitTypeError
1111

src/substrait/gen/antlr/SubstraitTypeLexer.py

Lines changed: 0 additions & 386 deletions
This file was deleted.

0 commit comments

Comments
 (0)