Skip to content

Conversation

NickCrews
Copy link
Contributor

This is mostly an ergonomics thing.

I don't want to have to import ibis; ibis.to_sql(e), I want to just do e.to_sql()

This also makes the docstring to compile() less confusing, and adds these methods to Columns and Values in the docs.

@cpcloud
Copy link
Member

cpcloud commented Jun 25, 2025

I like this, and often find myself wanting to continue chaining.

Copy link
Member

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would really like to avoid behavior changes like this that don't seem necessary for the stated goal of the PR.

"""
return self._find_backend().compile(
return self._find_backend(use_default=True).compile(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a necessary change? It was explicitly left as False (the default) to avoid people compiling to a dialect that they haven't specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be able to compile unbound expressions to sql:

import ibis

ibis.literal("foo").compile()

This change allows that. Though I agree, the implicitness is not good. Really I think we should add a dialect optional kwarg argument to Expr.compile() and then use that if given, or fall back to the default. Similar to how the new Expr.to_sql() works.

Note that I think it should be called dialect and not backend, because I should be able to supply the string "postgres" and it should work without an actual postgres instance connected.

But, you are right, I think this is out of scope for this PR, let's leave this change out.

Copy link
Contributor Author

@NickCrews NickCrews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this up! looks good.

I also would love to add a toplevel util method like ibis.to_dialect(dialect: str | ibis.BaseBackend) -> sqlglot.compiler | OurPolarsCompiler or similar to make it more friendly when specifying the dialect. Maybe should be called to_compiler() and we actually add a public Compiler class/Protocol that the sqlglot and polars compilers inherit from/implement

"""
return self._find_backend().compile(
return self._find_backend(use_default=True).compile(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be able to compile unbound expressions to sql:

import ibis

ibis.literal("foo").compile()

This change allows that. Though I agree, the implicitness is not good. Really I think we should add a dialect optional kwarg argument to Expr.compile() and then use that if given, or fall back to the default. Similar to how the new Expr.to_sql() works.

Note that I think it should be called dialect and not backend, because I should be able to supply the string "postgres" and it should work without an actual postgres instance connected.

But, you are right, I think this is out of scope for this PR, let's leave this change out.

@cpcloud cpcloud merged commit 493d6e5 into ibis-project:main Jun 26, 2025
132 of 133 checks passed
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.

2 participants