aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-09-27 20:05:36 +0200
committerShauren <shauren.trinity@gmail.com>2024-09-27 20:05:36 +0200
commit89f490bdcdf88c2576c17218926e89b1082ae682 (patch)
tree356a0be852515b56736f21bc60af3649c4153032 /src/common
parentbe04c17916aa35173ed328eb27cb5f246bc8b863 (diff)
Core/DataStores: Removed overriding field sign type based on db2 column compression
Diffstat (limited to 'src/common')
-rw-r--r--src/common/DataStores/DB2FileLoader.cpp104
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")));
}
}