Skip to content

Commit 1639e49

Browse files
committed
Adress review issues
1 parent 467f469 commit 1639e49

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ constexpr const char * TABLE_LOCATION_FIELD = "location";
7070
constexpr const char * SNAPSHOTS_FIELD = "snapshots";
7171
constexpr const char * LAST_UPDATED_MS_FIELD = "last-updated-ms";
7272

73+
namespace
74+
{
7375

7476
std::pair<Int32, Poco::JSON::Object::Ptr>
7577
parseTableSchemaFromManifestFile(const AvroForIcebergDeserializer & deserializer, const String & manifest_file_name)
@@ -102,6 +104,23 @@ std::string normalizeUuid(const std::string & uuid)
102104
return result;
103105
}
104106

107+
Poco::JSON::Object::Ptr
108+
readJSON(const String & metadata_file_path, ObjectStoragePtr object_storage, const ContextPtr & local_context, LoggerPtr log)
109+
{
110+
ObjectInfo object_info(metadata_file_path);
111+
auto buf = StorageObjectStorageSource::createReadBuffer(object_info, object_storage, local_context, log);
112+
113+
String json_str;
114+
readJSONObjectPossiblyInvalid(json_str, *buf);
115+
116+
Poco::JSON::Parser parser; /// For some reason base/base/JSON.h can not parse this json file
117+
Poco::Dynamic::Var json = parser.parse(json_str);
118+
return json.extract<Poco::JSON::Object::Ptr>();
119+
}
120+
121+
122+
}
123+
105124

106125
IcebergMetadata::IcebergMetadata(
107126
ObjectStoragePtr object_storage_,
@@ -272,20 +291,6 @@ struct ShortMetadataFileInfo
272291
String path;
273292
};
274293

275-
static Poco::JSON::Object::Ptr
276-
readJSON(const String & metadata_file_path, ObjectStoragePtr object_storage, const ContextPtr & local_context, LoggerPtr log)
277-
{
278-
ObjectInfo object_info(metadata_file_path);
279-
auto buf = StorageObjectStorageSource::createReadBuffer(object_info, object_storage, local_context, log);
280-
281-
String json_str;
282-
readJSONObjectPossiblyInvalid(json_str, *buf);
283-
284-
Poco::JSON::Parser parser; /// For some reason base/base/JSON.h can not parse this json file
285-
Poco::Dynamic::Var json = parser.parse(json_str);
286-
return json.extract<Poco::JSON::Object::Ptr>();
287-
}
288-
289294

