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

Method ToSchema

export.go:104–137  ·  view source on GitHub ↗

ToSchema to export the datatable to a schema struct

(opt ...ExportOption)

Source from the content-addressed store, hash-verified

102
103// ToSchema to export the datatable to a schema struct
104func (t *DataTable) ToSchema(opt ...ExportOption) *Schema {
105 if t == nil {
106 return nil
107 }
108
109 opts := newExportOptions(opt...)
110 if err := t.evaluateExpressions(); err != nil {
111 panic(err)
112 }
113
114 schema := &Schema{
115 Name: t.name,
116 Rows: make([][]interface{}, 0, t.nrows),
117 }
118
119 // visible columns
120 var cols []int
121 for i, col := range t.cols {
122 if opts.WithHiddenCols || col.IsVisible() {
123 cols = append(cols, i)
124 schema.Columns = append(schema.Columns, SchemaColumn{Type: col.UnderlyingType().Name(), Name: col.Name()})
125 }
126 }
127
128 for i := 0; i < t.nrows; i++ {
129 r := make([]interface{}, 0, len(cols))
130 for _, pos := range cols {
131 r = append(r, t.cols[pos].serie.Get(i))
132 }
133 schema.Rows = append(schema.Rows, r)
134 }
135
136 return schema
137}

Callers 1

TestToSchemaFunction · 0.80

Calls 6

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

Tested by 1

TestToSchemaFunction · 0.64