Skip to content

chore: add ruff checks to ci #79

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

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run linter and formatter

on:
pull_request:
push:
branches: [ main ]
tags: [ 'v*.*.*' ]

permissions:
contents: read

jobs:
test:
name: Lint and Format
strategy:
matrix:
os: [ubuntu-latest]
python: ["3.9"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install uv with python
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python }}
- name: Run ruff linter
run: |
uvx [email protected] check
- name: Run ruff formatter
run: |
uvx [email protected] format
17 changes: 14 additions & 3 deletions examples/adbc_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
names=["ints", "strs"],
)


def read_adbc_named_table(name: str, conn):
pa_schema = conn.adbc_get_table_schema(name)
substrait_schema = pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
substrait_schema = (
pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
)
return read_named_table(name, substrait_schema)


with adbc_driver_duckdb.dbapi.connect(":memory:") as conn:
with conn.cursor() as cur:
cur.adbc_ingest("AnswerToEverything", data)
Expand All @@ -38,7 +42,14 @@ def read_adbc_named_table(name: str, conn):
cur.executescript("LOAD substrait;")

table = read_adbc_named_table("AnswerToEverything", conn)
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'gte', column('ints'), literal(3, i64())))
table = filter(
table,
expression=scalar_function(
"functions_comparison.yaml",
"gte",
expressions=[column("ints"), literal(3, i64())],
),
)

cur.execute(table(registry).SerializeToString())
print(cur.fetch_arrow_table())
print(cur.fetch_arrow_table())
23 changes: 12 additions & 11 deletions examples/builder_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
registry = ExtensionRegistry(load_default_extensions=True)

ns = named_struct(
names=["id", "is_applicable"],
struct=struct(
types=[
i64(nullable=False),
boolean()
]
)
names=["id", "is_applicable"], struct=struct(types=[i64(nullable=False), boolean()])
)

table = read_named_table('example_table', ns)
table = filter(table, expression=column('is_applicable'))
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'lt', column('id'), literal(100, i64())))
table = project(table, expressions=[column('id')])
table = read_named_table("example_table", ns)
table = filter(table, expression=column("is_applicable"))
table = filter(
table,
expression=scalar_function(
"functions_comparison.yaml",
"lt",
expressions=[column("id"), literal(100, i64())],
),
)
table = project(table, expressions=[column("id")])

print(table(registry))

Expand Down
21 changes: 17 additions & 4 deletions examples/duckdb_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

try:
duckdb.install_extension("substrait")
except:
except duckdb.duckdb.HTTPException:
duckdb.install_extension("substrait", repository="community")
duckdb.load_extension("substrait")

Expand All @@ -29,14 +29,27 @@

registry = ExtensionRegistry(load_default_extensions=True)


def read_duckdb_named_table(name: str, conn):
pa_schema = conn.sql(f"SELECT * FROM {name} LIMIT 0").arrow().schema
substrait_schema = pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
substrait_schema = (
pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
)
return read_named_table(name, substrait_schema)


table = read_duckdb_named_table("customer", duckdb)
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'equal', column('c_nationkey'), literal(3, i32())))
table = project(table, expressions=[column('c_name'), column('c_address'), column('c_nationkey')])
table = filter(
table,
expression=scalar_function(
"functions_comparison.yaml",
"equal",
expressions=[column("c_nationkey"), literal(3, i32())],
),
)
table = project(
table, expressions=[column("c_name"), column("c_address"), column("c_nationkey")]
)

sql = f"CALL from_substrait_json('{dump_json(table(registry))}')"
print(duckdb.sql(sql))
15 changes: 6 additions & 9 deletions examples/pyarrow_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
import substrait
from substrait.builders.plan import project, read_named_table

arrow_schema = pa.schema([
pa.field("x", pa.int32()),
pa.field("y", pa.int32())
])
arrow_schema = pa.schema([pa.field("x", pa.int32()), pa.field("y", pa.int32())])

substrait_schema = pa_substrait.serialize_schema(arrow_schema).to_pysubstrait().base_schema
substrait_schema = (
pa_substrait.serialize_schema(arrow_schema).to_pysubstrait().base_schema
)

substrait_expr = pa_substrait.serialize_expressions(
exprs=[pc.field("x") + pc.field("y")],
names=["total"],
schema=arrow_schema
exprs=[pc.field("x") + pc.field("y")], names=["total"], schema=arrow_schema
)

pysubstrait_expr = substrait.proto.ExtendedExpression.FromString(bytes(substrait_expr))

table = read_named_table("example", substrait_schema)
table = project(table, expressions=[pysubstrait_expr])(None)
print(table)
print(table)
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ respect-gitignore = true
target-version = "py39"
# never autoformat upstream or generated code
exclude = ["third_party/", "src/substrait/gen"]
# do not autofix the following (will still get flagged in lint)
lint.unfixable = [
"F401", # unused imports
"T201", # print statements
]
Loading