Skip to content

Add create_sql_view method to Catalog#3415

Open
ebyhr wants to merge 1 commit into
apache:mainfrom
ebyhr:ebi/views
Open

Add create_sql_view method to Catalog#3415
ebyhr wants to merge 1 commit into
apache:mainfrom
ebyhr:ebi/views

Conversation

@ebyhr

@ebyhr ebyhr commented May 26, 2026

Copy link
Copy Markdown
Member

Rationale for this change

PyIceberg users currently need to provide a redundant object when creating a view.

dentifier = "default.some_view"
schema = pa.schema([pa.field("some_col", pa.int32())])
view_version = ViewVersion(
    version_id=1,
    schema_id=1,
    timestamp_ms=int(time.time() * 1000),
    summary={},
    representations=[
        SQLViewRepresentation(
            type="sql",
            sql="SELECT 1 as some_col",
            dialect="spark",
        )
    ],
    default_namespace=["default"],
)

catalog.create_view(
    identifier=identifier,
    schema=schema,
    view_version=view_version,
)

We could internally initialize version_id, schema_id, and timestamp_ms fields. This PR introduces a new create_sql_view method.

catalog.create_sql_view(
    identifier=identifier,
    schema=schema,
    dialect="spark",
    sql="SELECT 1 as some_col",
    default_namespace=("default",),
)

Are these changes tested?

Yes

Are there any user-facing changes?

Add create_sql_view method to Catalog

@ebyhr
ebyhr marked this pull request as ready for review May 26, 2026 04:31

@gabeiglio gabeiglio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

Comment thread pyiceberg/catalog/__init__.py Outdated

@rambleraptor rambleraptor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm lightly opinionated on making this a helper function that takes in a Catalog, rather than a new method on the Catalog itself.

@abnobdoss abnobdoss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good! Left a few minor comments.


Args:
identifier (str | Identifier): View identifier.
schema (Schema): View's schema.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
schema (Schema): View's schema.
schema (Schema | pa.Schema): View's schema.

properties: Properties = EMPTY_DICT,
default_catalog: str | None = None,
) -> View:
"""Create a view.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this description be different from create_view?


view_version = ViewVersion(
version_id=1,
schema_id=iceberg_schema.schema_id,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this schema_id discarded later in the self.create_view call later?

fresh_schema = assign_fresh_schema_ids(iceberg_schema)



@pytest.mark.integration
def test_rest_create_sql_view(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The create_sql_view function has a few permutations of accepted values - e.g. default_namespace accepts both str & Identifier. Could we expand the test coverage to cover the various signature paths?

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants