Skip to content

refactor(view)!: require named SQL fields and explicit dialect - #2324

Merged
zeroshade merged 7 commits into
apache:mainfrom
fallintoplace:refactor/view-sql-fields-and-dialect-upstream-20261024
Oct 27, 2026
Merged

zeroshade merged 7 commits into
apache:mainfrom
fallintoplace:refactor/view-sql-fields-and-dialect-upstream-20261024

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

  • Use named fields for SQL view representations.
  • Require a dialect when creating a view.

Why

  • This keeps the SQL and its dialect together and avoids a hidden default.

Implementation

  • Pass dialect through view and SQL catalog creation.
  • Preserve the selected dialect when Hive creates a view.

Refs #2062.

Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
@fallintoplace
fallintoplace force-pushed the refactor/view-sql-fields-and-dialect-upstream-20261024 branch from 2bb9140 to 5da8a60 Compare October 25, 2026 11:14

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The Hive change is a real fix: CreateView now keeps the chosen representation's dialect instead of rewriting it to default, and view_dialect_test.go pins it. Requiring an explicit dialect also removes a hidden default. Merged with current main, vet (including -tags integration) and the view, Hive and SQL catalog tests pass.

The PR moves NewRepresentation to named fields because SQL and dialect are both strings and can be swapped, but then adds new positional viewSQL, viewDialect string pairs to view.CreateView, CreateViewWithIOProperties, NewVersionFromSQL and sql.Catalog.CreateView, which is the same swap hazard (details inline). Since these are breaking changes anyway, please make them consistent. Also, the two compatibility notes from 5da8a60 were dropped by the "sync release notes with main" commit; these APIs are in v0.7.0, so please restore them.

Comment thread view/view.go Outdated
viewIdent table.Identifier,
schema *iceberg.Schema,
viewSQL string,
viewDialect string,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These two adjacent string parameters are the swap hazard this PR removes from NewRepresentation, and since both are non-empty, validation can't catch a swap. Could CreateView and CreateViewWithIOProperties take a view.Representation ({SQL: ..., Dialect: ...}) instead?

Comment thread view/metadata.go Outdated
func NewVersionFromSQL(id int64, schemaID int, sql string, defaultNS table.Identifier, opts ...VersionOpt) (*Version, error) {
return NewVersion(id, schemaID, Representations{NewRepresentation(sql, "default")}, defaultNS, opts...)
// using the provided SQL and dialect.
func NewVersionFromSQL(id int64, schemaID int, sql, dialect string, defaultNS table.Identifier, opts ...VersionOpt) (*Version, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here: NewVersionFromSQL(id, schemaID, sql, dialect string, ...) puts the pair back as positional strings. Taking a Representation would match NewRepresentation.

Comment thread catalog/sql/sql.go Outdated

// CreateView creates a new view in the catalog.
func (c *Catalog) CreateView(ctx context.Context, identifier table.Identifier, schema *iceberg.Schema, viewSQL string, props iceberg.Properties) error {
func (c *Catalog) CreateView(ctx context.Context, identifier table.Identifier, schema *iceberg.Schema, viewSQL, viewDialect string, props iceberg.Properties) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for sql.Catalog.CreateView: viewSQL, viewDialect string can be swapped silently.

Comment thread view/metadata.go
}
// NewRepresentation creates a SQL view representation from named fields.
// The SQL and Dialect fields are validated by NewVersion.
func NewRepresentation(repr Representation) Representation {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: with named fields, this only sets Type = "sql" on its argument. It's fine to keep as a helper, but NewVersion could also treat an empty Type as "sql" so callers can use the struct literal directly. Your call.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this is the consistent shape: the creation APIs and NewVersionFromSQL now take a view.Representation, so SQL and dialect can't be swapped anywhere, Hive passes the selected representation through intact, and both compatibility notes are back. Your merge of main (6c8a240) merges cleanly with current main, and go vet ./... (including -tags integration) and the view, Hive and SQL catalog tests pass on it. LGTM.

@zeroshade
zeroshade merged commit 362f47e into apache:main Oct 27, 2026
16 checks passed
zeroshade added a commit to zeroshade/iceberg-go that referenced this pull request Oct 27, 2026
apache#2324's two notes landed separated by blank lines, splitting the list.
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