diff options
Diffstat (limited to 'src/common/DataStores/DB2FileLoader.cpp')
-rw-r--r-- | src/common/DataStores/DB2FileLoader.cpp | 104 |
1 files changed, 14 insertions, 90 deletions
diff --git a/src/common/DataStores/DB2FileLoader.cpp b/src/common/DataStores/DB2FileLoader.cpp index 7a586178794..a0cc609250e 100644 --- a/src/common/DataStores/DB2FileLoader.cpp +++ b/src/common/DataStores/DB2FileLoader.cpp @@ -20,6 +20,7 @@ #include "DB2Meta.h" #include "Errors.h" #include "Log.h" +#include <fmt/ranges.h> #include <limits> #include <sstream> #include <system_error> @@ -182,8 +183,6 @@ public: virtual uint32 GetMaxId() const = 0; virtual DB2FileLoadInfo const* GetLoadInfo() const = 0; virtual DB2SectionHeader& GetSection(uint32 section) const = 0; - virtual bool IsSignedField(uint32 field) const = 0; - virtual char const* GetExpectedSignMismatchReason(uint32 field) const = 0; private: friend class DB2Record; @@ -229,8 +228,6 @@ public: uint32 GetMaxId() const override; DB2FileLoadInfo const* GetLoadInfo() const override; DB2SectionHeader& GetSection(uint32 section) const override; - bool IsSignedField(uint32 field) const override; - char const* GetExpectedSignMismatchReason(uint32 field) const override; private: void FillParentLookup(char* dataTable); @@ -295,8 +292,6 @@ public: uint32 GetMaxId() const override; DB2FileLoadInfo const* GetLoadInfo() const override; DB2SectionHeader& GetSection(uint32 section) const override; - bool IsSignedField(uint32 field) const override; - char const* GetExpectedSignMismatchReason(uint32 field) const override; private: void FillParentLookup(char* dataTable); @@ -982,68 +977,6 @@ DB2SectionHeader& DB2FileLoaderRegularImpl::GetSection(uint32 section) const return _sections[section]; } -bool DB2FileLoaderRegularImpl::IsSignedField(uint32 field) const -{ - if (field >= _header->TotalFieldCount) - { - ASSERT(field == _header->TotalFieldCount); - ASSERT(int32(field) == _loadInfo->Meta->ParentIndexField); - return _loadInfo->Meta->IsSignedField(field); - } - - DB2ColumnCompression compressionType = _columnMeta ? _columnMeta[field].CompressionType : DB2ColumnCompression::None; - switch (compressionType) - { - case DB2ColumnCompression::None: - case DB2ColumnCompression::CommonData: - case DB2ColumnCompression::Pallet: - case DB2ColumnCompression::PalletArray: - return _loadInfo->Meta->IsSignedField(field); - case DB2ColumnCompression::SignedImmediate: - return field != uint32(_loadInfo->Meta->IndexField); - case DB2ColumnCompression::Immediate: - return false; - default: - ABORT_MSG("Unhandled compression type %u in %s", uint32(_columnMeta[field].CompressionType), _fileName); - break; - } - - return false; -} - -char const* DB2FileLoaderRegularImpl::GetExpectedSignMismatchReason(uint32 field) const -{ - if (field >= _header->TotalFieldCount) - { - ASSERT(field == _header->TotalFieldCount); - ASSERT(int32(field) == _loadInfo->Meta->ParentIndexField); - return " (ParentIndexField must always be unsigned)"; - } - - DB2ColumnCompression compressionType = _columnMeta ? _columnMeta[field].CompressionType : DB2ColumnCompression::None; - switch (compressionType) - { - case DB2ColumnCompression::None: - case DB2ColumnCompression::CommonData: - case DB2ColumnCompression::Pallet: - case DB2ColumnCompression::PalletArray: - if (int32(field) == _loadInfo->Meta->IndexField) - return " (IndexField must always be unsigned)"; - if (int32(field) == _loadInfo->Meta->ParentIndexField) - return " (ParentIndexField must always be unsigned)"; - return ""; - case DB2ColumnCompression::SignedImmediate: - return " (CompressionType is SignedImmediate)"; - case DB2ColumnCompression::Immediate: - return " (CompressionType is Immediate)"; - default: - ABORT_MSG("Unhandled compression type %u in %s", uint32(_columnMeta[field].CompressionType), _fileName); - break; - } - - return ""; -} - DB2FileLoaderSparseImpl::DB2FileLoaderSparseImpl(char const* fileName, DB2FileLoadInfo const* loadInfo, DB2Header const* header, DB2FileSource* source) : _fileName(fileName), _loadInfo(loadInfo), @@ -1657,22 +1590,6 @@ DB2SectionHeader& DB2FileLoaderSparseImpl::GetSection(uint32 section) const return _sections[section]; } -bool DB2FileLoaderSparseImpl::IsSignedField(uint32 field) const -{ - ASSERT(field < _header->FieldCount); - return _loadInfo->Meta->IsSignedField(field); -} - -char const* DB2FileLoaderSparseImpl::GetExpectedSignMismatchReason(uint32 field) const -{ - ASSERT(field < _header->FieldCount); - if (int32(field) == _loadInfo->Meta->IndexField) - return " (IndexField must always be unsigned)"; - if (int32(field) == _loadInfo->Meta->ParentIndexField) - return " (ParentIndexField must always be unsigned)"; - return ""; -} - DB2Record::DB2Record(DB2FileLoaderImpl const& db2, uint32 recordIndex, std::size_t* fieldOffsets) : _db2(db2), _recordIndex(recordIndex), _recordData(db2.GetRawRecordData(recordIndex, nullptr)), _fieldOffsets(fieldOffsets) { @@ -2076,23 +1993,30 @@ void DB2FileLoader::Load(DB2FileSource* source, DB2FileLoadInfo const* loadInfo) if (loadInfo) { uint32 fieldIndex = 0; - std::string signValidationResult; + std::vector<std::string> signValidationResult; if (!loadInfo->Meta->HasIndexFieldInData()) { if (loadInfo->Fields[0].IsSigned) - signValidationResult += Trinity::StringFormat("ID must be unsigned in {}", source->GetFileName()); + signValidationResult.emplace_back(Trinity::StringFormat("ID must be unsigned in {}", source->GetFileName())); ++fieldIndex; } for (uint32 f = 0; f < loadInfo->Meta->FieldCount; ++f) { - if (loadInfo->Fields[fieldIndex].IsSigned != _impl->IsSignedField(f)) - signValidationResult += Trinity::StringFormat("Field {} in {} must be {}{}", loadInfo->Fields[fieldIndex].Name, - source->GetFileName(), _impl->IsSignedField(f) ? "signed" : "unsigned", _impl->GetExpectedSignMismatchReason(f)); + if (loadInfo->Fields[fieldIndex].IsSigned != loadInfo->Meta->IsSignedField(f)) + { + signValidationResult.emplace_back(Trinity::StringFormat("Field {} in {} must be {}", loadInfo->Fields[fieldIndex].Name, + source->GetFileName(), loadInfo->Meta->IsSignedField(f) ? "signed" : "unsigned")); + + if (int32(f) == loadInfo->Meta->IndexField) + signValidationResult.back() += " (IndexField must always be unsigned)"; + if (int32(f) == loadInfo->Meta->ParentIndexField) + signValidationResult.back() += " (ParentIndexField must always be unsigned)"; + } fieldIndex += loadInfo->Meta->Fields[f].ArraySize; } if (!signValidationResult.empty()) - throw DB2FileLoadException(std::move(signValidationResult)); + throw DB2FileLoadException(Trinity::StringFormat("{}", fmt::join(signValidationResult, "\n"))); } } |