Skip to content

Commit 28176e1

Browse files
committed
Implement naive deduction of table name from filename
1 parent 2c7533e commit 28176e1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewCompiler(filepath string) (*Compiler, error) {
4141
}
4242

4343
tableContext := map[string]*table.Table{
44-
"superhero": &csvTable, // TODO: Remove hardcoded value
44+
table.GetTableNameFromFile(filepath): &csvTable,
4545
}
4646
return &Compiler{tableContext: tableContext}, nil
4747
}

table/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ package table
22

33
import (
44
"fmt"
5+
"strings"
56
)
67

78
func getColumnAlias(index uint) string {
89
return fmt.Sprintf("Col_%d", index)
910
}
11+
12+
func GetTableNameFromFile(filename string) string {
13+
// TODO: Make this much, much smarter
14+
// - Handle multiple extensions: data.txt.csv > data
15+
// - Handle fully qualified paths: /home/rohit/project/data.csv > data
16+
17+
dotLocation := strings.LastIndex(filename, ".")
18+
return filename[:dotLocation]
19+
}

0 commit comments

Comments
 (0)