From d8f493426878254f81e4a0058c514b77fe7f28e9 Mon Sep 17 00:00:00 2001 From: Nicola Cabiddu Date: Wed, 20 Mar 2024 18:56:07 +0000 Subject: [PATCH] initial support collection in mixed --- src/realm/bplustree.cpp | 23 +++++++++++++++++++++-- src/realm/cluster.cpp | 12 +++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/realm/bplustree.cpp b/src/realm/bplustree.cpp index 2ebb9097ea8..c381d978093 100644 --- a/src/realm/bplustree.cpp +++ b/src/realm/bplustree.cpp @@ -867,8 +867,27 @@ ref_type BPlusTreeBase::typed_write(ref_type ref, _impl::ArrayWriterBase& out, A } else { if (node.has_refs()) { - // this should be extended to handle Mixed.... - return node.write(out, deep, only_modified, false); // unknown substructure, don't compress + // TODO: handle collection in mixed here. This is breaking.. + Array written_node(Allocator::get_default()); + written_node.create(NodeHeader::type_InnerBptreeNode, false, node.size()); + for (unsigned j = 0; j < node.size(); ++j) { + RefOrTagged rot = node.get_as_ref_or_tagged(j); + if (rot.is_ref() && rot.get_as_ref()) { + // it should/could only be a nested collection + compress = true; + written_node.set_as_ref(j, BPlusTreeBase::typed_write(rot.get_as_ref(), out, alloc, col_type, + deep, only_modified, compress)); + } + else { + Array a(alloc); + a.init_from_ref(rot.get_as_ref()); + written_node.set_as_ref(j, a.write(out, deep, only_modified, false)); + } + } + auto written_ref = written_node.write(out, false, false, false); + written_node.destroy(); + return written_ref; + // return node.write(out, deep, only_modified, false); // unknown substructure, don't compress } else { return node.write(out, false, only_modified, compress); // leaf array - do compress diff --git a/src/realm/cluster.cpp b/src/realm/cluster.cpp index 404bcf8fdf1..d940e870cd0 100644 --- a/src/realm/cluster.cpp +++ b/src/realm/cluster.cpp @@ -1678,7 +1678,17 @@ ref_type Cluster::typed_write(ref_type ref, _impl::ArrayWriterBase& out, const T const auto do_compress = (i < 3) ? true : false; if (i == 4) { - // TODO: handle collections in mixed + // TODO this is not working... + bool compress = true; + auto bptree_rot = leaf.get_as_ref_or_tagged(i); + if (bptree_rot.is_ref() && bptree_rot.get_as_ref()) { + written_leaf.set_as_ref(i, BPlusTreeBase::typed_write(bptree_rot.get_as_ref(), out, + m_alloc, col_type, deep, + only_modified, compress)); + } + else { + written_leaf.set(i, bptree_rot); + } } // compress only mixed arrays that are integers. skip all the rest for now. written_leaf.set_as_ref(