Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::VectorStringToStruct Struct Reference

Static Public Member Functions

static bool SplitStruct (const string_t &input, vector< unique_ptr< Vector > > &varchar_vectors, idx_t &row_idx, string_map_t< idx_t > &child_names, vector< reference< ValidityMask > > &child_masks)
static bool StringToNestedTypeCastLoop (const string_t *source_data, ValidityMask &source_mask, Vector &result, ValidityMask &result_mask, idx_t count, CastParameters &parameters, const SelectionVector *sel)

Member Function Documentation

◆ SplitStruct()

bool duckdb::VectorStringToStruct::SplitStruct ( const string_t & input,
vector< unique_ptr< Vector > > & varchar_vectors,
idx_t & row_idx,
string_map_t< idx_t > & child_names,
vector< reference< ValidityMask > > & child_masks )
static

Regular struct, in the form of {name: value, name_2: value_2, ...}

Key can not be empty

Key can not be NULL

This is an unnamed struct in the form of (value, value_2, ...)

219337 {
219338 const char *buf = input.GetData();
219339 idx_t len = input.GetSize();
219340 idx_t pos = 0;
219341 idx_t child_idx;
219342
219343 Vector temp_vec(LogicalType::VARCHAR);
219344 StringCastInputState input_state(buf, pos, len);
219345
219346 SkipWhitespace(input_state);
219347 if (pos == len || (buf[pos] != '{' && buf[pos] != '(')) {
219348 return false;
219349 }
219350 auto end_char = buf[pos] == '{' ? '}' : ')';
219351 pos++;
219352 SkipWhitespace(input_state);
219353 if (buf[pos] == end_char) {
219354 pos++;
219355 SkipWhitespace(input_state);
219356 return (pos == len);
219357 }
219358
219359 if (end_char == '}') {
219361 while (pos < len) {
219362 optional_idx start_pos;
219363 idx_t end_pos;
219364 while (pos < len && buf[pos] != ':') {
219365 bool set_escaped = false;
219366
219367 if (input_state.escaped) {
219368 if (!start_pos.IsValid()) {
219369 start_pos = pos;
219370 }
219371 end_pos = pos;
219372 } else if (buf[pos] == '"' || buf[pos] == '\'') {
219373 if (!start_pos.IsValid()) {
219374 start_pos = pos;
219375 }
219376 if (!SkipToCloseQuotes(input_state)) {
219377 return false;
219378 }
219379 end_pos = pos;
219380 } else if (buf[pos] == '\\') {
219381 if (!start_pos.IsValid()) {
219382 start_pos = pos;
219383 }
219384 set_escaped = true;
219385 end_pos = pos;
219386 } else if (!StringUtil::CharacterIsSpace(buf[pos])) {
219387 if (!start_pos.IsValid()) {
219388 start_pos = pos;
219389 }
219390 end_pos = pos;
219391 }
219392 input_state.escaped = set_escaped;
219393 pos++;
219394 }
219395 if (pos == len) {
219396 return false;
219397 }
219398 if (!start_pos.IsValid()) {
219400 return false;
219401 }
219402 idx_t key_start = start_pos.GetIndex();
219403 end_pos++;
219404 if (IsNull(buf, key_start, end_pos)) {
219406 return false;
219407 }
219408 auto child_name = HandleString<false>(temp_vec, buf, key_start, end_pos);
219409 auto it = child_names.find(child_name);
219410 if (it == child_names.end()) {
219411 return false; // false key
219412 }
219413 child_idx = it->second;
219414
219415 start_pos = optional_idx();
219416 pos++;
219417 SkipWhitespace(input_state);
219418 while (pos < len && (buf[pos] != ',' && buf[pos] != '}')) {
219419 if (!ValueStateTransition(input_state, start_pos, end_pos)) {
219420 return false;
219421 }
219422 }
219423 if (pos == len) {
219424 return false;
219425 }
219426 auto &child_vec = *varchar_vectors[child_idx];
219427 auto string_data = FlatVector::GetData<string_t>(child_vec);
219428 auto &child_mask = child_masks[child_idx].get();
219429
219430 if (!start_pos.IsValid()) {
219431 start_pos = 0;
219432 end_pos = 0;
219433 } else {
219434 end_pos++;
219435 }
219436 auto value_start = start_pos.GetIndex();
219437 if (IsNull(buf, value_start, end_pos)) {
219438 child_mask.SetInvalid(row_idx);
219439 } else {
219440 string_data[row_idx] = HandleString(child_vec, buf, value_start, end_pos);
219441 child_mask.SetValid(row_idx);
219442 }
219443
219444 if (buf[pos] == '}') {
219445 break;
219446 }
219447 pos++;
219448 SkipWhitespace(input_state);
219449 }
219450 } else {
219452 D_ASSERT(end_char == ')');
219453 idx_t child_idx = 0;
219454 while (pos < len) {
219455 if (child_idx == child_masks.size()) {
219456 return false;
219457 }
219458
219459 optional_idx start_pos;
219460 idx_t end_pos;
219461 while (pos < len && (buf[pos] != ',' && buf[pos] != ')')) {
219462 if (!ValueStateTransition(input_state, start_pos, end_pos)) {
219463 return false;
219464 }
219465 }
219466 if (pos == len) {
219467 return false;
219468 }
219469 auto &child_vec = *varchar_vectors[child_idx];
219470 auto string_data = FlatVector::GetData<string_t>(child_vec);
219471 auto &child_mask = child_masks[child_idx].get();
219472
219473 if (!start_pos.IsValid()) {
219474 start_pos = 0;
219475 end_pos = 0;
219476 } else {
219477 end_pos++;
219478 }
219479 auto value_start = start_pos.GetIndex();
219480 if (IsNull(buf, value_start, end_pos)) {
219481 child_mask.SetInvalid(row_idx);
219482 } else {
219483 string_data[row_idx] = HandleString(child_vec, buf, value_start, end_pos);
219484 child_mask.SetValid(row_idx);
219485 }
219486
219487 if (buf[pos] == ')') {
219488 break;
219489 }
219490 child_idx++;
219491 pos++;
219492 SkipWhitespace(input_state);
219493 }
219494 (void)child_idx;
219495 }
219496 pos++;
219497 SkipWhitespace(input_state);
219498 return (pos == len);
219499}
static string_t HandleString(Vector &vec, const char *buf, idx_t start, idx_t end)
Definition duckdb.cpp:219008
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ StringToNestedTypeCastLoop()

