Skip to content

feat: Schema.from_sqlglot() #11310

Open
Open
@zilto

Description

@zilto

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeatures or general enhancements

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions