@@ -151,7 +151,7 @@ namespace Iceberg
151151
152152std::string IcebergSchemaProcessor::default_link{};
153153
154- void IcebergSchemaProcessor::addIcebergTableSchema (Poco::JSON::Object::Ptr schema_ptr)
154+ void IcebergSchemaProcessor::addIcebergTableSchema (Poco::JSON::Object::Ptr schema_ptr, ContextPtr context_ )
155155{
156156 std::lock_guard lock (mutex);
157157
@@ -174,7 +174,7 @@ void IcebergSchemaProcessor::addIcebergTableSchema(Poco::JSON::Object::Ptr schem
174174 auto name = field->getValue <String>(f_name);
175175 bool required = field->getValue <bool >(f_required);
176176 current_full_name = name;
177- auto type = getFieldType (field, f_type, required, current_full_name, true );
177+ auto type = getFieldType (field, f_type, context_, required, current_full_name, true );
178178 clickhouse_schema->push_back (NameAndTypePair{name, type});
179179 clickhouse_types_by_source_ids[{schema_id, field->getValue <Int32>(f_id)}] = NameAndTypePair{current_full_name, type};
180180 clickhouse_ids_by_source_names[{schema_id, current_full_name}] = field->getValue <Int32>(f_id);
@@ -275,21 +275,25 @@ DataTypePtr IcebergSchemaProcessor::getSimpleType(const String & type_name, Cont
275275}
276276
277277DataTypePtr
278- IcebergSchemaProcessor::getComplexTypeFromObject (const Poco::JSON::Object::Ptr & type, String & current_full_name, bool is_subfield_of_root)
278+ IcebergSchemaProcessor::getComplexTypeFromObject (
279+ const Poco::JSON::Object::Ptr & type,
280+ String & current_full_name,
281+ ContextPtr context_,
282+ bool is_subfield_of_root)
279283{
280284 String type_name = type->getValue <String>(f_type);
281285 if (type_name == f_list)
282286 {
283287 bool element_required = type->getValue <bool >(" element-required" );
284- auto element_type = getFieldType (type, f_element, element_required);
288+ auto element_type = getFieldType (type, f_element, context_, element_required);
285289 return std::make_shared<DataTypeArray>(element_type);
286290 }
287291
288292 if (type_name == f_map)
289293 {
290- auto key_type = getFieldType (type, f_key, true );
294+ auto key_type = getFieldType (type, f_key, context_, true );
291295 auto value_required = type->getValue <bool >(" value-required" );
292- auto value_type = getFieldType (type, f_value, value_required);
296+ auto value_type = getFieldType (type, f_value, context_, value_required);
293297 return std::make_shared<DataTypeMap>(key_type, value_type);
294298 }
295299
@@ -313,7 +317,7 @@ IcebergSchemaProcessor::getComplexTypeFromObject(const Poco::JSON::Object::Ptr &
313317
314318 (current_full_name += " ." ).append (element_names.back ());
315319 scope_guard guard ([&] { current_full_name.resize (current_full_name.size () - element_names.back ().size () - 1 ); });
316- element_types.push_back (getFieldType (field, f_type, required, current_full_name, true ));
320+ element_types.push_back (getFieldType (field, f_type, context_, required, current_full_name, true ));
317321 TSA_SUPPRESS_WARNING_FOR_WRITE (clickhouse_types_by_source_ids)
318322 [{schema_id, field->getValue <Int32>(f_id)}] = NameAndTypePair{current_full_name, element_types.back ()};
319323
@@ -322,7 +326,7 @@ IcebergSchemaProcessor::getComplexTypeFromObject(const Poco::JSON::Object::Ptr &
322326 }
323327 else
324328 {
325- element_types.push_back (getFieldType (field, f_type, required));
329+ element_types.push_back (getFieldType (field, f_type, context_, required));
326330 }
327331 }
328332
@@ -335,18 +339,19 @@ IcebergSchemaProcessor::getComplexTypeFromObject(const Poco::JSON::Object::Ptr &
335339DataTypePtr IcebergSchemaProcessor::getFieldType (
336340 const Poco::JSON::Object::Ptr & field,
337341 const String & type_key,
342+ ContextPtr context_,
338343 bool required,
339344 String & current_full_name,
340345 bool is_subfield_of_root)
341346{
342347 if (field->isObject (type_key))
343- return getComplexTypeFromObject (field->getObject (type_key), current_full_name, is_subfield_of_root);
348+ return getComplexTypeFromObject (field->getObject (type_key), current_full_name, context_, is_subfield_of_root);
344349
345350 auto type = field->get (type_key);
346351 if (type.isString ())
347352 {
348353 const String & type_name = type.extract <String>();
349- auto data_type = getSimpleType (type_name, getContext () );
354+ auto data_type = getSimpleType (type_name, context_ );
350355 return required ? data_type : makeNullable (data_type);
351356 }
352357
@@ -376,7 +381,11 @@ bool IcebergSchemaProcessor::allowPrimitiveTypeConversion(const String & old_typ
376381
377382// Ids are passed only for error logging purposes
378383std::shared_ptr<ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDag (
379- const Poco::JSON::Object::Ptr & old_schema, const Poco::JSON::Object::Ptr & new_schema, Int32 old_id, Int32 new_id)
384+ const Poco::JSON::Object::Ptr & old_schema,
385+ const Poco::JSON::Object::Ptr & new_schema,
386+ ContextPtr context_,
387+ Int32 old_id,
388+ Int32 new_id)
380389{
381390 std::unordered_map<size_t , std::pair<Poco::JSON::Object::Ptr, const ActionsDAG::Node *>> old_schema_entries;
382391 auto old_schema_fields = old_schema->get (f_fields).extract <Poco::JSON::Array::Ptr>();
@@ -388,7 +397,7 @@ std::shared_ptr<ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDag(
388397 size_t id = field->getValue <size_t >(f_id);
389398 auto name = field->getValue <String>(f_name);
390399 bool required = field->getValue <bool >(f_required);
391- old_schema_entries[id] = {field, &dag->addInput (name, getFieldType (field, f_type, required))};
400+ old_schema_entries[id] = {field, &dag->addInput (name, getFieldType (field, f_type, context_, required))};
392401 }
393402 auto new_schema_fields = new_schema->get (f_fields).extract <Poco::JSON::Array::Ptr>();
394403 for (size_t i = 0 ; i != new_schema_fields->size (); ++i)
@@ -397,7 +406,7 @@ std::shared_ptr<ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDag(
397406 size_t id = field->getValue <size_t >(f_id);
398407 auto name = field->getValue <String>(f_name);
399408 bool required = field->getValue <bool >(f_required);
400- auto type = getFieldType (field, f_type, required);
409+ auto type = getFieldType (field, f_type, context_, required);
401410 auto old_node_it = old_schema_entries.find (id);
402411 if (old_node_it != old_schema_entries.end ())
403412 {
@@ -407,7 +416,7 @@ std::shared_ptr<ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDag(
407416 || field->getObject (f_type)->getValue <std::string>(f_type) == " list"
408417 || field->getObject (f_type)->getValue <std::string>(f_type) == " map" ))
409418 {
410- auto old_type = getFieldType (old_json, " type" , required);
419+ auto old_type = getFieldType (old_json, " type" , context_, required);
411420 auto transform = std::make_shared<EvolutionFunctionStruct>(std::vector{type}, std::vector{old_type}, old_json, field);
412421 old_node = &dag->addFunction (transform, std::vector<const Node *>{old_node}, name);
413422
@@ -437,7 +446,7 @@ std::shared_ptr<ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDag(
437446 }
438447 else if (allowPrimitiveTypeConversion (old_type, new_type))
439448 {
440- node = &dag->addCast (*old_node, getFieldType (field, f_type, required), name);
449+ node = &dag->addCast (*old_node, getFieldType (field, f_type, context_, required), name);
441450 }
442451 outputs.push_back (node);
443452 }
@@ -463,7 +472,10 @@ std::shared_ptr<ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDag(
463472 return dag;
464473}
465474
466- std::shared_ptr<const ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDagByIds (Int32 old_id, Int32 new_id)
475+ std::shared_ptr<const ActionsDAG> IcebergSchemaProcessor::getSchemaTransformationDagByIds (
476+ ContextPtr context_,
477+ Int32 old_id,
478+ Int32 new_id)
467479{
468480 if (old_id == new_id)
469481 return nullptr ;
@@ -482,7 +494,7 @@ std::shared_ptr<const ActionsDAG> IcebergSchemaProcessor::getSchemaTransformatio
482494 throw Exception (ErrorCodes::BAD_ARGUMENTS, " Schema with schema-id {} is unknown" , new_id);
483495
484496 return transform_dags_by_ids[{old_id, new_id}]
485- = getSchemaTransformationDag (old_schema_it->second , new_schema_it->second , old_id, new_id);
497+ = getSchemaTransformationDag (old_schema_it->second , new_schema_it->second , context_, old_id, new_id);
486498}
487499
488500Poco::JSON::Object::Ptr IcebergSchemaProcessor::getIcebergTableSchemaById (Int32 id) const
0 commit comments