ibis icon indicating copy to clipboard operation
ibis copied to clipboard

feat: `Schema.from_sqlglot()`

Open zilto opened this issue 5 months ago • 1 comments

Is your feature request related to a problem?

issue: Schema.to_sqlglot()

The semantics of .to_sqlglot() are a bit confusing. I expected the output to be a sqlglot.schema.Schema type with a single table.

Maybe it could be renamed to .to_sqlglot_columns_definition() ?

edit: I see some of this logic in available in ibis/expr/sql.py

add: Schema.from_sqlglot()

I'm working on dlt-hub/dlt and we use Ibis and SQLGlot for some internal component.

Currently, we maintain type-mapping between dlt <-> ibis and dlt <-> sqlglot. Some operations need schema conversion from ibis -> sqlglot or sqlglot -> ibis.

I would be convenient if Schema.from_sqlglot() was supported (Schema.to_sqlglot() already existing). This would streamline conversions between tools.

What is the motivation behind your request?

No response

Describe the solution you'd like

import sqlglot.schema

class Schema:
  # ...
  @classmethod 
  def from_sqlglot(cls, sqlglot_schema: sqlglot.schema.Schema) -> "Schema":
    from ibis.formats.sqlglot import SQLGlotSchema
    
    return SQLGlotSchema.to_ibis(sqlglot_schema)

  def to_sqlglot(self) -> sqlglot.schema.Schema:
    from ibis.formats.sqlglot import SQLGlotSchema

    return SQLGlotSchema.from_ibis(self)

  def to_sqlglot_columns_definition(self):
    # logic of the current `.to_sqlglot()`

What version of ibis are you running?

10.5.0

What backend(s) are you using, if any?

Used to support multiple backends

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

zilto avatar Jun 06 '25 16:06 zilto

+1 on this change.

cpcloud avatar Jun 09 '25 14:06 cpcloud

I'd like to work on adding from_sqlglot!

IndexSeek avatar Jun 18 '25 00:06 IndexSeek

Happy to see the refactor to_sqlglot() to to_sqlglot_columns_definition() merged! Though, maybe the issue should be reopened for the other methods:

  • to_sqlglot(self) -> SQLGlotSchema:
  • from_sqlglot(cls, sqlglot_schema: SQLGlotSchema) -> Schema: (#11351)

zilto avatar Jul 24 '25 19:07 zilto