Add fields to query api.

This commit is contained in:
Jim Myers 2020-06-24 17:17:53 -04:00
parent b7e5d49a42
commit c40d001588
3 changed files with 47 additions and 0 deletions

View File

@ -95,6 +95,23 @@ func makeWindowingQuery() dynamicquery.Query {
return query
}
func makeFieldsQuery() dynamicquery.Query {
fields := make([]dynamicquery.Field, 0)
fields = append(fields, dynamicquery.Field{
Label: "tx_id",
Field: "tx_id",
})
query := dynamicquery.Query{
Table: "udm_events_aion",
Schema: "source",
Fields: &fields,
Limit: 5,
}
return query
}
func TestClient_GetSegmentMembers(t *testing.T) {
client := getClient(t)
@ -166,6 +183,26 @@ func TestClient_ExecuteDynamicQueryWithWindowing(t *testing.T) {
fmt.Println("")
}
func TestClient_ExecuteDynamicQueryWithFields(t *testing.T) {
client := getClient(t)
resp, err := client.ExecuteDynamicQuery(makeFieldsQuery(), false, 10)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if resp == nil {
t.Fatal("resp is nil")
}
if resp.Error != "" {
t.Fatalf("error is not empty %s", resp.Error)
}
fmt.Fprintln(os.Stdout, "TestClient_ExecuteDynamicQueryWithFields")
fmt.Fprintln(os.Stdout, *resp)
fmt.Println("")
}
func TestClient_ExecuteDynamicQueryWithError(t *testing.T) {
client := getClient(t)
query := makeQuery(makeCondition())

9
dynamicquery/field.go Normal file
View File

@ -0,0 +1,9 @@
package dynamicquery
// Field selects a field to return
type Field struct {
Field string `json:"field"`
Label string `json:"label"`
DecimalAdjustment int `json:"decimal_adjustment"`
ToNegative bool `json:"to_negative"`
}

View File

@ -11,6 +11,7 @@ type Query struct {
Filter *Filter `json:"filter,omitempty"`
OrderBy []OrderBy `json:"order_by"`
Limit int `json:"limit"`
Fields *[]Field `json:"fields,omitempty"`
Latest *Latest `json:"latest,omitempty"`
Earliest *Earliest `json:"earliest,omitempty"`
Segments map[string]segment.Condition `json:"segments"`