-
Notifications
You must be signed in to change notification settings - Fork 9
/
response.go
137 lines (118 loc) · 4.87 KB
/
response.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package pinot
import (
"encoding/json"
log "github.com/sirupsen/logrus"
)
// BrokerResponse is the data structure for broker response.
type BrokerResponse struct {
SelectionResults *SelectionResults `json:"SelectionResults,omitempty"`
ResultTable *ResultTable `json:"resultTable,omitempty"`
TraceInfo map[string]string `json:"traceInfo,omitempty"`
AggregationResults []*AggregationResult `json:"aggregationResults,omitempty"`
Exceptions []Exception `json:"exceptions"`
NumSegmentsProcessed int `json:"numSegmentsProcessed"`
NumServersResponded int `json:"numServersResponded"`
NumSegmentsQueried int `json:"numSegmentsQueried"`
NumServersQueried int `json:"numServersQueried"`
NumSegmentsMatched int `json:"numSegmentsMatched"`
NumConsumingSegmentsQueried int `json:"numConsumingSegmentsQueried"`
NumDocsScanned int64 `json:"numDocsScanned"`
NumEntriesScannedInFilter int64 `json:"numEntriesScannedInFilter"`
NumEntriesScannedPostFilter int64 `json:"numEntriesScannedPostFilter"`
TotalDocs int64 `json:"totalDocs"`
TimeUsedMs int `json:"timeUsedMs"`
MinConsumingFreshnessTimeMs int64 `json:"minConsumingFreshnessTimeMs"`
NumGroupsLimitReached bool `json:"numGroupsLimitReached"`
}
// AggregationResult is the data structure for PQL aggregation result
type AggregationResult struct {
Function string `json:"function"`
Value string `json:"value,omitempty"`
GroupByColumns []string `json:"groupByColumns,omitempty"`
GroupByResult []GroupValue `json:"groupByResult,omitempty"`
}
// GroupValue is the data structure for PQL aggregation GroupBy result
type GroupValue struct {
Value string `json:"value"`
Group []string `json:"group"`
}
// SelectionResults is the data structure for PQL selection result
type SelectionResults struct {
Columns []string `json:"columns"`
Results [][]interface{} `json:"results"`
}
// RespSchema is response schema
type RespSchema struct {
ColumnDataTypes []string `json:"columnDataTypes"`
ColumnNames []string `json:"columnNames"`
}
// Exception is Pinot exceptions.
type Exception struct {
Message string `json:"message"`
ErrorCode int `json:"errorCode"`
}
// ResultTable is a ResultTable
type ResultTable struct {
DataSchema RespSchema `json:"dataSchema"`
Rows [][]interface{} `json:"rows"`
}
// GetRowCount returns how many rows in the ResultTable
func (r ResultTable) GetRowCount() int {
return len(r.Rows)
}
// GetColumnCount returns how many columns in the ResultTable
func (r ResultTable) GetColumnCount() int {
return len(r.DataSchema.ColumnNames)
}
// GetColumnName returns column name given column index
func (r ResultTable) GetColumnName(columnIndex int) string {
return r.DataSchema.ColumnNames[columnIndex]
}
// GetColumnDataType returns column data type given column index
func (r ResultTable) GetColumnDataType(columnIndex int) string {
return r.DataSchema.ColumnDataTypes[columnIndex]
}
// Get returns a ResultTable entry given row index and column index
func (r ResultTable) Get(rowIndex int, columnIndex int) interface{} {
return r.Rows[rowIndex][columnIndex]
}
// GetString returns a ResultTable string entry given row index and column index
func (r ResultTable) GetString(rowIndex int, columnIndex int) string {
return (r.Rows[rowIndex][columnIndex]).(string)
}
// GetInt returns a ResultTable int entry given row index and column index
func (r ResultTable) GetInt(rowIndex int, columnIndex int) int32 {
val, err := (r.Rows[rowIndex][columnIndex]).(json.Number).Int64()
if err != nil {
log.Errorf("Error converting to int: %v", err)
return 0
}
return int32(val)
}
// GetLong returns a ResultTable long entry given row index and column index
func (r ResultTable) GetLong(rowIndex int, columnIndex int) int64 {
val, err := (r.Rows[rowIndex][columnIndex]).(json.Number).Int64()
if err != nil {
log.Errorf("Error converting to long: %v", err)
return 0
}
return val
}
// GetFloat returns a ResultTable float entry given row index and column index
func (r ResultTable) GetFloat(rowIndex int, columnIndex int) float32 {
val, err := (r.Rows[rowIndex][columnIndex]).(json.Number).Float64()
if err != nil {
log.Errorf("Error converting to float: %v", err)
return 0
}
return float32(val)
}
// GetDouble returns a ResultTable double entry given row index and column index
func (r ResultTable) GetDouble(rowIndex int, columnIndex int) float64 {
val, err := (r.Rows[rowIndex][columnIndex]).(json.Number).Float64()
if err != nil {
log.Errorf("Error converting to double: %v", err)
return 0
}
return val
}