(tableName string)
| 133 | } |
| 134 | |
| 135 | func (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. |
| 181 | func (m *Source) Close() error { return nil } |
no test coverage detected