Table satisfys SourceSchema interface to get table schema for given table
(tableName string)
| 287 | |
| 288 | // Table satisfys SourceSchema interface to get table schema for given table |
| 289 | func (m *FileSource) Table(tableName string) (*schema.Table, error) { |
| 290 | |
| 291 | //u.Debugf("Table(%q) path:%v %#v", tableName, m.path, m.ss.Conf) |
| 292 | // We have a special table that is the list of all files |
| 293 | if m.filesTable == tableName { |
| 294 | return m.fdb.Table(tableName) |
| 295 | } |
| 296 | |
| 297 | // Check cache for this table |
| 298 | t, ok := m.tableSchemas[tableName] |
| 299 | if ok { |
| 300 | return t, nil |
| 301 | } |
| 302 | |
| 303 | var err error |
| 304 | // Its possible that the file handle implements schema handling |
| 305 | if schemaSource, hasSchema := m.fh.(schema.SourceTableSchema); hasSchema { |
| 306 | t, err = schemaSource.Table(tableName) |
| 307 | if err != nil { |
| 308 | u.Errorf("could not get %T table %q %v", schemaSource, tableName, err) |
| 309 | return nil, err |
| 310 | } |
| 311 | |
| 312 | } else { |
| 313 | |
| 314 | // Source doesn't implement Schema Handling so we are going to get |
| 315 | // a scanner and introspect some rows |
| 316 | t, err = m.buildTable(tableName) |
| 317 | if err != nil { |
| 318 | return nil, err |
| 319 | } |
| 320 | |
| 321 | } |
| 322 | |
| 323 | if t == nil { |
| 324 | return nil, fmt.Errorf("Missing table for %q", tableName) |
| 325 | } |
| 326 | |
| 327 | m.tableSchemas[tableName] = t |
| 328 | //u.Debugf("%p Table(%q) cols=%v", m, tableName, t.Columns()) |
| 329 | return t, nil |
| 330 | } |
| 331 | |
| 332 | func (m *FileSource) buildTable(tableName string) (*schema.Table, error) { |
| 333 |
nothing calls this directly
no test coverage detected