iceberg: route unprefixed requests to the first table bucket (#10675)

This commit is contained in:
Chris Lu
2026-08-09 22:20:13 -07:00
committed by GitHub
parent a2ff9cca27
commit c8cc56be91
3 changed files with 34 additions and 0 deletions
+4
View File
@@ -1344,6 +1344,10 @@ func runMini(cmd *Command, args []string) bool {
tableBucketSpec := *miniTableBucket
if tableBucketSpec == "" {
tableBucketSpec = os.Getenv("S3_TABLE_BUCKET")
} else if os.Getenv("S3_TABLE_BUCKET") == "" {
// The catalog routes unprefixed requests to the first S3_TABLE_BUCKET
// entry; let the -tableBucket flag mean the same thing.
os.Setenv("S3_TABLE_BUCKET", tableBucketSpec)
}
if err := ensureMiniTableBuckets(tableBucketSpec); err != nil {
glog.Warningf("failed to ensure table buckets %q: %v", tableBucketSpec, err)
@@ -81,3 +81,25 @@ func TestBuildFileIOConfig(t *testing.T) {
}
})
}
func TestGetBucketFromPrefix_TableBucketEnvFallback(t *testing.T) {
r := httptest.NewRequest("GET", "/v1/namespaces", nil)
t.Setenv("S3_TABLE_BUCKET", " ,analytics, other")
if got := getBucketFromPrefix(r); got != "analytics" {
t.Fatalf("first S3_TABLE_BUCKET entry: got %q, want analytics", got)
}
// The explicit default still wins over the table bucket list.
t.Setenv("S3TABLES_DEFAULT_BUCKET", "explicit")
if got := getBucketFromPrefix(r); got != "explicit" {
t.Fatalf("S3TABLES_DEFAULT_BUCKET override: got %q, want explicit", got)
}
// A prefixless value with neither env set falls through to the default.
t.Setenv("S3TABLES_DEFAULT_BUCKET", "")
t.Setenv("S3_TABLE_BUCKET", " , ")
if got := getBucketFromPrefix(r); got != "warehouse" {
t.Fatalf("empty specs: got %q, want warehouse", got)
}
}
+8
View File
@@ -236,6 +236,14 @@ func getBucketFromPrefix(r *http.Request) string {
if bucket := os.Getenv("S3TABLES_DEFAULT_BUCKET"); bucket != "" {
return bucket
}
// Some writers commit to the unprefixed path even though their reads
// honor the /v1/config prefix; the deployment's first table bucket is
// where those commits belong.
for _, name := range strings.Split(os.Getenv("S3_TABLE_BUCKET"), ",") {
if name = strings.TrimSpace(name); name != "" {
return name
}
}
// Default bucket if no prefix - use "warehouse" for Iceberg
return "warehouse"
}