MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / lbug_value_create_map

Function lbug_value_create_map

src/c_api/value.cpp:394–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392}
393
394lbug_state lbug_value_create_map(uint64_t num_fields, lbug_value** keys, lbug_value** values,
395 lbug_value** out_value) {
396 if (out_value == nullptr) {
397 return LbugError;
398 }
399 if (num_fields == 0) {
400 *out_value = createCAPIValue(
401 std::make_unique<Value>(LogicalType::MAP(LogicalType::ANY(), LogicalType::ANY()),
402 std::vector<std::unique_ptr<Value>>{}));
403 return LbugSuccess;
404 }
405 if (keys == nullptr || values == nullptr) {
406 return LbugError;
407 }
408 std::vector<std::unique_ptr<Value>> children;
409
410 auto first_key = static_cast<Value*>(keys[0]->_value);
411 auto first_value = static_cast<Value*>(values[0]->_value);
412 auto key_type = first_key->getDataType().copy();
413 auto value_type = first_value->getDataType().copy();
414
415 for (uint64_t i = 0; i < num_fields; ++i) {
416 auto key = static_cast<Value*>(keys[i]->_value);
417 auto value = static_cast<Value*>(values[i]->_value);
418 LogicalType resultKeyType;
419 LogicalType resultValueType;
420 if (!tryGetMaxParameterType(key_type, key->getDataType(), resultKeyType)) {
421 setLastCAPIErrorMessage(incompatibleParameterTypeMessage(key_type, key->getDataType()));
422 return LbugError;
423 }
424 if (!tryGetMaxParameterType(value_type, value->getDataType(), resultValueType)) {
425 setLastCAPIErrorMessage(
426 incompatibleParameterTypeMessage(value_type, value->getDataType()));
427 return LbugError;
428 }
429 key_type = std::move(resultKeyType);
430 value_type = std::move(resultValueType);
431 }
432 for (uint64_t i = 0; i < num_fields; ++i) {
433 auto key = static_cast<Value*>(keys[i]->_value);
434 auto value = static_cast<Value*>(values[i]->_value);
435 if (!canCopyValueForNested(*key, key_type)) {
436 setLastCAPIErrorMessage(incompatibleParameterTypeMessage(key->getDataType(), key_type));
437 return LbugError;
438 }
439 if (!canCopyValueForNested(*value, value_type)) {
440 setLastCAPIErrorMessage(
441 incompatibleParameterTypeMessage(value->getDataType(), value_type));
442 return LbugError;
443 }
444 std::vector<StructField> struct_fields;
445 struct_fields.emplace_back(InternalKeyword::MAP_KEY, key_type.copy());
446 struct_fields.emplace_back(InternalKeyword::MAP_VALUE, value_type.copy());
447 std::vector<std::unique_ptr<Value>> struct_values;
448 struct_values.push_back(copyValueForNested(*key, key_type));
449 struct_values.push_back(copyValueForNested(*value, value_type));
450 auto struct_type = LogicalType::STRUCT(std::move(struct_fields));
451 auto struct_value = new Value(std::move(struct_type), std::move(struct_values));

Callers 2

TEST_FFunction · 0.85
TESTFunction · 0.85

Calls 10

createCAPIValueFunction · 0.85
tryGetMaxParameterTypeFunction · 0.85
setLastCAPIErrorMessageFunction · 0.85
canCopyValueForNestedFunction · 0.85
copyValueForNestedFunction · 0.85
getDataTypeMethod · 0.80
emplace_backMethod · 0.80
copyMethod · 0.45
push_backMethod · 0.45

Tested by 2

TEST_FFunction · 0.68
TESTFunction · 0.68