Skip to content

Commit dc1bdc6

Browse files
authored
fix: response schema change for 0.9.0 (#37)
1 parent d1164d5 commit dc1bdc6

File tree

4 files changed

+10
-30
lines changed

4 files changed

+10
-30
lines changed

query.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,17 @@ func (e *QueryError) Error() string {
2020
}
2121

2222
type DataField struct {
23-
Name string `json:"name"`
24-
DataType TypeDetail `json:"data_type"`
25-
}
26-
27-
type TypeDetail struct {
23+
Name string `json:"name"`
2824
Type string `json:"type"`
2925
}
3026

31-
type DataSchema struct {
32-
Fields []DataField `json:"fields"`
33-
}
34-
3527
type QueryResponse struct {
3628
Data [][]interface{} `json:"data"`
3729
Error *QueryError `json:"error"`
3830
FinalURI string `json:"final_uri"`
3931
Id string `json:"id"`
4032
NextURI string `json:"next_uri"`
41-
Schema DataSchema `json:"schema,omitempty"`
33+
Schema []DataField `json:"schema"`
4234
State string `json:"state"`
4335
Stats QueryStats `json:"stats"`
4436
StatsURI string `json:"stats_uri"`

rows.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package godatabend
22

33
import (
44
"database/sql/driver"
5-
"encoding/json"
65
"fmt"
76
"io"
87
"reflect"
@@ -46,18 +45,9 @@ func newNextRows(dc *DatabendConn, resp *QueryResponse) (*nextRows, error) {
4645
return nil, err
4746
}
4847

49-
for _, field := range result.Schema.Fields {
48+
for _, field := range result.Schema {
5049
columns = append(columns, field.Name)
51-
x := &TypeDetail{}
52-
res, err := json.Marshal(field.DataType)
53-
if err != nil {
54-
return nil, err
55-
}
56-
err = json.Unmarshal(res, &x)
57-
if err != nil {
58-
return nil, err
59-
}
60-
types = append(types, x.Type)
50+
types = append(types, field.Type)
6151
}
6252

6353
parsers := make([]DataParser, len(types))

rows_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010
func TestTextRows(t *testing.T) {
1111
rows, err := newNextRows(&DatabendConn{}, &QueryResponse{
1212
Data: [][]interface{}{{1, 2, "3"}, {3, 2, "1"}},
13-
Schema: DataSchema{
14-
Fields: []DataField{
15-
{Name: "age", DataType: TypeDetail{Type: "Int32"}},
16-
{Name: "height", DataType: TypeDetail{Type: "Int64"}},
17-
{Name: "score", DataType: TypeDetail{Type: "String"}},
18-
},
13+
Schema: []DataField{
14+
{Name: "age", Type: "Int32"},
15+
{Name: "height", Type: "Int64"},
16+
{Name: "score", Type: "String"},
1917
},
2018
State: "Succeeded",
2119
})

tests/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func (s *DatabendTestSuite) TestDesc() {
9494
{"s2", "VARCHAR", "NO", "", ""},
9595
{"a16", "ARRAY(INT16)", "NO", "[]", ""},
9696
{"a8", "ARRAY(UINT8)", "NO", "[]", ""},
97-
{"d", "DATE", "NO", "0", ""},
98-
{"t", "TIMESTAMP", "NO", "0", ""},
97+
{"d", "DATE", "NO", "1970-01-01", ""},
98+
{"t", "TIMESTAMP", "NO", "1970-01-01 00:00:00.000000", ""},
9999
}, result)
100100
rows.Close()
101101
}

0 commit comments

Comments
 (0)