MCPcopy Create free account
hub / github.com/datasweet/datatable / ToTable

Method ToTable

export.go:58–89  ·  view source on GitHub ↗

ToTable to export the datatable to a csv-like struct

(opt ...ExportOption)

Source from the content-addressed store, hash-verified

56
57// ToTable to export the datatable to a csv-like struct
58func (t *DataTable) ToTable(opt ...ExportOption) [][]interface{} {
59 if t == nil {
60 return nil
61 }
62
63 opts := newExportOptions(opt...)
64 if err := t.evaluateExpressions(); err != nil {
65 panic(err)
66 }
67
68 rows := make([][]interface{}, 0, t.nrows+1)
69
70 // visible columns
71 var headers []interface{}
72 var cols []int
73 for i, col := range t.cols {
74 if opts.WithHiddenCols || col.IsVisible() {
75 cols = append(cols, i)
76 headers = append(headers, col.Name())
77 }
78 }
79
80 rows = append(rows, headers)
81 for i := 0; i < t.nrows; i++ {
82 r := make([]interface{}, 0, len(cols))
83 for _, pos := range cols {
84 r = append(r, t.cols[pos].serie.Get(i))
85 }
86 rows = append(rows, r)
87 }
88 return rows
89}
90
91// Schema describes a datatable
92type Schema struct {

Callers 1

TestToTableFunction · 0.80

Calls 5

evaluateExpressionsMethod · 0.95
newExportOptionsFunction · 0.85
IsVisibleMethod · 0.65
NameMethod · 0.65
GetMethod · 0.65

Tested by 1

TestToTableFunction · 0.64