290295
/**
291296
* Each version of table metadata is stored in a `metadata` directory and
@@ -297,10 +302,13 @@ static std::pair<Int32, String> getLatestMetadataFileAndVersion(
297302
const ObjectStoragePtr & object_storage,
298303
const StorageObjectStorage::Configuration & configuration,
299304
const ContextPtr & local_context,
300-
const std::optional<String> & table_uuid,
301-
MostRecentMetadataFileSelectionWay selection_way)
305+
const std::optional<String> & table_uuid)
302306
{
303307
auto log = getLogger("IcebergMetadataFileResolver");
308+
MostRecentMetadataFileSelectionWay selection_way
309+
= configuration.getSettingsRef()[StorageObjectStorageSetting::iceberg_recent_metadata_file_by_last_updated_ms_field].value
310+
? MostRecentMetadataFileSelectionWay::BY_LAST_UPDATED_MS_FIELD
311+
: MostRecentMetadataFileSelectionWay::BY_METADATA_FILE_VERSION;
304312
bool need_all_metadata_files_parsing
305313
= (selection_way == MostRecentMetadataFileSelectionWay::BY_LAST_UPDATED_MS_FIELD) || table_uuid.has_value();
306314
const auto metadata_files = listFiles(*object_storage, configuration, "metadata", ".metadata.json");
@@ -322,12 +330,6 @@ static std::pair<Int32, String> getLatestMetadataFileAndVersion(
322330
if (metadata_file_object->has("table-uuid"))
323331
{
324332
auto current_table_uuid = metadata_file_object->getValue<String>("table-uuid");
325-
LOG_DEBUG(
326-
&Poco::Logger::get("IcebergMetadataFileResolver"),
327-
"Table UUID is specified {}, current metadata file path is {}, current table UUID is {}",
328-
table_uuid.value(),
329-
metadata_file_path,
330-
current_table_uuid);
331333
if (normalizeUuid(table_uuid.value()) == normalizeUuid(current_table_uuid))
332334
{
333335
metadata_files_with_versions.emplace_back(
@@ -381,10 +383,6 @@ static std::pair<Int32, String> getLatestOrExplicitMetadataFileAndVersion(
381383
const ContextPtr & local_context,
382384
Poco::Logger * log)
383385
{
384-
MostRecentMetadataFileSelectionWay selection_way
385-
= configuration.getSettingsRef()[StorageObjectStorageSetting::iceberg_recent_metadata_file_by_last_updated_ms_field].value
386-
? MostRecentMetadataFileSelectionWay::BY_LAST_UPDATED_MS_FIELD
387-
: MostRecentMetadataFileSelectionWay::BY_METADATA_FILE_VERSION;
388386
if (configuration.getSettingsRef()[StorageObjectStorageSetting::iceberg_metadata_file_path].changed)
389387
{
390388
auto explicit_metadata_path = configuration.getSettingsRef()[StorageObjectStorageSetting::iceberg_metadata_file_path].value;
@@ -397,20 +395,15 @@ static std::pair<Int32, String> getLatestOrExplicitMetadataFileAndVersion(
397395
else if (configuration.getSettingsRef()[StorageObjectStorageSetting::iceberg_metadata_table_uuid].changed)
398396
{
399397
std::optional<String> table_uuid = configuration.getSettingsRef()[StorageObjectStorageSetting::iceberg_metadata_table_uuid].value;
400-
return getLatestMetadataFileAndVersion(object_storage, configuration, local_context, table_uuid, selection_way);
398+
return getLatestMetadataFileAndVersion(object_storage, configuration, local_context, table_uuid);
401399
}
402400
else
403401
{
404-
return getLatestMetadataFileAndVersion(object_storage, configuration, local_context, std::nullopt, selection_way);
402+
return getLatestMetadataFileAndVersion(object_storage, configuration, local_context, std::nullopt);
405403
}
406404
}
407405

408406

409-
Poco::JSON::Object::Ptr IcebergMetadata::readJSON(const String & metadata_file_path, const ContextPtr & local_context) const
410-
{
411-
return ::DB::readJSON(metadata_file_path, object_storage, local_context, log);
412-
}
413-
414407
bool IcebergMetadata::update(const ContextPtr & local_context)
415408
{
416409
auto configuration_ptr = configuration.lock();
@@ -420,7 +413,7 @@ bool IcebergMetadata::update(const ContextPtr & local_context)
420413

421414
last_metadata_version = metadata_version;
422415

423-
last_metadata_object = readJSON(metadata_file_path, local_context);
416+
last_metadata_object = readJSON(metadata_file_path, object_storage, local_context, log);
424417

425418
chassert(format_version == last_metadata_object->getValue<int>(FORMAT_VERSION_FIELD));
426419

src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ class IcebergMetadata : public IDataLakeMetadata, private WithContext
138138

139139
std::optional<String> getRelevantManifestList(const Poco::JSON::Object::Ptr & metadata);
140140

141-
Poco::JSON::Object::Ptr readJSON(const String & metadata_file_path, const ContextPtr & local_context) const;
142-
143141
Strings getDataFilesImpl(const ActionsDAG * filter_dag) const;
144142

145143
Iceberg::ManifestFilePtr tryGetManifestFile(const String & filename) const;

0 commit comments

Comments
 (0)