-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbowstring.go
More file actions
52 lines (44 loc) · 1.11 KB
/
Copy pathbowstring.go
File metadata and controls
52 lines (44 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package bow
import (
"fmt"
"strings"
"text/tabwriter"
)
// String returns a formatted representation of the Bow.
func (b *bow) String() string {
if b.NumCols() == 0 {
return ""
}
w := new(tabwriter.Writer)
writer := new(strings.Builder)
// tabs will be replaced by two spaces by formatter
w.Init(writer, 0, 4, 2, ' ', 0)
var cells []string
for colIndex := 0; colIndex < b.NumCols(); colIndex++ {
cells = append(cells, fmt.Sprintf(
"%v", fmt.Sprintf(
"%s:%v", b.Schema().Field(colIndex).Name, b.ColumnType(colIndex))))
}
_, err := fmt.Fprintln(w, strings.Join(cells, "\t"))
if err != nil {
panic(err)
}
for row := range b.GetRowsChan() {
cells = []string{}
for colIndex := 0; colIndex < b.NumCols(); colIndex++ {
cells = append(cells, fmt.Sprintf("%v", row[b.Schema().Field(colIndex).Name]))
}
if _, err = fmt.Fprintln(w, strings.Join(cells, "\t")); err != nil {
panic(err)
}
}
if b.Metadata().Len() > 0 {
if _, err = fmt.Fprintf(w, "metadata: %+v\n", b.Metadata()); err != nil {
panic(err)
}
}
if err = w.Flush(); err != nil {
panic(err)
}
return writer.String()
}