Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add optional query prefix name
  • Loading branch information
gloriacai01 committed Oct 23, 2025
commit e91cd30246cf06769f0d92dcb4265b1ee8d38adb
12 changes: 10 additions & 2 deletions app/data_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ type TabularDataByMQLOptions struct {
// PipelineID is the ID of the pipeline to query. Required if TabularDataSourceType
// is TabularDataSourceTypePipelineSink.
PipelineID string
// QueryPrefixName specifies the name of the saved query to prepend the provided MQL query.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "to prepend to the provided"

QueryPrefixName string
}

// CreateDataPipelineOptions contains optional parameters for CreateDataPipeline.
Expand Down Expand Up @@ -577,11 +579,17 @@ func (d *DataClient) TabularDataByMQL(
}
}

resp, err := d.dataClient.TabularDataByMQL(ctx, &pb.TabularDataByMQLRequest{
req := &pb.TabularDataByMQLRequest{
OrganizationId: organizationID,
MqlBinary: mqlBinary,
DataSource: dataSource,
})
}

if opts.QueryPrefixName != "" {
req.QueryPrefixName = &opts.QueryPrefixName
}

resp, err := d.dataClient.TabularDataByMQL(ctx, req)
if err != nil {
return nil, err
}
Expand Down
29 changes: 23 additions & 6 deletions app/data_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
syncPb "go.viam.com/api/app/datasync/v1"
"go.viam.com/test"
utils "go.viam.com/utils/protoutils"
"go.viam.com/utils/rpc"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -273,6 +274,7 @@ func dataRequestToProto(dataRequest DataRequest) *pb.DataRequest {

func createDataGrpcClient() *inject.DataServiceClient {
return &inject.DataServiceClient{}

}

func createDataSyncGrpcClient() *inject.DataSyncServiceClient {
Expand All @@ -289,7 +291,20 @@ func createDataPipelineGrpcClient() *inject.DataPipelinesServiceClient {

func TestDataClient(t *testing.T) {
grpcClient := createDataGrpcClient()
client := DataClient{dataClient: grpcClient}
// client := DataClient{dataClient: grpcClient}

viamclient, err := CreateViamClientWithOptions(context.Background(), Options{
BaseURL: "https://app.viam.dev",
Entity: "0c7a0aea-43ed-47fe-a1cc-8aee15634e26",
Credentials: rpc.Credentials{
Type: rpc.CredentialsTypeAPIKey,
Payload: "id95xo7tiiy8eekrflu7rzaegznpvbog",
},
}, logger)
if err != nil {
logger.Errorw("error creating viam client", "error", err)
}
client := viamclient.DataClient()

captureInterval := CaptureInterval{
Start: time.Now(),
Expand Down Expand Up @@ -405,8 +420,9 @@ func TestDataClient(t *testing.T) {
})

t.Run("TabularDataByMQL", func(t *testing.T) {

// convert to BSON byte arrays
matchQuery := bson.M{"$match": bson.M{"organization_id": "e76d1b3b-0468-4efd-bb7f-fb1d2b352fcb"}}
matchQuery := bson.M{"$match": bson.M{"organization_id": "6e3cd119-c559-43e7-bf15-7ce05531f18d"}}
matchBytes, _ := bson.Marshal(matchQuery)
limitQuery := bson.M{"$limit": 1}
limitBytes, _ := bson.Marshal(limitQuery)
Expand Down Expand Up @@ -434,11 +450,12 @@ func TestDataClient(t *testing.T) {
RawData: expectedRawDataPb,
}, nil
}
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{
// 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{
TabularDataSourceType: TabularDataSourceTypeStandard,
QueryPrefixName: "testing",
})
test.That(t, err, test.ShouldBeNil)
test.That(t, response, test.ShouldResemble, rawData)
Expand Down
2 changes: 1 addition & 1 deletion app/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

// Variables used throughout testing in app.
var (
organizationID = "organization_id"
organizationID = "6e3cd119-c559-43e7-bf15-7ce05531f18d"
start = time.Now().UTC().Round(time.Millisecond)
pbStart = timestamppb.New(start)
end = time.Now().UTC().Round(time.Millisecond)
Expand Down