bool duckdb::VectorStringToStruct::StringToNestedTypeCastLoop ( const string_t * source_data,
ValidityMask & source_mask,
Vector & result,
ValidityMask & result_mask,
idx_t count,
CastParameters & parameters,
const SelectionVector * sel )
static
214833 {
214834 auto varchar_struct_type = InitVarcharStructType(result.GetType());
214835 Vector varchar_vector(varchar_struct_type, count);
214836 auto &child_vectors = StructVector::GetEntries(varchar_vector);
214837 auto &result_children = StructVector::GetEntries(result);
214838 auto is_unnamed = StructType::IsUnnamed(result.GetType());
214839
214840 string_map_t<idx_t> child_names;
214841 vector<reference<ValidityMask>> child_masks;
214842 for (idx_t child_idx = 0; child_idx < result_children.size(); child_idx++) {
214843 if (!is_unnamed) {
214844 child_names.insert({StructType::GetChildName(result.GetType(), child_idx), child_idx});
214845 }
214846 child_masks.emplace_back(FlatVector::Validity(*child_vectors[child_idx]));
214847 child_masks[child_idx].get().SetAllInvalid(count);
214848 }
214849
214850 VectorTryCastData vector_cast_data(result, parameters);
214851 for (idx_t i = 0; i < count; i++) {
214852 idx_t idx = i;
214853 if (sel) {
214854 idx = sel->get_index(i);
214855 }
214856 if (!source_mask.RowIsValid(idx)) {
214857 result_mask.SetInvalid(i);
214858 continue;
214859 }
214860 if (!VectorStringToStruct::SplitStruct(source_data[idx], child_vectors, i, child_names, child_masks)) {
214861 auto error = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type %s",
214862 source_data[idx].GetString(), result.GetType().ToString());
214863 for (auto &child_mask : child_masks) {
214864 child_mask.get().SetInvalid(i); // some values may have already been found and set valid
214865 }
214866 HandleVectorCastError::Operation<string_t>(error, result_mask, i, vector_cast_data);
214867 }
214868 }
214869
214870 auto &cast_data = parameters.cast_data->Cast<StructBoundCastData>();
214871 auto &lstate = parameters.local_state->Cast<StructCastLocalState>();
214872 D_ASSERT(cast_data.child_cast_info.size() == result_children.size());
214873
214874 for (idx_t child_idx = 0; child_idx < result_children.size(); child_idx++) {
214875 auto &child_varchar_vector = *child_vectors[child_idx];
214876 auto &result_child_vector = *result_children[child_idx];
214877 auto &child_cast_info = cast_data.child_cast_info[child_idx];
214878 CastParameters child_parameters(parameters, child_cast_info.cast_data, lstate.local_states[child_idx]);
214879 if (!child_cast_info.function(child_varchar_vector, result_child_vector, count, child_parameters)) {
214880 vector_cast_data.all_converted = false;
214881 }
214882 }
214883 return vector_cast_data.all_converted;
214884}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
static bool SplitStruct(const string_t &input, vector< unique_ptr< Vector > > &varchar_vectors, idx_t &row_idx, string_map_t< idx_t > &child_names, vector< reference< ValidityMask > > &child_masks)
Definition duckdb.cpp:219335

The documentation for this struct was generated from the following file: