on master help sign in
add simple Relation->CSV conversion
commit8a9ad960e3507797de667adafd892d32a62e0366 authorAgentM <agentm@themactionfaction.com> dateThu 23 Apr 2015, 16:00 (12 years ago) parenteac4071
2 files changed+33−3
ProjectM36/Relation/Show/CSV.hs+23 project-m36.cabal+10−3
ProjectM36/Relation/Show/CSV.hsnew file+23
@@ -0,0 +1,23 @@
1+module ProjectM36.Relation.Show.CSV where
2+import ProjectM36.Base
3+import Data.Csv
4+import qualified Data.Map as M
5+import qualified Data.HashSet as HS
6+import qualified Data.ByteString.Lazy as BS
7+
8+--maybe support a header in the future
9+relationAsCSV :: Relation -> BS.ByteString
10+relationAsCSV (Relation _ tupleSet) = tupleSetAsCSV tupleSet
11+
12+tupleSetAsCSV :: RelationTupleSet -> BS.ByteString
13+tupleSetAsCSV tupleSet = encode $ HS.toList tupleSet
14+
15+instance ToRecord RelationTuple where
16+ toRecord (RelationTuple tupMap) = toRecord $ map toField (M.elems tupMap)
17+
18+instance ToField Atom where
19+ toField (StringAtom atom) = toField atom
20+ toField (IntAtom atom) = toField atom
21+ toField (RelationAtom atom) = undefined -- CSV does not support nested relations- this should likely be detected and rejected
22+
23+
project-m36.cabal+10−3
@@ -7,7 +7,7 @@ Category: Relational Algebra
77Cabal-Version: >= 1.2
88
99Library
10− Build-Depends: base,mtl,containers,unordered-containers,parsec,hashable,haskeline,directory,uuid
10+ Build-Depends: base,mtl,containers,unordered-containers,parsec,hashable,haskeline,directory,uuid,cassava,text,bytestring
1111 Exposed-Modules: ProjectM36.Error,
1212 ProjectM36.Transaction,
1313 ProjectM36.Transaction.Show,
@@ -19,7 +19,8 @@ Library
1919 ProjectM36.RelationalExpression,
2020 ProjectM36.Relation.Show.HTML,
2121 ProjectM36.StaticOptimizer,
22− ProjectM36.Relation.Show.Term
22+ ProjectM36.Relation.Show.Term,
23+ ProjectM36.Relation.Show.CSV
2324 GHC-Options: -Wall
2425
2526Executable tutd
@@ -47,4 +48,10 @@ Test-Suite test-static-optimizer
4748 type: exitcode-stdio-1.0
4849 main-is: test/Relation/StaticOptimizer.hs
4950 Build-Depends: base,HUnit,Cabal
50− GHC-Options: -Wall
51+ GHC-Options: -Wall
52+
53+benchmark bench
54+ type: exitcode-stdio-1.0
55+ main-is: benchmark/Relation.hs
56+ build-depends: base,criterion
57+ GHC-Options: -Wall -rtsopts