hendoxc opened a new issue, #434:
URL: https://github.com/apache/iceberg-go/issues/434
### Apache Iceberg version
main (development)
### Please describe the bug 🐞
Hey there, amazing project. I have been playing around with writes,
specifically writing to a table, and reading use Trino + rest.
```go
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cat, err := loadCatalog(ctx)
if err != nil {
log.Fatalf("failed to load catalog: %v", err)
}
err = createNamespace(ctx, cat)
if err != nil {
log.Fatalf("failed to create namespace: %v", err)
}
schema, err := loadSchema(ctx)
if err != nil {
log.Fatalf("failed to load schema: %v", err)
}
tbl, err := loadTable(ctx, cat, schema)
if err != nil {
log.Fatalf("failed to load table: %v", err)
}
arrowSchema, err := table.SchemaToArrowSchema(schema, nil, true, false)
mem := memory.DefaultAllocator
recordBuilder := array.NewRecordBuilder(mem, arrowSchema)
defer recordBuilder.Release()
fmt.Println("Building records...")
recordBuilder.Field(0).(*array.StringBuilder).AppendValues([]string{"id1",
"id2", "id3"}, nil)
recordBuilder.Field(1).(*array.Int32Builder).AppendValues([]int32{44,
13412, 87}, nil)
recordBuilder.Field(2).(*array.BooleanBuilder).AppendValues([]bool{true, false,
true}, nil)
newRecord := recordBuilder.NewRecord()
defer newRecord.Release()
arrTable := array.NewTableFromRecords(arrowSchema,
[]arrow.Record{newRecord})
defer arrTable.Release()
fmt.Println("Appending records to the table...")
tx := tbl.NewTransaction()
err = tx.AppendTable(ctx, arrTable, 3, nil)
if err != nil {
log.Fatalf("failed to append records: %v", err)
}
fmt.Println("Records appended to transaction.")
tbl, err = tx.Commit(ctx)
if err != nil {
log.Fatalf("failed to commit transaction: %v", err)
}
fmt.Println("Records appended successfully.")
scan, err := tx.Scan()
if err != nil {
log.Fatalf("failed to scan table: %v", err)
}
contents, err := scan.ToArrowTable(context.Background())
if err != nil {
log.Fatalf("failed to scan table: %v", err)
}
defer contents.Release()
fmt.Printf("Number of records in the table: %d\n", contents.NumRows())
}
```
My logs show
```
Table created at: s3://demo-iceberg/cre/event
Building records...
Appending records to the table...
Records appended to transaction.
Records appended successfully.
Number of records in the table: 3
```
I check the minio bucket, and things look normal
<img width="2089" alt="Image"
src="https://github.com/user-attachments/assets/cdd5a157-9252-4e4b-80c8-101c06bbe5a1"
/>
<img width="2099" alt="Image"
src="https://github.com/user-attachments/assets/63364736-bea1-4e85-897e-4c440d6945f3"
/>
But when I try to query the table using Trino + rest catalog
```
[65536] Query failed (#20250519_231332_00025_ba2ug):
io.trino.spi.TrinoException: Error processing metadata for table cre.event
org.apache.avro.InvalidAvroMagicException: Not an Avro data file
```
using `apache/iceberg-rest-fixture` gives maybe unrelated errors?
```
[qtp904058452-22] ERROR org.apache.iceberg.rest.RESTCatalogServlet - Error
processing REST request
org.apache.iceberg.exceptions.RESTException: Unhandled error:
ErrorResponse(code=404, type=NoSuchViewException, message=View does not exist:
cre.event)
org.apache.iceberg.exceptions.NoSuchViewException: View does not exist:
cre.event
```
I was wondering if how I'm writing to the table is correct or I've
misconfigured something?
## notes
How Im creating tables and namespaces
```go
func loadTable(ctx context.Context, cat catalog.Catalog, schema
*iceberg.Schema) (*table.Table, error) {
var tbl *table.Table
ok, err := cat.CheckTableExists(ctx, catalog.ToIdentifier("cre",
"event"))
if err != nil {
return nil, fmt.Errorf("failed to check table: %w", err)
}
if ok {
tbl, err = cat.LoadTable(ctx, catalog.ToIdentifier("cre",
"event"), iceberg.Properties{
"format-version": "2",
})
if err != nil {
return nil, fmt.Errorf("failed to load table: %w", err)
}
fmt.Printf("Table loaded at: %s\n", tbl.Location())
return tbl, nil
}
tbl, err = cat.CreateTable(ctx, catalog.ToIdentifier("cre", "event"),
schema)
if err != nil {
return nil, fmt.Errorf("failed to create table: %w", err)
}
fmt.Printf("Table created at: %s\n", tbl.Location())
return tbl, nil
}
func createNamespace(ctx context.Context, cat catalog.Catalog) error {
ok, err := cat.CheckNamespaceExists(ctx, catalog.ToIdentifier("cre"))
if err != nil {
return err
}
if !ok {
err = cat.CreateNamespace(ctx, catalog.ToIdentifier("cre"),
iceberg.Properties{})
if err != nil {
return err
}
}
return nil
}
func loadCatalog(ctx context.Context) (catalog.Catalog, error) {
cat, err := catalog.Load(ctx, "local", iceberg.Properties{
"type": "rest",
"uri": "http://localhost:8181",
io.S3Region: "us-west-2",
io.S3AccessKeyID: "admin",
io.S3SecretAccessKey: "password",
io.S3EndpointURL: "http://localhost:9000",
})
if err != nil {
return nil, fmt.Errorf("failed to create catalog: %w", err)
}
restCat, ok := cat.(*rest.Catalog)
if !ok {
return nil, fmt.Errorf("failed to cast catalog to rest.Catalog")
}
return restCat, nil
}
``
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]