zeroshade commented on code in PR #413: URL: https://github.com/apache/iceberg-go/pull/413#discussion_r2071739490
########## cmd/iceberg/output.go: ########## @@ -203,18 +204,153 @@ func (text) Schema(schema *iceberg.Schema) { pterm.DefaultTree.WithRoot(schemaTreeNode).Render() } -func (text) Spec(spec iceberg.PartitionSpec) { +func (textOutput) Spec(spec iceberg.PartitionSpec) { fmt.Println(spec) } -func (text) Uuid(u uuid.UUID) { +func (textOutput) Uuid(u uuid.UUID) { if u.String() != "" { fmt.Println(u.String()) } else { fmt.Println("missing") } } -func (text) Error(err error) { +func (textOutput) Error(err error) { + log.Fatal(err) +} + +type jsonOutput struct{} + +func (j jsonOutput) Identifiers(idList []table.Identifier) { + type dataType struct { + Identifiers []table.Identifier `json:"identifiers"` + } + + var data dataType + data.Identifiers = idList + + encodedData, err := json.Marshal(data) + if err != nil { + j.Error(err) + } + + fmt.Println(string(encodedData)) +} + +func (j jsonOutput) DescribeTable(tbl *table.Table) { + type dataType struct { + Metadata table.Metadata `json:"metadata,omitempty"` + MetadataLocation string `json:"metadata-location,omitempty"` + SortOrder table.SortOrder `json:"sort-order,omitempty"` + CurrentSnapshot *table.Snapshot `json:"current-snapshot,omitempty"` + Spec iceberg.PartitionSpec `json:"spec,omitempty"` + Schema *iceberg.Schema `json:"schema"` + } + + var data dataType + data.Metadata = tbl.Metadata() + data.MetadataLocation = tbl.MetadataLocation() + data.SortOrder = tbl.SortOrder() + data.CurrentSnapshot = tbl.CurrentSnapshot() + data.Spec = tbl.Spec() + data.Schema = tbl.Schema() + + encodedData, _ := json.Marshal(data) + fmt.Println(string(encodedData)) +} + +func (j jsonOutput) Files(tbl *table.Table, history bool) { + if history { + type dataType struct { + Snapshots []table.Snapshot `json:"snapshots"` + } + + var data dataType + data.Snapshots = tbl.Metadata().Snapshots() + + encodedData, err := json.Marshal(data) + if err != nil { + j.Error(err) + } + + fmt.Println(string(encodedData)) Review Comment: same comment as above -- 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org