Core/DataStores: Add a bit more info to db2 file loader sign check assertions

This commit is contained in:
Shauren
2021-11-04 22:27:28 +01:00
parent 5c8a058120
commit 270db9a352

View File

@@ -183,6 +183,7 @@ public:
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;
@@ -223,6 +224,7 @@ public:
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);
@@ -282,6 +284,7 @@ public:
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);
@@ -960,6 +963,39 @@ bool DB2FileLoaderRegularImpl::IsSignedField(uint32 field) const
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:
ASSERT(false, "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),
@@ -1564,6 +1600,16 @@ bool DB2FileLoaderSparseImpl::IsSignedField(uint32 field) const
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)
{
@@ -1949,7 +1995,9 @@ void DB2FileLoader::Load(DB2FileSource* source, DB2FileLoadInfo const* loadInfo)
for (uint32 f = 0; f < loadInfo->Meta->FieldCount; ++f)
{
ASSERT(loadInfo->Fields[fieldIndex].IsSigned == _impl->IsSignedField(f),
"Field %s in %s must be %s", loadInfo->Fields[fieldIndex].Name, source->GetFileName(), _impl->IsSignedField(f) ? "signed" : "unsigned");
"Field %s in %s must be %s%s", loadInfo->Fields[fieldIndex].Name, source->GetFileName(), _impl->IsSignedField(f) ? "signed" : "unsigned",
_impl->GetExpectedSignMismatchReason(f));
fieldIndex += loadInfo->Meta->Fields[f].ArraySize;
}
}