@@ -167,30 +167,51 @@ IcebergSnapshot IcebergSnapshot::GetSnapshotByTimestamp(const string &path, File
167
167
return ParseSnapShot (snapshot, info->iceberg_version , info->schema_id , info->schemas , metadata_compression_codec, skip_schema_inference);
168
168
}
169
169
170
- // Function to generate a metadata file url
171
- string GenerateMetaDataUrl (FileSystem &fs, const string &meta_path, const string &table_version, const string &metadata_compression_codec) {
172
- if (metadata_compression_codec != " gzip" ) {
173
- return fs.JoinPath (meta_path, " v" + table_version + " .metadata.json" );
170
+ // Function to generate a metadata file url from version and format string
171
+ // default format is "v%s%s.metadata.json" -> v00###-xxxxxxxxx-.gz.metadata.json"
172
+ string GenerateMetaDataUrl (FileSystem &fs, const string &meta_path, string &table_version, string &metadata_compression_codec, string &version_format = DEFAULT_TABLE_VERSION_FORMAT) {
173
+ // TODO: Need to URL Encode table_version
174
+ string compression_suffix = " " ;
175
+ string url;
176
+ if (metadata_compression_codec == " gzip" ) {
177
+ compression_suffix = " .gz" ;
178
+ }
179
+ for (auto try_format : StringUtil::Split (version_format, ' ,' )) {
180
+ url = fs.JoinPath (meta_path, StringUtil::Format (try_format, table_version, compression_suffix));
181
+ if (fs.FileExists (url)) {
182
+ return url;
183
+ }
174
184
}
175
- return fs.JoinPath (meta_path, " v" + table_version + " .gz.metadata.json" );
185
+
186
+ throw IOException (
187
+ " Iceberg metadata file not found for table version '%s' using '%s' compression and format(s): '%s'" , table_version, metadata_compression_codec, version_format);
176
188
}
177
189
178
- string IcebergSnapshot::ReadMetaData ( const string &path, FileSystem &fs, string metadata_compression_codec) {
179
- string metadata_file_path;
190
+
191
+ string IcebergSnapshot::GetMetaDataPath ( const string &path, FileSystem &fs, string metadata_compression_codec, string table_version = DEFAULT_VERSION_HINT_FILE, string version_format = DEFAULT_TABLE_VERSION_FORMAT) {
180
192
if (StringUtil::EndsWith (path, " .json" )) {
181
- metadata_file_path = path;
193
+ return path;
194
+ }
195
+
196
+ auto meta_path = fs.JoinPath (path, " metadata" );
197
+ string version_hint;
198
+ if (StringUtil::EndsWith (table_version, " .text" )||StringUtil::EndsWith (table_version, " .txt" )) {
199
+ version_hint = GetTableVersion (meta_path, fs, table_version);
182
200
} else {
183
- auto table_version = GetTableVersion (path, fs);
184
- auto meta_path = fs.JoinPath (path, " metadata" );
185
- metadata_file_path = GenerateMetaDataUrl (fs, meta_path, table_version, metadata_compression_codec);
201
+ version_hint = table_version;
186
202
}
203
+ return GenerateMetaDataUrl (fs, meta_path, version_hint, metadata_compression_codec, version_format);
204
+ }
205
+
187
206
207
+ string IcebergSnapshot::ReadMetaData (const string &path, FileSystem &fs, string metadata_compression_codec) {
188
208
if (metadata_compression_codec == " gzip" ) {
189
- return IcebergUtils::GzFileToString (metadata_file_path , fs);
209
+ return IcebergUtils::GzFileToString (path , fs);
190
210
}
191
- return IcebergUtils::FileToString (metadata_file_path , fs);
211
+ return IcebergUtils::FileToString (path , fs);
192
212
}
193
213
214
+
194
215
IcebergSnapshot IcebergSnapshot::ParseSnapShot (yyjson_val *snapshot, idx_t iceberg_format_version, idx_t schema_id,
195
216
vector<yyjson_val *> &schemas, string metadata_compression_codec,
196
217
bool skip_schema_inference) {
@@ -217,9 +238,8 @@ IcebergSnapshot IcebergSnapshot::ParseSnapShot(yyjson_val *snapshot, idx_t icebe
217
238
return ret;
218
239
}
219
240
220
- string IcebergSnapshot::GetTableVersion (const string &path, FileSystem &fs) {
221
- auto meta_path = fs.JoinPath (path, " metadata" );
222
- auto version_file_path = fs.JoinPath (meta_path, " version-hint.text" );
241
+ string IcebergSnapshot::GetTableVersion (const string &meta_path, FileSystem &fs, string version_file = DEFAULT_VERSION_HINT_FILE) {
242
+ auto version_file_path = fs.JoinPath (meta_path, version_file);
223
243
auto version_file_content = IcebergUtils::FileToString (version_file_path, fs);
224
244
225
245
try {
@@ -288,4 +308,4 @@ yyjson_val *IcebergSnapshot::IcebergSnapshot::FindSnapshotByIdTimestampInternal(
288
308
return max_snapshot;
289
309
}
290
310
291
- } // namespace duckdb
311
+ } // namespace duckdb
0 commit comments