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

Function lbug_value_create_list

src/c_api/value.cpp:328–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328lbug_state lbug_value_create_list(uint64_t num_elements, lbug_value** elements,
329 lbug_value** out_value) {
330 if (out_value == nullptr) {
331 return LbugError;
332 }
333 if (num_elements == 0) {
334 *out_value = createCAPIValue(std::make_unique<Value>(LogicalType::LIST(LogicalType::ANY()),
335 std::vector<std::unique_ptr<Value>>{}));
336 return LbugSuccess;
337 }
338 if (elements == nullptr) {
339 return LbugError;
340 }
341 std::vector<std::unique_ptr<Value>> children;
342
343 auto first_element = static_cast<Value*>(elements[0]->_value);
344 auto type = first_element->getDataType().copy();
345
346 for (uint64_t i = 0; i < num_elements; ++i) {
347 auto child = static_cast<Value*>(elements[i]->_value);
348 LogicalType resultType;
349 if (!tryGetMaxParameterType(type, child->getDataType(), resultType)) {
350 setLastCAPIErrorMessage(incompatibleParameterTypeMessage(type, child->getDataType()));
351 return LbugError;
352 }
353 type = std::move(resultType);
354 }
355 for (uint64_t i = 0; i < num_elements; ++i) {
356 auto child = static_cast<Value*>(elements[i]->_value);
357 if (!canCopyValueForNested(*child, type)) {
358 setLastCAPIErrorMessage(incompatibleParameterTypeMessage(child->getDataType(), type));
359 return LbugError;
360 }
361 children.push_back(copyValueForNested(*child, type));
362 }
363 auto* c_value = createCAPIValue(
364 std::make_unique<Value>(LogicalType::LIST(type.copy()), std::move(children)));
365 *out_value = c_value;
366 return LbugSuccess;
367}
368
369lbug_state lbug_value_create_struct(uint64_t num_fields, const char** field_names,
370 lbug_value** field_values, lbug_value** out_value) {

Callers 2

TEST_FFunction · 0.85
TESTFunction · 0.85

Calls 9

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

Tested by 2

TEST_FFunction · 0.68
TESTFunction · 0.68