Skip to content

Commit

Permalink
DATA-3755 Update Go SDK to have useRecentData option (viamrobotics#4786)
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayvuyyuru authored Feb 18, 2025
1 parent 810cd06 commit bb72ab1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/data_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ type DataByFilterOptions struct {
IncludeInternalData bool
}

// TabularDataByMQLOptions contains optional parameters for TabularDataByMQL.
type TabularDataByMQLOptions struct {
UseRecentData bool
}

// BinaryDataCaptureUploadOptions represents optional parameters for the BinaryDataCaptureUpload method.
type BinaryDataCaptureUploadOptions struct {
Type *DataType
Expand Down Expand Up @@ -438,7 +443,7 @@ func (d *DataClient) TabularDataBySQL(ctx context.Context, organizationID, sqlQu

// TabularDataByMQL queries tabular data with MQL (MongoDB Query Language) queries.
func (d *DataClient) TabularDataByMQL(
ctx context.Context, organizationID string, query []map[string]interface{},
ctx context.Context, organizationID string, query []map[string]interface{}, opts *TabularDataByMQLOptions,
) ([]map[string]interface{}, error) {
mqlBinary := [][]byte{}
for _, q := range query {
Expand All @@ -449,9 +454,15 @@ func (d *DataClient) TabularDataByMQL(
mqlBinary = append(mqlBinary, binary)
}

useRecentData := false
if opts != nil {
useRecentData = opts.UseRecentData
}

resp, err := d.dataClient.TabularDataByMQL(ctx, &pb.TabularDataByMQLRequest{
OrganizationId: organizationID,
MqlBinary: mqlBinary,
UseRecentData: &useRecentData,
})
if err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion app/data_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,13 @@ func TestDataClient(t *testing.T) {
RawData: expectedRawDataPb,
}, nil
}
response, err := client.TabularDataByMQL(context.Background(), organizationID, mqlQueries)
response, err := client.TabularDataByMQL(context.Background(), organizationID, mqlQueries, nil)
test.That(t, err, test.ShouldBeNil)
test.That(t, response, test.ShouldResemble, rawData)
response, err = client.TabularDataByMQL(context.Background(), organizationID, mqlQueries, &TabularDataByMQLOptions{UseRecentData: false})
test.That(t, err, test.ShouldBeNil)
test.That(t, response, test.ShouldResemble, rawData)
response, err = client.TabularDataByMQL(context.Background(), organizationID, mqlQueries, &TabularDataByMQLOptions{UseRecentData: true})
test.That(t, err, test.ShouldBeNil)
test.That(t, response, test.ShouldResemble, rawData)
})
Expand Down

0 comments on commit bb72ab1

Please sign in to comment.