-
Notifications
You must be signed in to change notification settings - Fork 3
/
fdw.go
52 lines (44 loc) · 1.14 KB
/
fdw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
// TODO: This file should be replaced by your actual implementation. Call SetTable in init to start serving queries.
import "fmt"
func init() {
SetTable(helloTable{Rows: 10})
}
type helloTable struct{ Rows int }
func (t helloTable) Stats(opts Options) TableStats {
return TableStats{Rows: uint(t.Rows), StartCost: 10, TotalCost: 1000}
}
func (t helloTable) Scan(rel *Relation, opts Options) Iterator {
return &helloIter{t: t, rel: rel}
}
var _ Explainable = (*helloIter)(nil)
type helloIter struct {
t helloTable
rel *Relation
row int
}
func (it *helloIter) Explain(e Explainer) {
e.Property("Powered by", "Go FDW")
}
func (it *helloIter) Next() []interface{} {
if it.row >= it.t.Rows {
return nil
}
out := make([]interface{}, len(it.rel.Attr.Attrs))
for i := range out {
attr := it.rel.Attr.Attrs[i]
if !attr.NotNull {
continue
}
switch attr.Type {
case TypeInt16, TypeInt32, TypeInt64:
out[i] = int(it.row)
case TypeText:
out[i] = fmt.Sprintf("Row: %d, Col: %q", it.row, attr.Name)
}
}
it.row++
return out
}
func (it *helloIter) Reset() { it.row = 0 }
func (it *helloIter) Close() error { return nil }