Skip to content

Commit

Permalink
feat: dump links
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Mar 21, 2024
1 parent 0b6743d commit 173cf45
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
34 changes: 34 additions & 0 deletions pkg/silo/default_dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2024 CGI France
//
// This file is part of SILO.
//
// SILO is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SILO is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SILO. If not, see <http://www.gnu.org/licenses/>.

package silo

type DumpToStdout struct{}

func NewDumpToStdout() *DumpToStdout {
return &DumpToStdout{}
}

func (d *DumpToStdout) Write(node DataNode, uuid string) error {
println(uuid, node.String())

return nil
}

func (d *DumpToStdout) Close() error {
return nil
}
7 changes: 4 additions & 3 deletions pkg/silo/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io"
"strconv"

"github.com/dominikbraun/graph"
)
Expand All @@ -47,13 +48,13 @@ func (d *Driver) Dump() error {
for _, node := range nodes {
nodemap[node.String()] = node

if err := grph.AddVertex(node); err != nil {
if err := grph.AddVertex(node); err != nil && !errors.Is(err, graph.ErrVertexAlreadyExists) {
return fmt.Errorf("%w", err)
}
}

for _, link := range links {
if err := grph.AddEdge(link.E1.String(), link.E2.String()); err != nil {
if err := grph.AddEdge(link.E1.String(), link.E2.String()); err != nil && !errors.Is(err, graph.ErrEdgeAlreadyExists) {
return fmt.Errorf("%w", err)
}
}
Expand All @@ -65,7 +66,7 @@ func (d *Driver) Dump() error {

for key := range nodemap {
err := graph.BFS[string, DataNode](grph, key, func(hash string) bool {
println(count, hash)
_ = d.writer.Write(nodemap[hash], strconv.Itoa(count))

delete(nodemap, hash)

Expand Down
13 changes: 8 additions & 5 deletions pkg/silo/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ func TestNominal(t *testing.T) {
t.Parallel()

rows := []silo.DataRow{
{"ID1": 1, "ID2": "1", "ID3": 1.0, "ID4": "00001"},
{"ID1": 2, "ID2": "2", "ID3": 2.0, "ID4": "00002"},
{"ID1": 1, "ID2": "1", "ID3": 1.10, "ID4": "00001"},
{"ID1": 2, "ID2": "2", "ID3": 2.20, "ID4": "00002"},
}
input := silo.NewDataRowReaderInMemory(rows)

backend := silo.NewBackendInMemory()
driver := silo.NewDriver(backend, nil)
writer := silo.NewDumpToStdout()
driver := silo.NewDriver(backend, writer)

err := driver.Scan(input)
require.NoError(t, err)
Expand All @@ -61,7 +62,8 @@ func TestPartialNull(t *testing.T) {
input := silo.NewDataRowReaderInMemory(rows)

backend := silo.NewBackendInMemory()
driver := silo.NewDriver(backend, nil)
writer := silo.NewDumpToStdout()
driver := silo.NewDriver(backend, writer)

err := driver.Scan(input)
require.NoError(t, err)
Expand All @@ -87,7 +89,8 @@ func TestPartialMissing(t *testing.T) {
input := silo.NewDataRowReaderInMemory(rows)

backend := silo.NewBackendInMemory()
driver := silo.NewDriver(backend, nil)
writer := silo.NewDumpToStdout()
driver := silo.NewDriver(backend, writer)

err := driver.Scan(input)
require.NoError(t, err)
Expand Down

0 comments on commit 173cf45

Please sign in to comment.