Kùzu C++ API
Loading...
Searching...
No Matches
copy_from_error.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <variant>
5#include <vector>
6
7#include "api.h"
8#include "constants.h"
9#include "type_utils.h"
10#include "types.h"
11#include "value.h"
12
13namespace kuzu {
14namespace common {
15class ValueVector;
16}
17namespace storage {
18class ColumnChunkData;
19}
20
21namespace processor {
22
23template<typename T>
24concept DataSource =
25 std::same_as<storage::ColumnChunkData, T> || std::same_as<common::ValueVector, T>;
26
28 // we should stick to integral types here as each value essentially adds a column to the output
29 // when reading from a file
30 using DataType = std::variant<uint64_t, uint32_t>;
31
32 static constexpr size_t BLOCK_IDX_IDX = 0;
33 static constexpr size_t OFFSET_IN_BLOCK_IDX = 1;
34 static constexpr size_t NUM_BLOCK_VALUES = 2;
35
37 explicit WarningSourceData(uint64_t numSourceSpecificValues);
38
39 template<std::integral... Types>
40 void dumpTo(uint64_t& blockIdx, uint32_t& offsetInBlock, Types&... vars) const;
41
42 template<std::integral... Types>
43 static WarningSourceData constructFrom(uint64_t blockIdx, uint32_t offsetInBlock,
44 Types... newValues);
45
46 uint64_t getBlockIdx() const;
47 uint32_t getOffsetInBlock() const;
48
49 template<DataSource T>
50 static WarningSourceData constructFromData(const std::vector<T*>& chunks, common::idx_t pos);
51
52 std::array<DataType, common::CopyConstants::MAX_NUM_WARNING_DATA_COLUMNS> values;
53 uint64_t numValues;
54};
55
58 uint64_t endByteOffset;
59
61
62 void setNewLine(uint64_t start);
63 void setEndOfLine(uint64_t end);
64};
65
66// If parsing in parallel during parsing we may not be able to determine line numbers
67// Thus we have additional fields that can be used to determine line numbers + reconstruct lines
68// After parsing this will be used to populate a PopulatedCopyFromError instance
70 CopyFromFileError(std::string message, WarningSourceData warningData, bool completedLine = true,
71 bool mustThrow = false);
72
73 std::string message;
76
78
79 bool operator<(const CopyFromFileError& o) const;
80};
81
83 std::string message;
84 std::string filePath;
86 uint64_t lineNumber;
87};
88
89template<std::integral... Types>
90void WarningSourceData::dumpTo(uint64_t& blockIdx, uint32_t& offsetInBlock, Types&... vars) const {
91 static_assert(sizeof...(Types) + NUM_BLOCK_VALUES <= std::tuple_size_v<decltype(values)>);
92 KU_ASSERT(sizeof...(Types) + NUM_BLOCK_VALUES == numValues);
94 [this](auto idx, auto& value) {
95 value = std::get<std::decay_t<decltype(value)>>(values[idx]);
96 },
97 blockIdx, offsetInBlock, vars...);
98}
99
100template<std::integral... Types>
101WarningSourceData WarningSourceData::constructFrom(uint64_t blockIdx, uint32_t offsetInBlock,
102 Types... newValues) {
103 static_assert(sizeof...(Types) + NUM_BLOCK_VALUES <= std::tuple_size_v<decltype(values)>,
104 "For performance reasons the number of warning metadata columns has a "
105 "statically-defined limit, modify "
106 "'common::CopyConstants::WARNING_DATA_MAX_NUM_COLUMNS' if you wish to increase it.");
107
108 WarningSourceData ret{sizeof...(Types) + NUM_BLOCK_VALUES};
109 common::TypeUtils::paramPackForEach([&ret](auto idx, auto value) { ret.values[idx] = value; },
110 blockIdx, offsetInBlock, newValues...);
111 return ret;
112}
113
114} // namespace processor
115} // namespace kuzu
#define KUZU_API
Definition api.h:25
#define KU_ASSERT(condition)
Definition assert.h:19
static void paramPackForEach(const Func &func, Types &&... values)
Definition type_utils.h:35
Definition copy_from_error.h:24
uint32_t idx_t
Definition types.h:44
Definition array_utils.h:7
Definition copy_from_error.h:69
std::string message
Definition copy_from_error.h:73
bool mustThrow
Definition copy_from_error.h:77
bool operator<(const CopyFromFileError &o) const
WarningSourceData warningData
Definition copy_from_error.h:75
bool completedLine
Definition copy_from_error.h:74
CopyFromFileError(std::string message, WarningSourceData warningData, bool completedLine=true, bool mustThrow=false)
Definition copy_from_error.h:56
void setNewLine(uint64_t start)
void setEndOfLine(uint64_t end)
bool isCompleteLine
Definition copy_from_error.h:60
uint64_t startByteOffset
Definition copy_from_error.h:57
uint64_t endByteOffset
Definition copy_from_error.h:58
Definition copy_from_error.h:82
std::string skippedLineOrRecord
Definition copy_from_error.h:85
std::string message
Definition copy_from_error.h:83
uint64_t lineNumber
Definition copy_from_error.h:86
std::string filePath
Definition copy_from_error.h:84
Definition copy_from_error.h:27
void dumpTo(uint64_t &blockIdx, uint32_t &offsetInBlock, Types &... vars) const
Definition copy_from_error.h:90
static constexpr size_t NUM_BLOCK_VALUES
Definition copy_from_error.h:34
static WarningSourceData constructFromData(const std::vector< T * > &chunks, common::idx_t pos)
WarningSourceData()
Definition copy_from_error.h:36
static WarningSourceData constructFrom(uint64_t blockIdx, uint32_t offsetInBlock, Types... newValues)
Definition copy_from_error.h:101
uint64_t numValues
Definition copy_from_error.h:53
WarningSourceData(uint64_t numSourceSpecificValues)
std::variant< uint64_t, uint32_t > DataType
Definition copy_from_error.h:30
std::array< DataType, common::CopyConstants::MAX_NUM_WARNING_DATA_COLUMNS > values
Definition copy_from_error.h:52