-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathresult_rows.go
More file actions
74 lines (65 loc) · 1.66 KB
/
result_rows.go
File metadata and controls
74 lines (65 loc) · 1.66 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
63
64
65
66
67
68
69
70
71
72
73
74
package godatabend
import (
"database/sql/driver"
"time"
"github.com/pkg/errors"
)
func queryResponseColumnTypeOptions(settings *Settings) (*ColumnTypeOptions, error) {
opts := defaultColumnTypeOptions()
if settings == nil {
return opts, nil
}
opts.SetGeometryOutputFormat(settings.GeometryOutputFormat)
opts.SetBinaryOutputFormat(settings.BinaryOutputFormat)
opts.SetHTTPJSONResultMode(settings.HTTPJSONResultMode)
if settings.TimeZone == "" {
return opts, nil
}
location, err := time.LoadLocation(settings.TimeZone)
if err != nil {
return nil, err
}
opts.SetTimezone(location)
return opts, nil
}
func materializeJSONQueryRows(resp *QueryResponse) error {
if resp == nil || (resp.typedRows != nil && len(resp.typedRows) > 0) || len(resp.Data) == 0 {
return nil
}
if resp.Schema == nil || len(*resp.Schema) != len(resp.Data[0]) {
return errors.New("query rows and schema do not match")
}
opts, err := queryResponseColumnTypeOptions(resp.Settings)
if err != nil {
return err
}
schema, err := parse_schema(resp.Schema, opts)
if err != nil {
return err
}
rows := make([][]driver.Value, 0, len(resp.Data))
for _, rowText := range resp.Data {
row := make([]driver.Value, len(rowText))
for i, val := range rowText {
if val == nil {
row[i] = nil
continue
}
parsed, err := schema.types[i].Parse(*val)
if err != nil {
return err
}
row[i] = parsed
}
rows = append(rows, row)
}
resp.typedRows = rows
resp.Data = nil
return nil
}
func prependQueryRows(resp *QueryResponse, prefixRows [][]driver.Value) {
if resp == nil || len(prefixRows) == 0 {
return
}
resp.typedRows = append(prefixRows, resp.typedRows...)
}