Skip to content

Commit 7c6863c

Browse files
authored
Merge pull request #459 from IntersectMBO/mheinzel/add-normal-union
Add table union to normal API
2 parents 01b734f + 395e3c1 commit 7c6863c

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/Database/LSMTree/Monoidal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ duplicate (Internal.MonoidalTable t) = Internal.MonoidalTable <$> Internal.dupli
669669
-> IO (Table IO k v) #-}
670670
-- | Union two full tables, creating a new table.
671671
--
672-
-- A good mental model of this operation is @'Data.Map.unionWith' (<>)@ on
673-
-- @'Data.Map.Map' k v@.
672+
-- A good mental model of this operation is @'Data.Map.Lazy.unionWith' (<>)@ on
673+
-- @'Data.Map.Lazy.Map' k v@.
674674
--
675675
-- Multiple tables of the same type but with different configuration parameters
676676
-- can live in the same session. However, 'union' only works for tables that

src/Database/LSMTree/Normal.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ module Database.LSMTree.Normal (
101101
-- * Persistence
102102
, duplicate
103103

104+
-- * Table union
105+
, union
106+
104107
-- * Concurrency #concurrency#
105108
-- $concurrency
106109

@@ -778,3 +781,29 @@ duplicate ::
778781
=> Table m k v blob
779782
-> m (Table m k v blob)
780783
duplicate (Internal.NormalTable t) = Internal.NormalTable <$!> Internal.duplicate t
784+
785+
{-------------------------------------------------------------------------------
786+
Table union
787+
-------------------------------------------------------------------------------}
788+
789+
{-# SPECIALISE union ::
790+
Table IO k v blob
791+
-> Table IO k v blob
792+
-> IO (Table IO k v blob) #-}
793+
-- | Union two full tables, creating a new table.
794+
--
795+
-- A good mental model of this operation is @'Data.Map.Lazy.union'@ on
796+
-- @'Data.Map.Lazy.Map' k v@.
797+
--
798+
-- Multiple tables of the same type but with different configuration parameters
799+
-- can live in the same session. However, 'union' only works for tables that
800+
-- have the same key\/value types and configuration parameters.
801+
--
802+
-- NOTE: unioning tables creates a new table, but does not close the tables that
803+
-- were used as inputs.
804+
union :: forall m k v blob.
805+
IOLike m
806+
=> Table m k v blob
807+
-> Table m k v blob
808+
-> m (Table m k v blob)
809+
union = undefined

test/Database/LSMTree/Class/Normal.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ class (IsSession (Session h)) => IsTable h where
211211
=> h m k v blob
212212
-> m (h m k v blob)
213213

214+
union ::
215+
( IOLike m
216+
, SerialiseValue v
217+
, C k v blob
218+
)
219+
=> h m k v blob
220+
-> h m k v blob
221+
-> m (h m k v blob)
222+
214223
withTableNew :: forall h m k v blob a.
215224
( IOLike m
216225
, IsTable h
@@ -296,3 +305,4 @@ instance IsTable R.Table where
296305
open sesh snap = R.open sesh R.configNoOverride snap
297306

298307
duplicate = R.duplicate
308+
union = R.union

test/Database/LSMTree/Model/IO/Normal.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ instance Class.IsTable Table where
9191

9292
duplicate (Table s t) = Table s <$> runInOpenSession s (Model.duplicate t)
9393

94+
union (Table s1 t1) (Table _s2 t2) =
95+
Table s1 <$> runInOpenSession s1 (Model.union Model.noResolve t1 t2)
96+
9497
convLookupResult :: Model.LookupResult v b -> Class.LookupResult v b
9598
convLookupResult = \case
9699
Model.NotFound -> Class.NotFound

0 commit comments

Comments
 (0)