The table inheritance works mostly

When a table has partitions or inheritance children these are listed as subnodes. A subnode can appear multiple times under different parents as postgresql supports inheriting multiple tables.

The sizes are still missing and maybe some things I have note verified yet are not correct.
This commit is contained in:
eelke 2023-01-22 15:57:22 +01:00
parent ccd88d0578
commit 39dbab4d36
17 changed files with 452 additions and 127 deletions

View file

@ -0,0 +1,64 @@
#include <gtest/gtest.h>
#include "PrintTo_Qt.h"
#include "catalog/PgClass.h"
#include "catalog/PgDatabaseCatalog.h"
#include "ui/catalog/tables/TableTreeBuilder.h"
#include "ui/catalog/tables/TableNode.h"
#include "catalog/PgInheritsContainer.h"
TEST(TableTreeBuilder, EmptySourceEmptyResult)
{
std::map<Oid, PgClass> source;
PgDatabaseCatalog catalog;
PgInheritsContainer inherited(catalog);
TableTreeBuilder builder(source, inherited);
auto result = builder.Build();
EXPECT_EQ(result->children.size(), 0);
}
TEST(TableTreeBuilder, TopLevelOnly)
{
std::map<Oid, PgClass> source;
PgDatabaseCatalog catalog;
PgClass cls1(catalog, 1000, "a", 11);
source.emplace(1000, cls1);
PgInheritsContainer inherited(catalog);
TableTreeBuilder builder(source, inherited);
auto result = builder.Build();
EXPECT_EQ(result->children.size(), 1);
}
class FakeIFindParents : public IFindParents
{
public:
std::vector<Oid> getParentsOf(Oid oid) const override
{
if (oid == 1001)
return { 1002 };
return {};
}
};
TEST(TableTreeBuilder, WithChild)
{
std::map<Oid, PgClass> source;
FakeIFindParents findParents;
PgDatabaseCatalog catalog;
PgClass cls1(catalog, 1001, "a", 11);
source.emplace(1001, cls1);
PgClass cls2(catalog, 1002, "b", 11);
source.emplace(1002, cls2);
PgInheritsContainer inherited(catalog);
TableTreeBuilder builder(source, findParents);
auto result = builder.Build();
EXPECT_EQ(result->children.size(), 1);
EXPECT_EQ(result->children[0]->children.size(), 1);
EXPECT_TRUE(result->children[0]->children[0]->parent.lock() == result->children[0]);
}

View file

@ -14,6 +14,7 @@ QT += core widgets
HEADERS +=
SOURCES += main.cpp \
TableTreeBuilderTests.cpp \
tst_ConvertLangToSqlString.cpp \
tst_ConvertToMultiLineCString.cpp \
tst_ExplainJsonParser.cpp \