aslatter commented on issue #547:
URL: https://github.com/apache/iceberg-go/issues/547#issuecomment-3218349772
My original program for working with s3-metadata which ran into this is the
following:
<details>
<summary>Click to expand</summary>
```go
package main
import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"os"
"strings"
"github.com/apache/iceberg-go"
"github.com/apache/iceberg-go/catalog/rest"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/aws/aws-sdk-go-v2/config"
)
func main() {
if err := mainErr(); err != nil {
fmt.Fprintln(os.Stdout, "error:", err)
os.Exit(1)
}
}
func mainErr() error {
var tableBucketARNString string
var tableString string
flag.StringVar(&tableBucketARNString, "table-bucket", "", "s3
table-bucket")
flag.StringVar(&tableString, "table", "", "table within s3
table-bucket, in the form namespace.table_name")
flag.Parse()
if tableBucketARNString == "" {
return errors.New("flag -table-bucket is required")
}
if tableString == "" {
return errors.New("flag -table is required")
}
bucketARN, err := arn.Parse(tableBucketARNString)
if err != nil {
return fmt.Errorf("parsing bucket arn: %s", err)
}
tableIdent := strings.Split(tableString, ".")
ctx := context.Background()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return fmt.Errorf("loading AWS config: %s", err)
}
awsRegion := cfg.Region
if awsRegion == "" {
return errors.New("missing AWS region")
}
cat, err := rest.NewCatalog(ctx, "unknown",
fmt.Sprintf("https://s3tables.%s.amazonaws.com/iceberg", awsRegion),
rest.WithAwsConfig(cfg),
rest.WithWarehouseLocation(tableBucketARNString),
rest.WithSigV4(),
rest.WithSigV4RegionSvc(awsRegion, bucketARN.Service),
)
if err != nil {
return fmt.Errorf("opening iceberg catalog: %s", err)
}
inventory, err := cat.LoadTable(ctx, tableIdent, iceberg.Properties{})
_, riter, err := inventory.Scan().ToArrowRecords(ctx)
if err != nil {
return fmt.Errorf("scanning inventory table: %s", err)
}
for rec, err := range riter {
if err != nil {
return fmt.Errorf("iterating over scanned records: %s",
err)
}
err = json.NewEncoder(os.Stdout).Encode(rec)
if err != nil {
return fmt.Errorf("encoding json for record: %s", err)
}
}
return nil
}
```
</details>
Example:
```
export AWS_REGION=<aws region>
AWS_ACCOUNT_ID=12345678
S3_BUCKET_NAME="your-bucket-with-metadata-enabled"
go run ./ -table-bucket
arn:aws:s3tables:$AWS_REGION:$AWS_ACCOUNT_ID:bucket/aws-s3 -table
b_${S3_BUCKET_NAME}.inventory
```
(I had inventory enabled - if you only have "journal" enabled you'd use that
instead of "inventory")
--
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]