This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 76c653b8a refactor(table): drop pterm from library path (#2061)
76c653b8a is described below
commit 76c653b8ad08d9adb517f8b45b07e42bdcf29d60
Author: Andrei Tserakhau <[email protected]>
AuthorDate: Sun Sep 27 12:08:24 2026 +0200
refactor(table): drop pterm from library path (#2061)
Render schema mismatch output with `text/tabwriter` instead of `pterm`.
This removes `pterm`/`atomicgo.dev/keyboard` from `table` and
`catalog/rest` imports and fixes js/wasm builds.
Output stays equivalent, but is returned only in the error with no stdout
side effect.
`pterm` remains used by the CLI.
---
table/arrow_utils.go | 26 +++++++++++++++++---------
table/table_test.go | 14 +++++---------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/table/arrow_utils.go b/table/arrow_utils.go
index a6e1c1e29..c974b8d69 100644
--- a/table/arrow_utils.go
+++ b/table/arrow_utils.go
@@ -29,6 +29,7 @@ import (
"slices"
"strconv"
"strings"
+ "text/tabwriter"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
@@ -46,7 +47,6 @@ import (
tblutils "github.com/apache/iceberg-go/table/internal"
"github.com/geoarrow/geoarrow-go"
"github.com/google/uuid"
- "github.com/pterm/pterm"
"golang.org/x/sync/errgroup"
)
@@ -1507,13 +1507,13 @@ func arrowSchemaEqual(left, right *arrow.Schema) bool {
type schemaCompatVisitor struct {
provided *iceberg.Schema
- errorData pterm.TableData
+ errorData [][]string
}
func checkSchemaCompat(requested, provided *iceberg.Schema) error {
sc := &schemaCompatVisitor{
provided: provided,
- errorData: pterm.TableData{{"", "Table Field", "Requested
Field"}},
+ errorData: [][]string{{"", "Table Field", "Requested Field"}},
}
_, compat := iceberg.PreOrderVisit(requested, sc)
@@ -1615,12 +1615,20 @@ func (sc *schemaCompatVisitor) isFieldCompat(lhs
iceberg.NestedField) bool {
func (sc *schemaCompatVisitor) Schema(s *iceberg.Schema, v func() bool) bool {
if !v() {
- pterm.DisableColor()
- tbl :=
pterm.DefaultTable.WithHasHeader(true).WithData(sc.errorData)
- tbl.Render()
- txt, _ := tbl.Srender()
- pterm.EnableColor()
- panic("mismatch in fields:\n" + txt)
+ // Render the collected mismatch rows into the error message
with the
+ // stdlib tabwriter. Unlike the former pterm renderer this
writes only to
+ // the returned error and has no stdout side effect. tabwriter
measures
+ // column width by rune count, so the leading status column
(✅/❌) may be
+ // off by one display cell in terminals that render those
double-width;
+ // the reported content is unaffected.
+ var buf strings.Builder
+ w := tabwriter.NewWriter(&buf, 0, 0, 2, ' ', 0)
+ for _, row := range sc.errorData {
+ fmt.Fprintln(w, strings.Join(row, "\t"))
+ }
+ _ = w.Flush()
+
+ panic("mismatch in fields:\n" + buf.String())
}
return true
diff --git a/table/table_test.go b/table/table_test.go
index 0d1877827..7033e5bdd 100644
--- a/table/table_test.go
+++ b/table/table_test.go
@@ -51,7 +51,6 @@ import (
"github.com/apache/iceberg-go/table"
"github.com/google/uuid"
"github.com/klauspost/compress/zstd"
- "github.com/pterm/pterm"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@@ -735,18 +734,15 @@ func (t *TableWritingTestSuite)
TestAddFilesFailsSchemaMismatch() {
files := []string{filePath}
- pterm.DisableOutput() // disable error to console
- defer pterm.EnableOutput()
-
tx := tbl.NewTransaction()
err = tx.AddFiles(t.ctx, files, nil, false)
t.Error(err)
t.EqualError(err, `error encountered during file conversion: invalid
schema: mismatch in fields:
- | Table Field | Requested Field
-✅ | 1: foo: optional boolean | 1: foo: optional boolean
-✅ | 2: bar: optional string | 2: bar: optional string
-❌ | 3: baz: optional int | 3: baz: optional string
-✅ | 4: qux: optional date | 4: qux: optional date
+ Table Field Requested Field
+✅ 1: foo: optional boolean 1: foo: optional boolean
+✅ 2: bar: optional string 2: bar: optional string
+❌ 3: baz: optional int 3: baz: optional string
+✅ 4: qux: optional date 4: qux: optional date
`)
}