5#include "../DataBinder/SqlRawColumn.hpp"
6#include "../SqlSchema.hpp"
7#include "../SqlServerType.hpp"
8#include "RowIsolation.hpp"
9#include "SqlBackupFormats.hpp"
21namespace Lightweight::detail
30 std::function<std::expected<void, BatchInsertError>(std::span<SqlRawColumn const> slice, std::size_t rowCount)>;
34struct BatchManagerHooks
37 SliceInserter tryInsert;
40 FailureClassifier classify;
46 std::function<void(std::size_t rowInManager, std::string_view sqlState, std::string_view message, std::string sampleKey)>
51 std::function<void(std::string_view column, std::string_view reason)> onCellNulled;
54 std::function<void(std::size_t settledRows)> onSettled;
59 #pragma warning(disable : 4251)
63struct LIGHTWEIGHT_API BatchManager
73 explicit BatchManager(BatchManagerHooks hooks,
74 std::vector<SqlColumnDeclaration>
const& colDecls,
76 SqlServerType serverType = SqlServerType::UNKNOWN,
77 SqlServerType sourceServerType = SqlServerType::UNKNOWN);
81 BatchManager(BatchManager
const&) =
delete;
82 BatchManager& operator=(BatchManager
const&) =
delete;
83 BatchManager(BatchManager&&) noexcept;
84 BatchManager& operator=(BatchManager&&) noexcept;
91 void PushRow(std::vector<SqlBackup::BackupValue> const& row);
95 void PushBatch(SqlBackup::ColumnBatch const& batch);
102 void PushBatch(SqlBackup::ColumnBatch const& batch, std::
size_t skipRows);
114 [[nodiscard]] std::
size_t SettledRows() const noexcept;
117 [[nodiscard]] std::unique_ptr<BatchColumn> CreateColumn(SqlColumnDeclaration const& col) const;
120 void DiscardPendingRows();
128 void PushIntoColumn(
size_t columnIndex,
130 std::function<
void(BatchColumn& column,
size_t first,
size_t count)> const& push);
136 void RecordValueFailure(
size_t columnIndex,
size_t pendingRow, std::string_view reason);
142 [[nodiscard]] std::
string DescribeRowKey(std::vector<SqlRawColumn> const& rawColumns,
size_t row) const;
146 void SkipRows(
size_t count);
153 void ExtendWatermark(
size_t firstRow,
size_t settledEnd);
157 size_t firstPendingRow = 0;
159 size_t settledRows = 0;
160 size_t capacity = 1000;
161 BatchManagerHooks hooks;
163 std::vector<
bool> columnRequired;
165 std::vector<
size_t> keyColumns;
167 std::vector<
bool> excludedRows;
169 std::vector<std::optional<std::
string>> exclusionReasons;
175 size_t pendingRow {};
177 size_t columnIndex {};
184 std::vector<NulledCell> nulledCells;
185 std::vector<std::unique_ptr<BatchColumn>> columns;
186 SqlServerType serverType = SqlServerType::UNKNOWN;
188 SqlServerType sourceServerType = SqlServerType::UNKNOWN;
192 bool trimsFixedCharPadding =
false;
194 bool hasNativeGuidType =
false;
196 std::vector<std::string> columnNames;