aboutsummaryrefslogtreecommitdiffstats
path: root/test/VM.cpp
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-05-19 00:52:15 -0300
committerGitHub <noreply@github.com>2026-05-19 00:52:15 -0300
commit85ed897de3676af866cc619dc700025820c02201 (patch)
treec820e27cca41270c8503847978b537635db9820d /test/VM.cpp
parenta1ad592d31a14c674b9e44ab5fe1fe1358d03707 (diff)
downloadRNT-85ed897de3676af866cc619dc700025820c02201.tar.gz
RNT-85ed897de3676af866cc619dc700025820c02201.zip
VM: Projection instruction
Diffstat (limited to 'test/VM.cpp')
-rw-r--r--test/VM.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/VM.cpp b/test/VM.cpp
index b0a602f..f4ce453 100644
--- a/test/VM.cpp
+++ b/test/VM.cpp
@@ -221,3 +221,43 @@ TEST_CASE("TAKE limits tuples emitted from a SCAN", "[take]")
f.cursors.Close(cursor);
f.handler.Close(handle);
}
+
+TEST_CASE("PROJECT filters tuple attributes by name", "[project]")
+{
+ Fixture f;
+ const std::vector<std::string> path = { "relations", "people" };
+
+ f.objects.Register(path, std::make_unique<nt::ObjectManager::Relation>(), make_relation_type());
+ store_tuple(f.backend, f.objects, path, { { "name", "John" }, { "age", "30" }, { "city", "Lisbon" } });
+
+ auto* handle = f.handler.Open(path, &f.conn);
+ REQUIRE(handle != nullptr);
+ auto* rel = dynamic_cast<nt::ObjectManager::Relation*>(f.objects.Find(path)->object.get());
+ auto* cursor = f.cursors.Open(handle, rel->merkle_root);
+ REQUIRE(cursor != nullptr);
+
+ nt::PlanNode scan;
+ scan.op = nt::PlanNode::Op::SCAN;
+ scan.scan_cursor = cursor;
+
+ nt::PlanNode project;
+ project.op = nt::PlanNode::Op::PROJECT;
+ project.left = &scan;
+ project.project_attrs = { "name", "city" };
+
+ nt::VM vm(f.cursors);
+ nt::Tuple* t = vm.Next(&project);
+ REQUIRE(t != nullptr);
+
+ std::vector<std::string> names;
+ for (const auto& attr : t->attrs()) names.push_back(attr.name);
+
+ REQUIRE(names.size() == 2);
+ REQUIRE(std::find(names.begin(), names.end(), "name") != names.end());
+ REQUIRE(std::find(names.begin(), names.end(), "city") != names.end());
+ REQUIRE(std::find(names.begin(), names.end(), "age") == names.end());
+ REQUIRE(vm.Next(&project) == nullptr);
+
+ f.cursors.Close(cursor);
+ f.handler.Close(handle);
+}