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::StringValueResult Class Reference
Inheritance diagram for duckdb::StringValueResult:
Collaboration diagram for duckdb::StringValueResult:

Public Member Functions

 StringValueResult (CSVStates &states, CSVStateMachine &state_machine, const shared_ptr< CSVBufferHandle > &buffer_handle, Allocator &buffer_allocator, idx_t result_size_p, idx_t buffer_position, CSVErrorHandler &error_handler, CSVIterator &iterator, bool store_line_size, shared_ptr< CSVFileScan > csv_file_scan, idx_t &lines_read, bool sniffing, const string &path, idx_t scan_id, bool &used_unstrictness)
void NullPaddingQuotedNewlineCheck () const
bool AddRowInternal ()
void HandleUnicodeError (idx_t col_idx, LinePosition &error_position)
 Force the throw of a Unicode error.
bool HandleTooManyColumnsError (const char *value_ptr, const idx_t size)
void AddValueToVector (const char *value_ptr, idx_t size, bool allocate=false)
idx_t HandleMultiDelimiter (const idx_t buffer_pos) const
DataChunk & ToChunk ()
void Reset ()
 Resets the state of the result.
void SkipBOM () const
 BOM skipping (https://en.wikipedia.org/wiki/Byte_order_mark).
bool PrintErrorLine () const
void RemoveLastLine ()
Public Member Functions inherited from duckdb::ScannerResult
 ScannerResult (CSVStates &states, CSVStateMachine &state_machine, idx_t result_size)
bool IsStateCurrent (CSVState state) const
void Print () const

Static Public Member Functions

static void AddQuotedValue (StringValueResult &result, const idx_t buffer_pos)
 Specialized code for quoted values, makes sure to remove quotes and escapes.
static void AddPossiblyEscapedValue (StringValueResult &result, const idx_t buffer_pos, const char *value_ptr, const idx_t length, const bool empty)
 Specialized code for possibly escaped values, makes sure to remove escapes.
static void AddValue (StringValueResult &result, const idx_t buffer_pos)
 Adds a Value to the result.
static bool AddRow (StringValueResult &result, const idx_t buffer_pos)
 Adds a Row to the result.
static void InvalidState (StringValueResult &result)
 Behavior when hitting an invalid state.
static void QuotedNewLine (StringValueResult &result)
 Handles QuotedNewline State.
static bool EmptyLine (StringValueResult &result, const idx_t buffer_pos)
 Handles EmptyLine states.
static void SetComment (StringValueResult &result, idx_t buffer_pos)
static bool UnsetComment (StringValueResult &result, idx_t buffer_pos)
Static Public Member Functions inherited from duckdb::ScannerResult
static void SetQuoted (ScannerResult &result, idx_t quoted_position)
static void SetUnquoted (ScannerResult &result)
static void SetEscaped (ScannerResult &result)
static void SetComment (ScannerResult &result, idx_t buffer_pos)
static bool UnsetComment (ScannerResult &result, idx_t buffer_pos)
static bool IsCommentSet (const ScannerResult &result)

Public Attributes

unsafe_vector< void * > vector_ptr
 Information on the vector.
unsafe_vector< ValidityMask * > validity_mask
char * buffer_ptr
 Variables to iterate over the CSV buffers.
idx_t buffer_size
idx_t position_before_comment
const uint32_t number_of_columns
 CSV Options that impact the parsing.
const bool null_padding
const bool ignore_errors
const idx_t extra_delimiter_bytes = 0
unsafe_unique_array< const char * > null_str_ptr
unsafe_unique_array< idx_t > null_str_size
idx_t null_str_count
DataChunk parse_chunk
 Internal Data Chunk used for flushing.
int64_t number_of_rows = 0
idx_t cur_col_id = 0
bool figure_out_new_line = false
CSVErrorHandler & error_handler
 Information to properly handle errors.
CSVIterator & iterator
FullLinePosition current_line_position
 Line position of the current line.
unordered_map< idx_t, FullLinePosition > line_positions_per_row
 Used for CSV line reconstruction on flushed errors.
bool store_line_size = false
bool added_last_line = false
bool quoted_new_line = false
bool try_row = false
 If we are trying a row or not when figuring out the next row to start from.
unsafe_unique_array< ParseTypeInfo > parse_types
vector< string > names
shared_ptr< CSVFileScan > csv_file_scan
idx_t & lines_read
bool & used_unstrictness
unsafe_unique_array< bool > projected_columns
 Information regarding projected columns.
bool projecting_columns = false
idx_t chunk_col_id = 0
bool icu_loaded = false
unordered_map< idx_t, shared_ptr< CSVBufferHandle > > buffer_handles
 We must ensure that we keep the buffers alive until processing the query result.
idx_t requested_size
 Requested size of buffers (i.e., either 32Mb or set by buffer_size parameter).
LineError current_errors
 Errors happening in the current line (if any).
StrpTimeFormat date_format
StrpTimeFormat timestamp_format
bool sniffing
char decimal_separator
unordered_set< idx_t > borked_rows
 We store borked rows so we can generate multiple errors during flushing.
String path
bool first_line_is_comment = false
bool ignore_empty_values = true
Public Attributes inherited from duckdb::ScannerResult
bool quoted = false
 Variable to keep information regarding quoted and escaped values.
bool unquoted = false
 If the current quoted value is unquoted.
bool escaped = false
 If the current value has been escaped.
bool comment = false
 Variable to keep track if we are in a comment row. Hence, won't add it.
idx_t quoted_position = 0
LinePosition last_position
const idx_t result_size
 Size of the result.
CSVStateMachine & state_machine
bool cur_line_starts_as_comment = false

Additional Inherited Members

Protected Attributes inherited from duckdb::ScannerResult
CSVStates & states

Constructor & Destructor Documentation

◆ StringValueResult()

duckdb::StringValueResult::StringValueResult ( CSVStates & states,
CSVStateMachine & state_machine,
const shared_ptr< CSVBufferHandle > & buffer_handle,
Allocator & buffer_allocator,
idx_t result_size_p,
idx_t buffer_position,
CSVErrorHandler & error_handler,
CSVIterator & iterator,
bool store_line_size,
shared_ptr< CSVFileScan > csv_file_scan,
idx_t & lines_read,
bool sniffing,
const string & path,
idx_t scan_id,
bool & used_unstrictness )
169304 : ScannerResult(states, state_machine, result_size_p),
169305 number_of_columns(NumericCast<uint32_t>(state_machine.dialect_options.num_cols)),
169306 null_padding(state_machine.options.null_padding), ignore_errors(state_machine.options.ignore_errors.GetValue()),
169307 extra_delimiter_bytes(state_machine.dialect_options.state_machine_options.delimiter.GetValue().empty()
169308 ? 0
169309 : state_machine.dialect_options.state_machine_options.delimiter.GetValue().size() - 1),
169310 error_handler(error_hander_p), iterator(iterator_p), store_line_size(store_line_size_p),
169311 csv_file_scan(std::move(csv_file_scan_p)), lines_read(lines_read_p), used_unstrictness(used_unstrictness),
169312 current_errors(scan_id, state_machine.options.IgnoreErrors()), sniffing(sniffing_p), path(path_p) {
169313 // Vector information
169314 D_ASSERT(number_of_columns > 0);
169315 if (!buffer_handle) {
169316 // It Was Over Before It Even Began
169317 D_ASSERT(iterator.done);
169318 return;
169319 }
169320 buffer_handles[buffer_handle->buffer_idx] = buffer_handle;
169321 // Buffer Information
169322 buffer_ptr = buffer_handle->Ptr();
169323 buffer_size = buffer_handle->actual_size;
169324 last_position = {buffer_handle->buffer_idx, buffer_position, buffer_size};
169325 requested_size = buffer_handle->requested_size;
169326 // Current Result information
169327 current_line_position.begin = {iterator.pos.buffer_idx, iterator.pos.buffer_pos, buffer_handle->actual_size};
169329 // Fill out Parse Types
169330 vector<LogicalType> logical_types;
169331 parse_types = make_unsafe_uniq_array<ParseTypeInfo>(number_of_columns);
169332 LogicalType varchar_type = LogicalType::VARCHAR;
169333 if (!csv_file_scan) {
169334 for (idx_t i = 0; i < number_of_columns; i++) {
169335 parse_types[i] = ParseTypeInfo(varchar_type, true);
169336 logical_types.emplace_back(LogicalType::VARCHAR);
169337 string name = "Column_" + to_string(i);
169338 names.emplace_back(name);
169339 }
169340 } else {
169341 if (csv_file_scan->file_types.size() > number_of_columns) {
169342 throw InvalidInputException(
169343 "Mismatch between the number of columns (%d) in the CSV file and what is expected in the scanner (%d).",
169344 number_of_columns, csv_file_scan->file_types.size());
169345 }
169346 icu_loaded = csv_file_scan->buffer_manager->context.db->ExtensionIsLoaded("icu");
169347 for (idx_t i = 0; i < csv_file_scan->file_types.size(); i++) {
169348 auto type = csv_file_scan->file_types[i];
169349 if (type.IsJSONType()) {
169350 type = LogicalType::VARCHAR;
169351 }
169352 if (StringValueScanner::CanDirectlyCast(type, icu_loaded)) {
169353 parse_types[i] = ParseTypeInfo(type, true);
169354 logical_types.emplace_back(type);
169355 } else {
169356 parse_types[i] = ParseTypeInfo(varchar_type, type.id() == LogicalTypeId::VARCHAR || type.IsNested());
169357 logical_types.emplace_back(LogicalType::VARCHAR);
169358 }
169359 }
169360 names = csv_file_scan->GetNames();
169361 if (!csv_file_scan->projected_columns.empty()) {
169362 projecting_columns = false;
169363 projected_columns = make_unsafe_uniq_array<bool>(number_of_columns);
169364 for (idx_t col_idx = 0; col_idx < number_of_columns; col_idx++) {
169365 if (csv_file_scan->projected_columns.find(col_idx) == csv_file_scan->projected_columns.end()) {
169366 // Column is not projected
169367 projecting_columns = true;
169368 projected_columns[col_idx] = false;
169369 } else {
169370 projected_columns[col_idx] = true;
169371 }
169372 }
169373 }
169374 if (!projecting_columns) {
169375 for (idx_t j = logical_types.size(); j < number_of_columns; j++) {
169376 // This can happen if we have sneaky null columns at the end that we wish to ignore
169377 parse_types[j] = ParseTypeInfo(varchar_type, true);
169378 logical_types.emplace_back(LogicalType::VARCHAR);
169379 }
169380 }
169381 }
169382
169383 // Initialize Parse Chunk
169384 parse_chunk.Initialize(buffer_allocator, logical_types, result_size);
169385 for (auto &col : parse_chunk.data) {
169386 vector_ptr.push_back(FlatVector::GetData(col));
169387 validity_mask.push_back(&FlatVector::Validity(col));
169388 }
169389
169390 // Setup the NullStr information
169391 null_str_count = state_machine.options.null_str.size();
169392 null_str_ptr = make_unsafe_uniq_array_uninitialized<const char *>(null_str_count);
169393 null_str_size = make_unsafe_uniq_array_uninitialized<idx_t>(null_str_count);
169394 for (idx_t i = 0; i < null_str_count; i++) {
169395 null_str_ptr[i] = state_machine.options.null_str[i].c_str();
169396 null_str_size[i] = state_machine.options.null_str[i].size();
169397 }
169398 date_format = state_machine.options.dialect_options.date_format.at(LogicalTypeId::DATE).GetValue();
169399 timestamp_format = state_machine.options.dialect_options.date_format.at(LogicalTypeId::TIMESTAMP).GetValue();
169400 decimal_separator = state_machine.options.decimal_separator[0];
169401
169402 if (iterator.first_one) {
169403 lines_read +=
169404 state_machine.dialect_options.skip_rows.GetValue() + state_machine.dialect_options.header.GetValue();
169405 if (lines_read == 0) {
169406 SkipBOM();
169407 }
169408 }
169409 ignore_empty_values = state_machine.dialect_options.state_machine_options.delimiter.GetValue()[0] != ' ' &&
169410 state_machine.dialect_options.state_machine_options.quote != ' ' &&
169411 state_machine.dialect_options.state_machine_options.escape != ' ' &&
169412 state_machine.dialect_options.state_machine_options.comment != ' ';
169413}
const idx_t result_size
Size of the result.
Definition duckdb.cpp:167232
LineError current_errors
Errors happening in the current line (if any).
Definition duckdb.cpp:167832
FullLinePosition current_line_position
Line position of the current line.
Definition duckdb.cpp:167802
char * buffer_ptr
Variables to iterate over the CSV buffers.
Definition duckdb.cpp:167778
const uint32_t number_of_columns
CSV Options that impact the parsing.
Definition duckdb.cpp:167783
DataChunk parse_chunk
Internal Data Chunk used for flushing.
Definition duckdb.cpp:167794
CSVErrorHandler & error_handler
Information to properly handle errors.
Definition duckdb.cpp:167799
unsafe_vector< void * > vector_ptr
Information on the vector.
Definition duckdb.cpp:167773
unsafe_unique_array< bool > projected_columns
Information regarding projected columns.
Definition duckdb.cpp:167819
unordered_map< idx_t, shared_ptr< CSVBufferHandle > > buffer_handles
We must ensure that we keep the buffers alive until processing the query result.
Definition duckdb.cpp:167826
idx_t requested_size
Requested size of buffers (i.e., either 32Mb or set by buffer_size parameter).
Definition duckdb.cpp:167829
void SkipBOM() const
BOM skipping (https://en.wikipedia.org/wiki/Byte_order_mark).
Definition duckdb.cpp:170939
static bool CanDirectlyCast(const LogicalType &type, bool icu_loaded)
If we can directly cast the type when consuming the CSV file, or we have to do it later.
Definition duckdb.cpp:171040
std::string to_string(const T &value)
Definition duckdb.cpp:19425
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ~StringValueResult()

duckdb::StringValueResult::~StringValueResult ( )
169415 {
169416 // We have to insert the lines read by this scanner
169417 error_handler.Insert(iterator.GetBoundaryIdx(), lines_read);
169418 if (!iterator.done) {
169419 // Some operators, like Limit, might cause a future error to incorrectly report the wrong error line
169420 // Better to print nothing to print something wrong
169421 error_handler.DontPrintErrorLine();
169422 }
169423}

Member Function Documentation

◆ AddQuotedValue()

void duckdb::StringValueResult::AddQuotedValue ( StringValueResult & result,
const idx_t buffer_pos )
inlinestatic

Specialized code for quoted values, makes sure to remove quotes and escapes.

169806 {
169807 if (!result.unquoted) {
169808 result.current_errors.Insert(UNTERMINATED_QUOTES, result.cur_col_id, result.chunk_col_id, result.last_position);
169809 }
169810 if (buffer_pos <= result.quoted_position + 1) {
169811 AddPossiblyEscapedValue(result, buffer_pos, result.buffer_ptr + result.quoted_position + 1, 0,
169812 buffer_pos < result.last_position.buffer_pos + 2);
169813 result.quoted = false;
169814 return;
169815 }
169816 // remove potential empty values
169817 idx_t length = buffer_pos - result.quoted_position - 1;
169818 while (length > 0 && result.ignore_empty_values &&
169819 result.buffer_ptr[result.quoted_position + 1 + length - 1] == ' ') {
169820 length--;
169821 }
169822 if (length == 0) {
169823 // All content was stripped as empty/space values
169824 AddPossiblyEscapedValue(result, buffer_pos, result.buffer_ptr + result.quoted_position + 1, 0, true);
169825 result.quoted = false;
169826 return;
169827 }
169828 length--;
169829 AddPossiblyEscapedValue(result, buffer_pos, result.buffer_ptr + result.quoted_position + 1, length,
169830 buffer_pos < result.last_position.buffer_pos + 2);
169831 result.quoted = false;
169832}
static void AddPossiblyEscapedValue(StringValueResult &result, const idx_t buffer_pos, const char *value_ptr, const idx_t length, const bool empty)
Specialized code for possibly escaped values, makes sure to remove escapes.
Definition duckdb.cpp:169834
@ UNTERMINATED_QUOTES
If the CSV has too many column.
Definition duckdb.cpp:166189
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddPossiblyEscapedValue()

void duckdb::StringValueResult::AddPossiblyEscapedValue ( StringValueResult & result,
const idx_t buffer_pos,
const char * value_ptr,
const idx_t length,
const bool empty )
inlinestatic

Specialized code for possibly escaped values, makes sure to remove escapes.

169835 {
169836 if (result.escaped) {
169837 if (result.projecting_columns) {
169838 if (!result.projected_columns[result.cur_col_id]) {
169839 result.cur_col_id++;
169840 result.escaped = false;
169841 return;
169842 }
169843 }
169844 if (result.cur_col_id >= result.number_of_columns &&
169845 !result.state_machine.state_machine_options.strict_mode.GetValue()) {
169846 result.used_unstrictness = true;
169847 return;
169848 }
169849 if (!result.HandleTooManyColumnsError(value_ptr, length)) {
169850 // If it's an escaped value we have to remove all the escapes, this is not really great
169851 // If we are going to escape, this vector must be a varchar vector
169852 if (result.parse_chunk.data[result.chunk_col_id].GetType() != LogicalType::VARCHAR) {
169853 result.current_errors.Insert(CAST_ERROR, result.cur_col_id, result.chunk_col_id, result.last_position);
169854 if (!result.state_machine.options.IgnoreErrors()) {
169855 // We have to write the cast error message.
169856 std::ostringstream error;
169857 // Casting Error Message
169858 error << "Could not convert string \"" << std::string(value_ptr, length) << "\" to \'"
169859 << LogicalTypeIdToString(result.parse_types[result.chunk_col_id].type_id) << "\'";
169860 auto error_string = error.str();
169861 FullLinePosition::SanitizeError(error_string);
169862 result.current_errors.ModifyErrorMessageOfLastError(error_string);
169863 }
169864 result.cur_col_id++;
169865 result.chunk_col_id++;
169866 } else {
169867 if (result.parse_chunk.data[result.chunk_col_id].GetType() != LogicalType::VARCHAR) {
169868 // We cant have escapes on non varchar columns
169869 result.current_errors.Insert(CAST_ERROR, result.cur_col_id, result.chunk_col_id,
169870 result.last_position);
169871 if (!result.state_machine.options.IgnoreErrors()) {
169872 // We have to write the cast error message.
169873 std::ostringstream error;
169874 // Casting Error Message
169875 error << "Could not convert string \"" << std::string(value_ptr, length) << "\" to \'"
169876 << LogicalTypeIdToString(result.parse_types[result.chunk_col_id].type_id) << "\'";
169877 auto error_string = error.str();
169878 FullLinePosition::SanitizeError(error_string);
169879 result.current_errors.ModifyErrorMessageOfLastError(error_string);
169880 }
169881 return;
169882 }
169884 value_ptr, length, result.state_machine.dialect_options.state_machine_options.escape.GetValue(),
169885 result.state_machine.dialect_options.state_machine_options.quote.GetValue(),
169886 result.state_machine.dialect_options.state_machine_options.strict_mode.GetValue(),
169887 result.parse_chunk.data[result.chunk_col_id]);
169888 result.AddValueToVector(value.GetData(), value.GetSize());
169889 }
169890 }
169891 } else {
169892 if (empty) {
169893 // empty value
169894 auto value = string_t();
169895 result.AddValueToVector(value.GetData(), value.GetSize());
169896 } else {
169897 result.AddValueToVector(value_ptr, length);
169898 }
169899 }
169900 result.escaped = false;
169901}
static string_t RemoveEscape(const char *str_ptr, idx_t end, char escape, char quote, bool strict_mode, Vector &vector)
Creates a new string with all escaped values removed.
Definition duckdb.cpp:170609
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddValue()

void duckdb::StringValueResult::AddValue ( StringValueResult & result,
const idx_t buffer_pos )
inlinestatic

Adds a Value to the result.

169920 {
169921 if (result.last_position.buffer_pos > buffer_pos) {
169922 return;
169923 }
169924 if (result.quoted) {
169925 AddQuotedValue(result, buffer_pos - result.extra_delimiter_bytes);
169926 } else if (result.escaped) {
169927 AddPossiblyEscapedValue(result, buffer_pos, result.buffer_ptr + result.last_position.buffer_pos,
169928 buffer_pos - result.last_position.buffer_pos, false);
169929 } else {
169930 result.AddValueToVector(result.buffer_ptr + result.last_position.buffer_pos,
169931 result.HandleMultiDelimiter(buffer_pos));
169932 }
169933 result.last_position.buffer_pos = buffer_pos + 1;
169934}
static void AddQuotedValue(StringValueResult &result, const idx_t buffer_pos)
Specialized code for quoted values, makes sure to remove quotes and escapes.
Definition duckdb.cpp:169806
Here is the call graph for this function:

◆ AddRow()

bool duckdb::StringValueResult::AddRow ( StringValueResult & result,
const idx_t buffer_pos )
inlinestatic

Adds a Row to the result.

170199 {
170200 if (result.last_position.buffer_pos <= buffer_pos) {
170201 // We add the value
170202 if (result.quoted) {
170203 AddQuotedValue(result, buffer_pos);
170204 } else {
170205 char *value_ptr = result.buffer_ptr + result.last_position.buffer_pos;
170206 idx_t size = buffer_pos - result.last_position.buffer_pos;
170207 if (result.escaped) {
170208 AddPossiblyEscapedValue(result, buffer_pos, value_ptr, size, size == 0);
170209 } else {
170210 result.AddValueToVector(value_ptr, size);
170211 }
170212 }
170213 if (result.state_machine.dialect_options.state_machine_options.new_line == NewLineIdentifier::CARRY_ON) {
170214 if (result.states.states[1] == CSVState::RECORD_SEPARATOR) {
170215 // Even though this is marked as a carry on, this is a hippie mixie
170216 result.last_position.buffer_pos = buffer_pos + 1;
170217 } else {
170218 result.last_position.buffer_pos = buffer_pos + 2;
170219 }
170220 } else {
170221 result.last_position.buffer_pos = buffer_pos + 1;
170222 }
170223 }
170224
170225 // We add the value
170226 return result.AddRowInternal();
170227}
GOpaque< Size > size(const GMat &src)
@ RECORD_SEPARATOR
-----------------------------------------------------------------------------------------------------...
Definition duckdb.cpp:59181
Here is the call graph for this function:

◆ InvalidState()

void duckdb::StringValueResult::InvalidState ( StringValueResult & result)
inlinestatic

Behavior when hitting an invalid state.

170229 {
170230 if (result.quoted) {
170231 result.current_errors.Insert(UNTERMINATED_QUOTES, result.cur_col_id, result.chunk_col_id, result.last_position);
170232 } else {
170233 LinesPerBoundary lines_per_batch(result.iterator.GetBoundaryIdx(), result.lines_read);
170234 bool first_nl = false;
170235 auto borked_line = result.current_line_position.ReconstructCurrentLine(first_nl, result.buffer_handles,
170236 result.PrintErrorLine());
170237 CSVError csv_error;
170238 auto error = CSVError::InvalidState(
170239 result.state_machine.options, result.cur_col_id, lines_per_batch, borked_line,
170240 result.current_line_position.begin.GetGlobalPosition(result.requested_size, first_nl),
170241 result.last_position.GetGlobalPosition(result.requested_size, first_nl), result.path);
170242 result.error_handler.Error(error, true);
170243 }
170244}
static CSVError InvalidState(const CSVReaderOptions &options, idx_t current_column, LinesPerBoundary error_info, string &csv_row, idx_t row_byte_position, optional_idx byte_position, const String &current_path)
Produces error for when the state machine reaches an invalid state.
Definition duckdb.cpp:175903
Here is the call graph for this function:

◆ QuotedNewLine()

void duckdb::StringValueResult::QuotedNewLine ( StringValueResult & result)
inlinestatic

Handles QuotedNewline State.

170084 {
170085 result.quoted_new_line = true;
170086}

◆ NullPaddingQuotedNewlineCheck()

void duckdb::StringValueResult::NullPaddingQuotedNewlineCheck ( ) const
170088 {
170089 // We do some checks for null_padding correctness
170090 if (state_machine.options.null_padding && iterator.IsBoundarySet() && quoted_new_line) {
170091 // If we have null_padding set, we found a quoted new line, we are scanning the file in parallel; We error.
170092 LinesPerBoundary lines_per_batch(iterator.GetBoundaryIdx(), lines_read);
170093 auto csv_error = CSVError::NullPaddingFail(state_machine.options, lines_per_batch, path);
170094 error_handler.Error(csv_error, true);
170095 }
170096}
static CSVError NullPaddingFail(const CSVReaderOptions &options, LinesPerBoundary error_info, const String &current_path)
Produces error messages for null_padding option is set, and we have quoted new values in parallel.
Definition duckdb.cpp:176060

◆ EmptyLine()

bool duckdb::StringValueResult::EmptyLine ( StringValueResult & result,
const idx_t buffer_pos )
inlinestatic

Handles EmptyLine states.

170246 {
170247 // We care about empty lines if this is a single column csv file
170248 result.last_position = {result.iterator.pos.buffer_idx, result.iterator.pos.buffer_pos + 1, result.buffer_size};
170249 if (result.states.IsCarriageReturn() &&
170250 result.state_machine.dialect_options.state_machine_options.new_line == NewLineIdentifier::CARRY_ON) {
170251 result.last_position.buffer_pos++;
170252 }
170253 if (result.number_of_columns == 1) {
170254 for (idx_t i = 0; i < result.null_str_count; i++) {
170255 if (result.null_str_size[i] == 0) {
170256 bool empty = false;
170257 if (!result.state_machine.options.force_not_null.empty()) {
170258 empty = result.state_machine.options.force_not_null[0];
170259 }
170260 if (empty) {
170261 static_cast<string_t *>(result.vector_ptr[0])[result.number_of_rows] = string_t();
170262 } else {
170263 result.validity_mask[0]->SetInvalid(static_cast<idx_t>(result.number_of_rows));
170264 }
170265 result.number_of_rows++;
170266 }
170267 }
170268 if (static_cast<idx_t>(result.number_of_rows) >= result.result_size) {
170269 // We have a full chunk
170270 return true;
170271 }
170272 }
170273 return false;
170274}

◆ AddRowInternal()

bool duckdb::StringValueResult::AddRowInternal ( )
inline
170098 {
170099 LinePosition current_line_start = {iterator.pos.buffer_idx, iterator.pos.buffer_pos, buffer_size};
170100 idx_t current_line_size = current_line_start - current_line_position.end;
170101 if (store_line_size) {
170102 error_handler.NewMaxLineSize(current_line_size);
170103 }
170105 current_line_position.end = current_line_start;
170106 if (current_line_size > state_machine.options.maximum_line_size.GetValue()) {
170107 current_errors.Insert(MAXIMUM_LINE_SIZE, 1, chunk_col_id, last_position, current_line_size);
170108 }
170109 if (!state_machine.options.null_padding) {
170110 for (idx_t col_idx = cur_col_id; col_idx < number_of_columns; col_idx++) {
170111 current_errors.Insert(TOO_FEW_COLUMNS, col_idx - 1, chunk_col_id, last_position);
170112 }
170113 }
170114
170115 const auto chunk_col_id_before = chunk_col_id;
170116 if (current_errors.HandleErrors(*this)) {
170117 // Before we add row, invalid all columns that are not populated for this row (i.e., CSV rows have fewer fields
170118 // than expected). Otherwise, uninitialized string_t with valid bits set would lead invalid memory access.
170119 if (borked_rows.find(static_cast<idx_t>(number_of_rows)) != borked_rows.end()) {
170120 for (idx_t cur_col_idx = chunk_col_id_before; cur_col_idx < validity_mask.size(); ++cur_col_idx) {
170121 validity_mask[cur_col_idx]->SetInvalid(static_cast<idx_t>(number_of_rows));
170122 }
170123 }
170124
170125 D_ASSERT(buffer_handles.find(current_line_position.begin.buffer_idx) != buffer_handles.end());
170126 D_ASSERT(buffer_handles.find(current_line_position.end.buffer_idx) != buffer_handles.end());
170127 line_positions_per_row[static_cast<idx_t>(number_of_rows)] = current_line_position;
170128 number_of_rows++;
170129 if (static_cast<idx_t>(number_of_rows) >= result_size) {
170130 // We have a full chunk
170131 return true;
170132 }
170133 return false;
170134 }
170135 NullPaddingQuotedNewlineCheck();
170136 quoted_new_line = false;
170137 // We need to check if we are getting the correct number of columns here.
170138 // If columns are correct, we add it, and that's it.
170139 if (cur_col_id < number_of_columns) {
170140 // We have too few columns:
170141 if (null_padding) {
170142 while (cur_col_id < number_of_columns) {
170143 bool empty = false;
170144 if (cur_col_id < state_machine.options.force_not_null.size()) {
170145 empty = state_machine.options.force_not_null[cur_col_id];
170146 }
170147 if (projecting_columns) {
170148 if (!projected_columns[cur_col_id]) {
170149 cur_col_id++;
170150 continue;
170151 }
170152 }
170153 if (empty) {
170154 static_cast<string_t *>(vector_ptr[chunk_col_id])[number_of_rows] = string_t();
170155 } else {
170156 validity_mask[chunk_col_id]->SetInvalid(static_cast<idx_t>(number_of_rows));
170157 }
170158 cur_col_id++;
170159 chunk_col_id++;
170160 }
170161 } else {
170162 // If we are not null-padding this is an error
170163 if (!state_machine.options.IgnoreErrors()) {
170164 bool first_nl = false;
170165 auto borked_line =
170166 current_line_position.ReconstructCurrentLine(first_nl, buffer_handles, PrintErrorLine());
170167 LinesPerBoundary lines_per_batch(iterator.GetBoundaryIdx(), lines_read);
170168 if (current_line_position.begin == last_position) {
170169 auto csv_error = CSVError::IncorrectColumnAmountError(
170170 state_machine.options, cur_col_id - 1, lines_per_batch, borked_line,
170171 current_line_position.begin.GetGlobalPosition(requested_size, first_nl),
170172 last_position.GetGlobalPosition(requested_size, first_nl), path);
170173 error_handler.Error(csv_error, try_row);
170174 } else {
170175 auto csv_error = CSVError::IncorrectColumnAmountError(
170176 state_machine.options, cur_col_id - 1, lines_per_batch, borked_line,
170177 current_line_position.begin.GetGlobalPosition(requested_size, first_nl),
170178 last_position.GetGlobalPosition(requested_size), path);
170179 error_handler.Error(csv_error, try_row);
170180 }
170181 }
170182 // If we are here we ignore_errors, so we delete this line
170183 RemoveLastLine();
170184 }
170185 }
170186 D_ASSERT(buffer_handles.find(current_line_position.begin.buffer_idx) != buffer_handles.end());
170187 D_ASSERT(buffer_handles.find(current_line_position.end.buffer_idx) != buffer_handles.end());
170188 line_positions_per_row[static_cast<idx_t>(number_of_rows)] = current_line_position;
170189 cur_col_id = 0;
170190 chunk_col_id = 0;
170191 number_of_rows++;
170192 if (static_cast<idx_t>(number_of_rows) >= result_size) {
170193 // We have a full chunk
170194 return true;
170195 }
170196 return false;
170197}
static CSVError IncorrectColumnAmountError(const CSVReaderOptions &state_machine, idx_t actual_columns, LinesPerBoundary error_info, string &csv_row, idx_t row_byte_position, optional_idx byte_position, const String &current_path)
Produces error for incorrect (e.g., smaller and lower than the predefined) number of columns in a CSV...
Definition duckdb.cpp:176089
bool try_row
If we are trying a row or not when figuring out the next row to start from.
Definition duckdb.cpp:167810
void RemoveLastLine()
Definition duckdb.cpp:170943
bool PrintErrorLine() const
Definition duckdb.cpp:170954
unordered_set< idx_t > borked_rows
We store borked rows so we can generate multiple errors during flushing.
Definition duckdb.cpp:167839
unordered_map< idx_t, FullLinePosition > line_positions_per_row
Used for CSV line reconstruction on flushed errors.
Definition duckdb.cpp:167804
@ TOO_FEW_COLUMNS
If there is a mismatch between Column Names and Types.
Definition duckdb.cpp:166187
@ MAXIMUM_LINE_SIZE
If something went wrong during sniffing and was not possible to find suitable candidates.
Definition duckdb.cpp:166191

◆ HandleUnicodeError()

void duckdb::StringValueResult::HandleUnicodeError ( idx_t col_idx,
LinePosition & error_position )

Force the throw of a Unicode error.

169936 {
169937 bool first_nl = false;
169938 auto borked_line = current_line_position.ReconstructCurrentLine(first_nl, buffer_handles, PrintErrorLine());
169939 LinesPerBoundary lines_per_batch(iterator.GetBoundaryIdx(), lines_read);
169940 if (current_line_position.begin == error_position) {
169941 auto csv_error = CSVError::InvalidUTF8(state_machine.options, col_idx, lines_per_batch, borked_line,
169942 current_line_position.begin.GetGlobalPosition(requested_size, first_nl),
169943 error_position.GetGlobalPosition(requested_size, first_nl), path);
169944 error_handler.Error(csv_error, true);
169945 } else {
169946 auto csv_error = CSVError::InvalidUTF8(state_machine.options, col_idx, lines_per_batch, borked_line,
169947 current_line_position.begin.GetGlobalPosition(requested_size, first_nl),
169948 error_position.GetGlobalPosition(requested_size), path);
169949 error_handler.Error(csv_error, true);
169950 }
169951}
Here is the call graph for this function:

◆ HandleTooManyColumnsError()

bool duckdb::StringValueResult::HandleTooManyColumnsError ( const char * value_ptr,
const idx_t size )
169434 {
169435 if (cur_col_id >= number_of_columns) {
169436 if (state_machine.state_machine_options.strict_mode.GetValue()) {
169437 bool error = true;
169438 if (cur_col_id == number_of_columns && ((quoted && state_machine.options.allow_quoted_nulls) || !quoted)) {
169439 // we make an exception if the first over-value is null
169440 bool is_value_null = false;
169441 for (idx_t i = 0; i < null_str_count; i++) {
169442 is_value_null = is_value_null || IsValueNull(null_str_ptr[i], value_ptr, size);
169443 }
169444 error = !is_value_null;
169445 }
169446 if (error) {
169447 // We error pointing to the current value error.
169448 current_errors.Insert(TOO_MANY_COLUMNS, cur_col_id, chunk_col_id, last_position);
169449 cur_col_id++;
169450 }
169451 // We had an error
169452 return true;
169453 }
169454 used_unstrictness = true;
169455 }
169456 return false;
169457}
bool quoted
Variable to keep information regarding quoted and escaped values.
Definition duckdb.cpp:167220
@ TOO_MANY_COLUMNS
If the CSV has too few columns.
Definition duckdb.cpp:166188

◆ AddValueToVector()

void duckdb::StringValueResult::AddValueToVector ( const char * value_ptr,
idx_t size,
bool allocate = false )
inline
169509 {
169510 if (HandleTooManyColumnsError(value_ptr, size)) {
169511 return;
169512 }
169513 if (cur_col_id >= number_of_columns) {
169514 if (!state_machine.state_machine_options.strict_mode.GetValue()) {
169515 used_unstrictness = true;
169516 return;
169517 }
169518 bool error = true;
169519 if (cur_col_id == number_of_columns && ((quoted && state_machine.options.allow_quoted_nulls) || !quoted)) {
169520 // we make an exception if the first over-value is null
169521 bool is_value_null = false;
169522 for (idx_t i = 0; i < null_str_count; i++) {
169523 is_value_null = is_value_null || IsValueNull(null_str_ptr[i], value_ptr, size);
169524 }
169525 error = !is_value_null;
169526 }
169527 if (error) {
169528 // We error pointing to the current value error.
169529 current_errors.Insert(TOO_MANY_COLUMNS, cur_col_id, chunk_col_id, last_position);
169530 cur_col_id++;
169531 }
169532 return;
169533 }
169534
169535 if (projecting_columns) {
169536 if (!projected_columns[cur_col_id]) {
169537 cur_col_id++;
169538 return;
169539 }
169540 }
169541
169542 if (((quoted && state_machine.options.allow_quoted_nulls) || !quoted)) {
169543 // Check for the occurrence of escaped null string like \N only if strict_mode is disabled
169544 const bool check_unquoted_escaped_null =
169545 state_machine.state_machine_options.strict_mode.GetValue() == false && escaped && !quoted && size == 1;
169546 for (idx_t i = 0; i < null_str_count; i++) {
169547 bool is_null = false;
169548 if (null_str_size[i] == 2 && null_str_ptr[i][0] == state_machine.state_machine_options.escape.GetValue()) {
169549 is_null = check_unquoted_escaped_null && null_str_ptr[i][1] == value_ptr[0];
169550 } else if (size == null_str_size[i] && !check_unquoted_escaped_null) {
169551 is_null = IsValueNull(null_str_ptr[i], value_ptr, size);
169552 }
169553 if (is_null) {
169554 bool empty = false;
169555 if (chunk_col_id < state_machine.options.force_not_null.size()) {
169556 empty = state_machine.options.force_not_null[chunk_col_id];
169557 }
169558 if (empty) {
169559 if (parse_types[chunk_col_id].type_id != LogicalTypeId::VARCHAR) {
169560 // If it is not a varchar, empty values are not accepted, we must error.
169561 current_errors.Insert(CAST_ERROR, cur_col_id, chunk_col_id, last_position);
169562 } else {
169563 static_cast<string_t *>(vector_ptr[chunk_col_id])[number_of_rows] = string_t();
169564 }
169565 } else {
169566 if (chunk_col_id == number_of_columns) {
169567 // We check for a weird case, where we ignore an extra value, if it is a null value
169568 return;
169569 }
169570 validity_mask[chunk_col_id]->SetInvalid(static_cast<idx_t>(number_of_rows));
169571 }
169572 cur_col_id++;
169573 chunk_col_id++;
169574 return;
169575 }
169576 }
169577 }
169578 bool success = true;
169579 string strip_thousands;
169580 if (LogicalType::IsNumeric(parse_types[chunk_col_id].type_id) &&
169581 state_machine.options.thousands_separator != '\0') {
169582 // If we have a thousands separator we should try to use that
169583 strip_thousands = BaseScanner::RemoveSeparator(value_ptr, size, state_machine.options.thousands_separator);
169584 value_ptr = strip_thousands.c_str();
169585 size = strip_thousands.size();
169586 }
169587 switch (parse_types[chunk_col_id].type_id) {
169588 case LogicalTypeId::BOOLEAN:
169589 success =
169590 TryCastStringBool(value_ptr, size, static_cast<bool *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169591 break;
169592 case LogicalTypeId::TINYINT:
169593 success = TrySimpleIntegerCast(value_ptr, size, static_cast<int8_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169594 false);
169595 break;
169596 case LogicalTypeId::SMALLINT:
169597 success = TrySimpleIntegerCast(value_ptr, size,
169598 static_cast<int16_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169599 break;
169600 case LogicalTypeId::INTEGER:
169601 success = TrySimpleIntegerCast(value_ptr, size,
169602 static_cast<int32_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169603 break;
169604 case LogicalTypeId::BIGINT:
169605 success = TrySimpleIntegerCast(value_ptr, size,
169606 static_cast<int64_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169607 break;
169608 case LogicalTypeId::UTINYINT:
169609 success = TrySimpleIntegerCast<uint8_t, false>(
169610 value_ptr, size, static_cast<uint8_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169611 break;
169612 case LogicalTypeId::USMALLINT:
169613 success = TrySimpleIntegerCast<uint16_t, false>(
169614 value_ptr, size, static_cast<uint16_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169615 break;
169616 case LogicalTypeId::UINTEGER:
169617 success = TrySimpleIntegerCast<uint32_t, false>(
169618 value_ptr, size, static_cast<uint32_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169619 break;
169620 case LogicalTypeId::UBIGINT:
169621 success = TrySimpleIntegerCast<uint64_t, false>(
169622 value_ptr, size, static_cast<uint64_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169623 break;
169624 case LogicalTypeId::DOUBLE:
169625 success =
169626 TryDoubleCast<double>(value_ptr, size, static_cast<double *>(vector_ptr[chunk_col_id])[number_of_rows],
169627 false, state_machine.options.decimal_separator[0]);
169628 break;
169629 case LogicalTypeId::FLOAT:
169630 success = TryDoubleCast<float>(value_ptr, size, static_cast<float *>(vector_ptr[chunk_col_id])[number_of_rows],
169631 false, state_machine.options.decimal_separator[0]);
169632 break;
169633 case LogicalTypeId::DATE: {
169634 if (!date_format.Empty()) {
169635 success = date_format.TryParseDate(value_ptr, size,
169636 static_cast<date_t *>(vector_ptr[chunk_col_id])[number_of_rows]);
169637 } else {
169638 idx_t pos;
169639 bool special;
169640 success = Date::TryConvertDate(value_ptr, size, pos,
169641 static_cast<date_t *>(vector_ptr[chunk_col_id])[number_of_rows], special,
169642 false) == DateCastResult::SUCCESS;
169643 }
169644 break;
169645 }
169646 case LogicalTypeId::TIME: {
169647 idx_t pos;
169648 success = Time::TryConvertTime(value_ptr, size, pos,
169649 static_cast<dtime_t *>(vector_ptr[chunk_col_id])[number_of_rows], false);
169650 break;
169651 }
169652 case LogicalTypeId::TIMESTAMP:
169653 case LogicalTypeId::TIMESTAMP_TZ: {
169654 if (!timestamp_format.Empty()) {
169655 success = timestamp_format.TryParseTimestamp(
169656 value_ptr, size, static_cast<timestamp_t *>(vector_ptr[chunk_col_id])[number_of_rows]);
169657 } else {
169658 const bool use_offset = (parse_types[chunk_col_id].type_id == LogicalTypeId::TIMESTAMP_TZ);
169660 value_ptr, size, static_cast<timestamp_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169661 use_offset) == TimestampCastResult::SUCCESS;
169662 }
169663 break;
169664 }
169665 case LogicalTypeId::DECIMAL: {
169666 if (decimal_separator == ',') {
169667 switch (parse_types[chunk_col_id].internal_type) {
169668 case PhysicalType::INT16:
169669 success = TryDecimalStringCast<int16_t, ','>(
169670 value_ptr, size, static_cast<int16_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169671 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169672 break;
169673 case PhysicalType::INT32:
169674 success = TryDecimalStringCast<int32_t, ','>(
169675 value_ptr, size, static_cast<int32_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169676 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169677 break;
169678 case PhysicalType::INT64:
169679 success = TryDecimalStringCast<int64_t, ','>(
169680 value_ptr, size, static_cast<int64_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169681 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169682 break;
169683 case PhysicalType::INT128:
169684 success = TryDecimalStringCast<hugeint_t, ','>(
169685 value_ptr, size, static_cast<hugeint_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169686 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169687 break;
169688 default:
169689 throw InternalException("Invalid Physical Type for Decimal Value. Physical Type: " +
169690 TypeIdToString(parse_types[chunk_col_id].internal_type));
169691 }
169692
169693 } else if (decimal_separator == '.') {
169694 switch (parse_types[chunk_col_id].internal_type) {
169695 case PhysicalType::INT16:
169696 success = TryDecimalStringCast(value_ptr, size,
169697 static_cast<int16_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169698 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169699 break;
169700 case PhysicalType::INT32:
169701 success = TryDecimalStringCast(value_ptr, size,
169702 static_cast<int32_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169703 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169704 break;
169705 case PhysicalType::INT64:
169706 success = TryDecimalStringCast(value_ptr, size,
169707 static_cast<int64_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169708 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169709 break;
169710 case PhysicalType::INT128:
169711 success = TryDecimalStringCast(value_ptr, size,
169712 static_cast<hugeint_t *>(vector_ptr[chunk_col_id])[number_of_rows],
169713 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169714 break;
169715 default:
169716 throw InternalException("Invalid Physical Type for Decimal Value. Physical Type: " +
169717 TypeIdToString(parse_types[chunk_col_id].internal_type));
169718 }
169719 } else {
169720 throw InvalidInputException("Decimals can only have ',' and '.' as decimal separators");
169721 }
169722 break;
169723 }
169724 default: {
169725 // By default, we add a string
169726 // We only evaluate if a string is utf8 valid, if it's actually a varchar
169727 if (parse_types[chunk_col_id].validate_utf8 &&
169728 !Utf8Proc::IsValid(value_ptr, UnsafeNumericCast<uint32_t>(size))) {
169729 bool force_error = !state_machine.options.ignore_errors.GetValue() && sniffing;
169730 // Invalid unicode, we must error
169731 if (force_error) {
169732 HandleUnicodeError(cur_col_id, last_position);
169733 }
169734 // If we got here, we are ignoring errors, hence we must ignore this line.
169735 current_errors.Insert(INVALID_ENCODING, cur_col_id, chunk_col_id, last_position);
169736 static_cast<string_t *>(vector_ptr[chunk_col_id])[number_of_rows] = StringVector::AddStringOrBlob(
169737 parse_chunk.data[chunk_col_id], string_t(value_ptr, UnsafeNumericCast<uint32_t>(0)));
169738 break;
169739 }
169740 if (allocate) {
169741 // If it's a value produced over multiple buffers, we must allocate
169742 static_cast<string_t *>(vector_ptr[chunk_col_id])[number_of_rows] = StringVector::AddStringOrBlob(
169743 parse_chunk.data[chunk_col_id], string_t(value_ptr, UnsafeNumericCast<uint32_t>(size)));
169744 } else {
169745 static_cast<string_t *>(vector_ptr[chunk_col_id])[number_of_rows] =
169746 string_t(value_ptr, UnsafeNumericCast<uint32_t>(size));
169747 }
169748 break;
169749 }
169750 }
169751 if (!success) {
169752 current_errors.Insert(CAST_ERROR, cur_col_id, chunk_col_id, last_position);
169753 if (!state_machine.options.IgnoreErrors()) {
169754 // We have to write the cast error message.
169755 std::ostringstream error;
169756 // Casting Error Message
169757 error << "Could not convert string \"" << std::string(value_ptr, size) << "\" to \'"
169758 << LogicalTypeIdToString(parse_types[chunk_col_id].type_id) << "\'";
169759 auto error_string = error.str();
169760 FullLinePosition::SanitizeError(error_string);
169761
169762 current_errors.ModifyErrorMessageOfLastError(error_string);
169763 }
169764 }
169765 cur_col_id++;
169766 chunk_col_id++;
169767}
static string RemoveSeparator(const char *value_ptr, const idx_t size, char thousands_separator)
Removes thousands separator.
Definition duckdb.cpp:168369
static DUCKDB_API DateCastResult TryConvertDate(const char *buf, idx_t len, idx_t &pos, date_t &result, bool &special, bool strict=false)
Definition duckdb.cpp:117363
bool escaped
If the current value has been escaped.
Definition duckdb.cpp:167224
void HandleUnicodeError(idx_t col_idx, LinePosition &error_position)
Force the throw of a Unicode error.
Definition duckdb.cpp:169936
static DUCKDB_API TimestampCastResult TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result, const bool use_offset, optional_ptr< int32_t > nanos=nullptr, bool strict=false)
Strict Timestamp does not accept offsets.
Definition duckdb.cpp:129558
static bool IsValid(const char *s, size_t len)
Returns whether or not the UTF8 string is valid.
Definition duckdb.cpp:507383
::int64_t int64_t
::int8_t int8_t
::uint32_t uint32_t
::uint8_t uint8_t
::uint64_t uint64_t
::uint16_t uint16_t
::int32_t int32_t
::int16_t int16_t
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ INVALID_ENCODING
If the null_padding option is set, and we have quoted new values in parallel.
Definition duckdb.cpp:166193
static DUCKDB_API string_t AddStringOrBlob(Vector &vector, const char *data, idx_t len)
Definition duckdb.cpp:137893

◆ SetComment()

void duckdb::StringValueResult::SetComment ( StringValueResult & result,
idx_t buffer_pos )
inlinestatic
169459 {
169460 if (!result.comment) {
169461 result.position_before_comment = buffer_pos;
169462 result.comment = true;
169463 }
169464}

◆ UnsetComment()

bool duckdb::StringValueResult::UnsetComment ( StringValueResult & result,
idx_t buffer_pos )
inlinestatic
169466 {
169467 bool done = false;
169468 if (result.last_position.buffer_pos < result.position_before_comment) {
169469 bool all_empty = true;
169470 for (idx_t i = result.last_position.buffer_pos; i < result.position_before_comment; i++) {
169471 if (result.buffer_ptr[i] != ' ') {
169472 all_empty = false;
169473 break;
169474 }
169475 }
169476 if (!all_empty) {
169477 done = AddRow(result, result.position_before_comment);
169478 }
169479 } else {
169480 if (result.cur_col_id != 0) {
169481 done = AddRow(result, result.position_before_comment);
169482 }
169483 }
169484 if (result.number_of_rows == 0) {
169485 result.first_line_is_comment = true;
169486 }
169487 result.comment = false;
169488 if (result.state_machine.dialect_options.state_machine_options.new_line.GetValue() != NewLineIdentifier::CARRY_ON) {
169489 result.last_position.buffer_pos = buffer_pos + 1;
169490 } else {
169491 result.last_position.buffer_pos = buffer_pos + 2;
169492 }
169493 LinePosition current_line_start = {result.iterator.pos.buffer_idx, result.iterator.pos.buffer_pos,
169494 result.buffer_size};
169495 result.current_line_position.begin = result.current_line_position.end;
169496 result.current_line_position.end = current_line_start;
169497 result.cur_col_id = 0;
169498 result.chunk_col_id = 0;
169499 return done;
169500}
static bool AddRow(StringValueResult &result, const idx_t buffer_pos)
Adds a Row to the result.
Definition duckdb.cpp:170199

◆ HandleMultiDelimiter()

idx_t duckdb::StringValueResult::HandleMultiDelimiter ( const idx_t buffer_pos) const
inline
169903 {
169904 idx_t size = buffer_pos - last_position.buffer_pos - extra_delimiter_bytes;
169905 if (buffer_pos < last_position.buffer_pos + extra_delimiter_bytes) {
169906 // If this is a scenario where the value is null, that is fine (e.g., delim = '||' and line is: A||)
169907 if (buffer_pos == last_position.buffer_pos) {
169908 size = 0;
169909 } else {
169910 // Otherwise something went wrong.
169911 throw InternalException(
169912 "Value size is lower than the number of extra delimiter bytes in the HandleMultiDelimiter(). "
169913 "buffer_pos = %d, last_position.buffer_pos = %d, extra_delimiter_bytes = %d",
169914 buffer_pos, last_position.buffer_pos, extra_delimiter_bytes);
169915 }
169916 }
169917 return size;
169918}

◆ ToChunk()

DataChunk & duckdb::StringValueResult::ToChunk ( )
169769 {
169770 if (number_of_rows < 0) {
169771 throw InternalException("CSVScanner: ToChunk() function. Has a negative number of rows, this indicates an "
169772 "issue with the error handler.");
169773 }
169774 parse_chunk.SetCardinality(static_cast<idx_t>(number_of_rows));
169775 return parse_chunk;
169776}

◆ Reset()

void duckdb::StringValueResult::Reset ( )

Resets the state of the result.

169778 {
169779 if (number_of_rows == 0) {
169780 return;
169781 }
169782 number_of_rows = 0;
169783 cur_col_id = 0;
169784 chunk_col_id = 0;
169785 for (auto &v : validity_mask) {
169786 v->SetAllValid(result_size);
169787 }
169788 // We keep a reference to the buffer from our current iteration if it already exists
169789 shared_ptr<CSVBufferHandle> cur_buffer;
169790 auto handle_iter = buffer_handles.find(iterator.GetBufferIdx());
169791 if (handle_iter != buffer_handles.end()) {
169792 cur_buffer = handle_iter->second;
169793 }
169794 buffer_handles.clear();
169795 idx_t actual_size = 0;
169796 if (cur_buffer) {
169797 buffer_handles[cur_buffer->buffer_idx] = cur_buffer;
169798 actual_size = cur_buffer->actual_size;
169799 }
169800 current_errors.Reset();
169801 borked_rows.clear();
169802 current_line_position.begin = {iterator.pos.buffer_idx, iterator.pos.buffer_pos, actual_size};
169804}
uint32_t v
Here is the caller graph for this function:

◆ SkipBOM()

void duckdb::StringValueResult::SkipBOM ( ) const

BOM skipping (https://en.wikipedia.org/wiki/Byte_order_mark).

170939 {
170940 StringUtil::SkipBOM(buffer_ptr, buffer_size, iterator.pos.buffer_pos);
170941}
static DUCKDB_API void SkipBOM(const char *buffer_ptr, const idx_t &buffer_size, idx_t &buffer_pos)
BOM skipping (https://en.wikipedia.org/wiki/Byte_order_mark).
Definition duckdb.cpp:110287
Here is the call graph for this function:

◆ PrintErrorLine()

bool duckdb::StringValueResult::PrintErrorLine ( ) const

If we should Print Error Lines We only really care about error lines if we are going to error or store them in a rejects table

170954 {
170955 // To print a lint, result size must be different, than one (i.e., this is a SetStart() trying to figure out new
170956 // lines) And must either not be ignoring errors OR must be storing them in a rejects table.
170957 return result_size != 1 &&
170958 (state_machine.options.store_rejects.GetValue() || !state_machine.options.ignore_errors.GetValue());
170959}
Here is the caller graph for this function:

◆ RemoveLastLine()

void duckdb::StringValueResult::RemoveLastLine ( )

Removes last added line, usually because we figured out later on that it's an ill-formed line or that it does not fit our schema

170943 {
170944 // potentially de-nullify values
170945 for (idx_t i = 0; i < chunk_col_id; i++) {
170946 validity_mask[i]->SetValid(static_cast<idx_t>(number_of_rows));
170947 }
170948 // reset column trackers
170949 cur_col_id = 0;
170950 chunk_col_id = 0;
170951 // decrement row counter
170952 number_of_rows--;
170953}

Member Data Documentation

◆ first_line_is_comment

bool duckdb::StringValueResult::first_line_is_comment = false

Variable used when trying to figure out where a new segment starts, we must always start from a Valid (i.e., non-comment) line.


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