-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.go
93 lines (76 loc) · 1.95 KB
/
select.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package aqlquerier
import (
"database/sql/driver"
"fmt"
"github.com/bsn-si/IPEHR-gateway/src/pkg/aqlprocessor"
"github.com/bsn-si/IPEHR-gateway/src/pkg/errors"
)
func (exec *executer) queryData(sources dataRows) (*Rows, error) {
if len(sources) == 0 {
return &Rows{}, nil
}
result := &Rows{
rows: []Row{},
}
//TODO: add DISTINCT handling
// exec.query.Select.Distinct
for _, dataRow := range sources {
row := Row{
values: []interface{}{},
}
for _, selectExpr := range exec.query.Select.SelectExprs {
switch slct := selectExpr.Value.(type) {
case *aqlprocessor.IdentifiedPathSelectValue:
{
var val any
ip := slct.Val
indexNode, ok := dataRow.cells[slct.Val.Identifier]
if ok {
if ip.ObjectPath != nil {
val, _ = getValueForPath(ip.ObjectPath, indexNode.data)
} else {
return nil, errors.New("unsupported select expresion format")
}
}
row.values = append(row.values, val)
}
case *aqlprocessor.PrimitiveSelectValue:
{
val := exec.getPrimitiveColumnValue(slct)
row.values = append(row.values, val)
}
case *aqlprocessor.AggregateFunctionCallSelectValue:
{
return nil, errors.New("Aggregation function call not implemented")
}
case *aqlprocessor.FunctionCallSelectValue:
{
return nil, errors.New("Function call not implemented")
}
default:
return nil, errors.New("Unexpected SelectExpr type")
}
}
result.rows = append(result.rows, row)
}
return exec.fillColumns(result), nil
}
func (exec *executer) getPrimitiveColumnValue(prim *aqlprocessor.PrimitiveSelectValue) driver.Value {
if prim == nil {
return nil
}
return prim.Val.Val
}
func (exec *executer) fillColumns(rows *Rows) *Rows {
for i, se := range exec.query.Select.SelectExprs {
c := Column{
Path: se.Path,
Name: se.AliasName,
}
if c.Name == "" {
c.Name = fmt.Sprintf("#%d", i)
}
rows.columns = append(rows.columns, c)
}
return rows
}