You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "dttung2905 (via GitHub)" <gi...@apache.org> on 2025/04/03 22:36:48 UTC
[PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
dttung2905 opened a new pull request, #376:
URL: https://github.com/apache/iceberg-go/pull/376
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
Posted by "dttung2905 (via GitHub)" <gi...@apache.org>.
dttung2905 commented on PR #376:
URL: https://github.com/apache/iceberg-go/pull/376#issuecomment-2784047531
> This looks good. As a separate PR can we look into adding a test to the rest_integration_test.go file to ensure we have integration tests with the rest catalog?
That makes total sense as well
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
Posted by "dttung2905 (via GitHub)" <gi...@apache.org>.
dttung2905 commented on PR #376:
URL: https://github.com/apache/iceberg-go/pull/376#issuecomment-2783937743
> I'd love it if you pursued implementing the View objects. Please create `view` as a separate package from table though.
Sure. I will try to find some time this week to implement it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on PR #376:
URL: https://github.com/apache/iceberg-go/pull/376#issuecomment-2783647259
I'd love it if you pursued implementing the View objects. Please create `view` as a separate package from table though.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #376:
URL: https://github.com/apache/iceberg-go/pull/376#discussion_r2031448057
##########
catalog/rest/rest.go:
##########
@@ -1156,3 +1156,80 @@ func (r *Catalog) CheckViewExists(ctx context.Context, identifier table.Identifi
return true, nil
}
+
+type viewVersion struct {
+ VersionID int64 `json:"version-id"`
+ TimestampMs int64 `json:"timestamp-ms"`
+ SchemaID int `json:"schema-id"`
+ Summary map[string]string `json:"summary"`
+ Representations []struct {
+ Type string `json:"type"`
+ SQL string `json:"sql"`
+ Dialect string `json:"dialect"`
+ } `json:"representations"`
+ DefaultCatalog string `json:"default-catalog"`
+ DefaultNamespace []string `json:"default-namespace"`
+}
+
+type createViewRequest struct {
+ Name string `json:"name"`
+ Schema *iceberg.Schema `json:"schema"`
+ Location string `json:"location,omitempty"`
+ Props iceberg.Properties `json:"properties,omitempty"`
+ SQL string `json:"sql"`
+ ViewVersion viewVersion `json:"view-version"`
+}
+
+type viewResponse struct {
+ MetadataLoc string `json:"metadata-location"`
+ RawMetadata json.RawMessage `json:"metadata"`
+ Config iceberg.Properties `json:"config"`
+ Metadata table.Metadata `json:"-"`
+}
+
+// CreateView creates a new view in the catalog.
+func (r *Catalog) CreateView(ctx context.Context, identifier table.Identifier, schema *iceberg.Schema, sql string, props iceberg.Properties) error {
+ ns, view, err := splitIdentForPath(identifier)
+ if err != nil {
+ return err
+ }
+
+ freshSchema, err := iceberg.AssignFreshSchemaIDs(schema, nil)
+ if err != nil {
+ return err
+ }
+
+ payload := createViewRequest{
+ Name: view,
+ Schema: freshSchema,
+ SQL: sql,
+ Props: props,
+ ViewVersion: viewVersion{
+ VersionID: 1,
+ TimestampMs: time.Now().UnixMilli(),
+ SchemaID: freshSchema.ID,
+ Summary: map[string]string{"sql": sql},
+ Representations: []struct {
+ Type string `json:"type"`
+ SQL string `json:"sql"`
+ Dialect string `json:"dialect"`
+ }{
+ {Type: "sql", SQL: sql, Dialect: "default"},
+ },
+ DefaultCatalog: r.name,
+ DefaultNamespace: strings.Split(ns, namespaceSeparator),
+ },
+ }
+
+ _, err = doPost[createViewRequest, viewResponse](ctx, r.baseURI, []string{"namespaces", ns, "views"}, payload,
+ r.cl, map[int]error{
+ http.StatusNotFound: catalog.ErrNoSuchNamespace,
+ http.StatusConflict: catalog.ErrViewAlreadyExists,
+ })
+ if err != nil {
+ return err
+ }
+ fmt.Println("created view", identifier)
Review Comment:
extraneous print
##########
catalog/rest/rest.go:
##########
@@ -1156,3 +1156,80 @@ func (r *Catalog) CheckViewExists(ctx context.Context, identifier table.Identifi
return true, nil
}
+
+type viewVersion struct {
+ VersionID int64 `json:"version-id"`
+ TimestampMs int64 `json:"timestamp-ms"`
+ SchemaID int `json:"schema-id"`
+ Summary map[string]string `json:"summary"`
+ Representations []struct {
+ Type string `json:"type"`
+ SQL string `json:"sql"`
+ Dialect string `json:"dialect"`
+ } `json:"representations"`
+ DefaultCatalog string `json:"default-catalog"`
+ DefaultNamespace []string `json:"default-namespace"`
+}
+
+type createViewRequest struct {
+ Name string `json:"name"`
+ Schema *iceberg.Schema `json:"schema"`
+ Location string `json:"location,omitempty"`
+ Props iceberg.Properties `json:"properties,omitempty"`
+ SQL string `json:"sql"`
+ ViewVersion viewVersion `json:"view-version"`
+}
+
+type viewResponse struct {
+ MetadataLoc string `json:"metadata-location"`
+ RawMetadata json.RawMessage `json:"metadata"`
+ Config iceberg.Properties `json:"config"`
+ Metadata table.Metadata `json:"-"`
+}
+
+// CreateView creates a new view in the catalog.
+func (r *Catalog) CreateView(ctx context.Context, identifier table.Identifier, schema *iceberg.Schema, sql string, props iceberg.Properties) error {
+ ns, view, err := splitIdentForPath(identifier)
+ if err != nil {
+ return err
+ }
+
+ freshSchema, err := iceberg.AssignFreshSchemaIDs(schema, nil)
+ if err != nil {
+ return err
+ }
+
+ payload := createViewRequest{
+ Name: view,
+ Schema: freshSchema,
+ SQL: sql,
+ Props: props,
+ ViewVersion: viewVersion{
+ VersionID: 1,
+ TimestampMs: time.Now().UnixMilli(),
+ SchemaID: freshSchema.ID,
+ Summary: map[string]string{"sql": sql},
+ Representations: []struct {
+ Type string `json:"type"`
+ SQL string `json:"sql"`
+ Dialect string `json:"dialect"`
+ }{
+ {Type: "sql", SQL: sql, Dialect: "default"},
+ },
+ DefaultCatalog: r.name,
+ DefaultNamespace: strings.Split(ns, namespaceSeparator),
+ },
+ }
+
+ _, err = doPost[createViewRequest, viewResponse](ctx, r.baseURI, []string{"namespaces", ns, "views"}, payload,
+ r.cl, map[int]error{
+ http.StatusNotFound: catalog.ErrNoSuchNamespace,
+ http.StatusConflict: catalog.ErrViewAlreadyExists,
+ })
+ if err != nil {
Review Comment:
just `return err` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade merged PR #376:
URL: https://github.com/apache/iceberg-go/pull/376
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat (catalog/rest): Add create view for rest catalog [iceberg-go]
Posted by "dttung2905 (via GitHub)" <gi...@apache.org>.
dttung2905 commented on code in PR #376:
URL: https://github.com/apache/iceberg-go/pull/376#discussion_r2031604779
##########
catalog/rest/rest.go:
##########
@@ -1156,3 +1156,80 @@ func (r *Catalog) CheckViewExists(ctx context.Context, identifier table.Identifi
return true, nil
}
+
+type viewVersion struct {
+ VersionID int64 `json:"version-id"`
+ TimestampMs int64 `json:"timestamp-ms"`
+ SchemaID int `json:"schema-id"`
+ Summary map[string]string `json:"summary"`
+ Representations []struct {
+ Type string `json:"type"`
+ SQL string `json:"sql"`
+ Dialect string `json:"dialect"`
+ } `json:"representations"`
+ DefaultCatalog string `json:"default-catalog"`
+ DefaultNamespace []string `json:"default-namespace"`
+}
+
+type createViewRequest struct {
+ Name string `json:"name"`
+ Schema *iceberg.Schema `json:"schema"`
+ Location string `json:"location,omitempty"`
+ Props iceberg.Properties `json:"properties,omitempty"`
+ SQL string `json:"sql"`
+ ViewVersion viewVersion `json:"view-version"`
+}
+
+type viewResponse struct {
+ MetadataLoc string `json:"metadata-location"`
+ RawMetadata json.RawMessage `json:"metadata"`
+ Config iceberg.Properties `json:"config"`
+ Metadata table.Metadata `json:"-"`
+}
+
+// CreateView creates a new view in the catalog.
+func (r *Catalog) CreateView(ctx context.Context, identifier table.Identifier, schema *iceberg.Schema, sql string, props iceberg.Properties) error {
+ ns, view, err := splitIdentForPath(identifier)
+ if err != nil {
+ return err
+ }
+
+ freshSchema, err := iceberg.AssignFreshSchemaIDs(schema, nil)
+ if err != nil {
+ return err
+ }
+
+ payload := createViewRequest{
+ Name: view,
+ Schema: freshSchema,
+ SQL: sql,
+ Props: props,
+ ViewVersion: viewVersion{
+ VersionID: 1,
+ TimestampMs: time.Now().UnixMilli(),
+ SchemaID: freshSchema.ID,
+ Summary: map[string]string{"sql": sql},
+ Representations: []struct {
+ Type string `json:"type"`
+ SQL string `json:"sql"`
+ Dialect string `json:"dialect"`
+ }{
+ {Type: "sql", SQL: sql, Dialect: "default"},
+ },
+ DefaultCatalog: r.name,
+ DefaultNamespace: strings.Split(ns, namespaceSeparator),
+ },
+ }
+
+ _, err = doPost[createViewRequest, viewResponse](ctx, r.baseURI, []string{"namespaces", ns, "views"}, payload,
+ r.cl, map[int]error{
+ http.StatusNotFound: catalog.ErrNoSuchNamespace,
+ http.StatusConflict: catalog.ErrViewAlreadyExists,
+ })
+ if err != nil {
+ return err
+ }
+ fmt.Println("created view", identifier)
Review Comment:
Fixed. Thank you for the quick review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org