MCPcopy Create free account
hub / github.com/araddon/qlbridge / loadTable

Method loadTable

datasource/mockcsv/mockcsv.go:135–178  ·  view source on GitHub ↗
(tableName string)

Source from the content-addressed store, hash-verified

133}
134
135func (m *Source) loadTable(tableName string) error {
136
137 csvRaw, ok := m.raw[tableName]
138 if !ok {
139 return schema.ErrNotFound
140 }
141
142 // The expected format is that the csv data is a single string, with new-lines, etc.
143 sr := strings.NewReader(csvRaw)
144 csvSource, err := datasource.NewCsvSource(tableName, 0, sr, make(<-chan bool, 1))
145 if err != nil {
146 u.Warnf("Could not load csv table=%q %v", tableName, err)
147 return err
148 }
149 if csvSource == nil {
150 return fmt.Errorf("No csv-source created for %q", tableName)
151 }
152 ds := membtree.NewStaticData(tableName)
153 ds.SetColumns(csvSource.Columns())
154 m.tables[tableName] = ds
155
156 // Now we are going to page through the Csv rows and Put into
157 // Static Data Source, ie copy into memory btree structure
158 for {
159 msg := csvSource.Next()
160 if msg == nil {
161 break
162 }
163 dm, ok := msg.Body().(*datasource.SqlDriverMessageMap)
164 if !ok {
165 return fmt.Errorf("Expected *datasource.SqlDriverMessageMap but got %T", msg.Body())
166 }
167
168 // We don't know the Key
169 ds.Put(nil, nil, dm.Values())
170 }
171
172 iter := &Table{StaticDataSource: ds}
173 tbl, err := ds.Table(tableName)
174 if err != nil {
175 return err
176 }
177 return datasource.IntrospectTable(tbl, iter)
178}
179
180// Close csv source.
181func (m *Source) Close() error { return nil }

Callers 3

OpenMethod · 0.95
TableMethod · 0.95
CreateTableMethod · 0.95

Calls 11

NewCsvSourceFunction · 0.92
NewStaticDataFunction · 0.92
IntrospectTableFunction · 0.92
ErrorfMethod · 0.80
ColumnsMethod · 0.65
NextMethod · 0.65
BodyMethod · 0.65
PutMethod · 0.65
ValuesMethod · 0.65
TableMethod · 0.65
SetColumnsMethod · 0.45

Tested by

no test coverage detected