Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
27 changes: 27 additions & 0 deletions src/app/data-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
TabularDataByFilterResponse,
TabularDataByMQLResponse,
TabularDataBySQLResponse,
TabularDataSourceType,
TagsByFilterRequest,
TagsByFilterResponse,
TagsFilter,
Expand Down Expand Up @@ -1427,17 +1428,21 @@ describe('DataPipelineClient tests', () => {
const pipelineName = 'testPipeline';
const mqlQuery = [{ $match: { component_name: 'sensor-1' } }];
const schedule = '0 0 * * *';
const dataSourceTypeStandard = TabularDataSourceType.STANDARD;
const dataSourceTypeHotStorage = TabularDataSourceType.HOT_STORAGE;

describe('listDataPipelines tests', () => {
const pipeline1 = new DataPipeline({
id: 'pipeline1',
name: 'pipeline1',
organizationId: 'org1',
dataSourceType: dataSourceTypeStandard,
});
const pipeline2 = new DataPipeline({
id: 'pipeline2',
name: 'pipeline2',
organizationId: 'org2',
dataSourceType: dataSourceTypeHotStorage,
});
const pipelines = [pipeline1, pipeline2];

Expand Down Expand Up @@ -1471,6 +1476,7 @@ describe('DataPipelineClient tests', () => {
id: pipelineId,
name: pipelineName,
organizationId,
dataSourceType: dataSourceTypeStandard,
});

let capReq: GetDataPipelineRequest;
Expand Down Expand Up @@ -1532,6 +1538,27 @@ describe('DataPipelineClient tests', () => {
name: pipelineName,
mqlBinary: mqlQuery.map((value) => BSON.serialize(value)),
schedule,
dataSourceType: dataSourceTypeStandard,
});

const response = await subject().createDataPipeline(
organizationId,
pipelineName,
mqlQuery,
schedule,
'standard'
);
expect(capReq).toStrictEqual(expectedRequest);
expect(response).toEqual(pipelineId);
});

it('create data pipeline with optional dataSourceType', async () => {
const expectedRequest = new CreateDataPipelineRequest({
organizationId,
name: pipelineName,
mqlBinary: mqlQuery.map((value) => BSON.serialize(value)),
schedule,
dataSourceType: dataSourceTypeStandard,
});

const response = await subject().createDataPipeline(
Expand Down
22 changes: 21 additions & 1 deletion src/app/data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1409,24 +1409,44 @@ export class DataClient {
* @param name The name of the data pipeline
* @param query The MQL query to run as a list of BSON documents
* @param schedule The schedule to run the query on (cron expression)
* @param dataSourceType The type of data source to use for the data pipeline
* @returns The ID of the created data pipeline
*/
async createDataPipeline(
organizationId: string,
name: string,
query: Uint8Array[] | Record<string, Date | JsonValue>[],
schedule: string
schedule: string,
dataSourceType?: string
Copy link
Member

Choose a reason for hiding this comment

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

The type of dataSourceType should match this: https://github.com/viamrobotics/viam-typescript-sdk/blob/867c57aa402adf1f63bb94a23dd1a71112d5b71c/src/app/data-client.ts#L17C3-L17C24.
Here is how we use it for reference:

tabularDataSource?: TabularDataSource

): Promise<string> {
const mqlBinary: Uint8Array[] =
query[0] instanceof Uint8Array
? (query as Uint8Array[])
: query.map((value) => BSON.serialize(value));

const inputDataSourceType = dataSourceType ?? 'standard';
let dataSource: TabularDataSourceType;

switch (inputDataSourceType) {
case 'standard': {
dataSource = TabularDataSourceType.STANDARD;
break;
}
case 'hot_storage': {
dataSource = TabularDataSourceType.HOT_STORAGE;
break;
}
default: {
throw new Error(`Invalid data source type: ${dataSourceType}`);
}
}

const resp = await this.dataPipelinesClient.createDataPipeline({
organizationId,
name,
mqlBinary,
schedule,
dataSourceType: dataSource,
});
return resp.id;
}
Expand Down