-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult.go
More file actions
62 lines (56 loc) · 1.33 KB
/
Copy pathresult.go
File metadata and controls
62 lines (56 loc) · 1.33 KB
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
53
54
55
56
57
58
59
60
61
62
package ferndb
import (
"errors"
"github.com/chaitanya-uike/ferndb/attr"
"github.com/chaitanya-uike/ferndb/catalog"
"github.com/chaitanya-uike/ferndb/pipeline"
"github.com/chaitanya-uike/ferndb/plan"
"github.com/chaitanya-uike/ferndb/types"
)
type Result struct {
Cols []string
Rows [][]types.Value
Affected int64
}
func (tx *Tx) resolveColumns(sp *plan.SelectPlan) ([]string, []attr.Attribute, error) {
cat, err := tx.catalog()
if err != nil {
return nil, nil, err
}
names := make([]string, len(sp.OutputAttrs))
for i, expr := range sp.Projections {
names[i] = columnName(cat, expr)
}
return names, sp.OutputAttrs, nil
}
func columnName(cat *catalog.Catalog, expr plan.Expr) string {
if c, ok := expr.(*plan.ColumnReference); ok {
if s, ok := cat.Schema(c.Table); ok {
if col := s.ColumnByID(c.ColumnID); col != nil {
return col.Name
}
}
}
return "?column?"
}
func materialize(op pipeline.Op, attrs []attr.Attribute) ([][]types.Value, error) {
if err := op.Open(); err != nil {
return nil, err
}
defer op.Close()
var out [][]types.Value
for {
row, err := op.Next()
if errors.Is(err, pipeline.EOF) {
return out, nil
}
if err != nil {
return nil, err
}
values := make([]types.Value, len(attrs))
for i, a := range attrs {
values[i] = row[a]
}
out = append(out, values)
}
}