diff --git a/lib/cmds/data-lake.js b/lib/cmds/data-lake.js deleted file mode 100644 index 6e5ef06..0000000 --- a/lib/cmds/data-lake.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -const options = require('../common-yargs'); - -exports.command = 'data-lake '; -exports.desc = 'Perform operations on the analytics data lake.'; -exports.builder = yargs => { - return options(yargs.commandDir('data_lake_cmds')); -}; -exports.handler = function (argv) {}; diff --git a/lib/cmds/data_lake_cmds/cancel-query.js b/lib/cmds/data_lake_cmds/cancel-query.js deleted file mode 100644 index f7b8876..0000000 --- a/lib/cmds/data_lake_cmds/cancel-query.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -const { del } = require('../../api'); -const print = require('../../print'); - -exports.command = 'cancel-query '; -exports.desc = 'Cancel a single query execution.'; -exports.builder = yargs => { - yargs.positional('queryId', { - describe: 'Id of the query to cancel.', - type: 'string' - }); -}; - -exports.handler = async argv => { - const response = await del(argv, `/v1/analytics/data-lake/query/${argv.queryId}`); - print(response.data, argv); -}; diff --git a/lib/cmds/data_lake_cmds/get-query.js b/lib/cmds/data_lake_cmds/get-query.js deleted file mode 100644 index 644bde8..0000000 --- a/lib/cmds/data_lake_cmds/get-query.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -const { get } = require('../../api'); -const print = require('../../print'); - -exports.command = 'get-query '; -exports.desc = 'Fetch a single query execution.'; -exports.builder = yargs => { - yargs.positional('queryId', { - describe: 'Id of the query to fetch.', - type: 'string' - }); -}; - -exports.handler = async argv => { - const response = await get(argv, `/v1/analytics/data-lake/query/${argv.queryId}`); - print(response.data, argv); -}; diff --git a/lib/cmds/data_lake_cmds/get-schema.js b/lib/cmds/data_lake_cmds/get-schema.js deleted file mode 100644 index 01deea2..0000000 --- a/lib/cmds/data_lake_cmds/get-schema.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -const { get } = require('../../api'); -const print = require('../../print'); - -exports.command = 'get-schema '; -exports.desc = 'Fetch a single query execution.'; -exports.builder = yargs => { - yargs.positional('projectId', { - describe: 'The ID of the project to fetch the schema from.', - type: 'string' - }).option('table', { - alias: 't', - type: 'string', - describe: 'Name of the table to fetch the schema of. The possible list of choices are provided. Note, not every project will have every table', - demandOption: true, - choices: [ - 'condition', - 'condition_summaries', - 'condition_summary', - 'conditions', - 'copynumber', - 'demographic', - 'dosage', - 'fusion', - 'gene', - 'media', - 'medication', - 'observation', - 'patient', - 'procedure', - 'procedures', - 'sequence', - 'specimen', - 'variant' - ] - }); -}; - -exports.handler = async argv => { - const response = await get(argv, `/v1/analytics/data-lake/schema/${argv.table}?datasetId=${argv.projectId}`); - print(response.data, argv); -}; diff --git a/lib/cmds/data_lake_cmds/list-queries.js b/lib/cmds/data_lake_cmds/list-queries.js deleted file mode 100644 index f58e86d..0000000 --- a/lib/cmds/data_lake_cmds/list-queries.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -const { list } = require('../../api'); -const print = require('../../print'); -const querystring = require('querystring'); - -exports.command = 'list-queries '; -exports.desc = 'List the query executions in the project.'; -exports.builder = yargs => { - yargs.positional('projectId', { - describe: 'The ID of the project to fetch queries of.', - type: 'string' - }).option('page-size', { - alias: 'n', - type: 'number', - default: 25, - describe: 'Maximum number of queries to return.' - }).option('next-page-token', { - alias: 't', - type: 'string', - describe: 'Token to retrieve the next page of results' - }); -}; - -exports.handler = async argv => { - const query = { - datasetId: argv.projectId, - pageSize: argv.pageSize - }; - - if (argv.nextPageToken) { - query.nextPageToken = argv.nextPageToken; - } - - const response = await list(argv, `/v1/analytics/data-lake/query?${querystring.stringify(query)}`); - print(response.data, argv); -}; diff --git a/lib/cmds/data_lake_cmds/list-schemas.js b/lib/cmds/data_lake_cmds/list-schemas.js deleted file mode 100644 index da142ae..0000000 --- a/lib/cmds/data_lake_cmds/list-schemas.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -const { get } = require('../../api'); -const print = require('../../print'); - -exports.command = 'list-schemas '; -exports.desc = 'List the schemas of all tables in the data lake for this project.'; -exports.builder = yargs => { - yargs.positional('projectId', { - describe: 'The ID of the project to fetch schemas of.', - type: 'string' - }); -}; - -exports.handler = async argv => { - const response = await get(argv, `/v1/analytics/data-lake/schema?datasetId=${argv.projectId}`); - print(response.data, argv); -}; diff --git a/lib/cmds/data_lake_cmds/query.js b/lib/cmds/data_lake_cmds/query.js deleted file mode 100644 index f6e492f..0000000 --- a/lib/cmds/data_lake_cmds/query.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const { post } = require('../../api'); -const print = require('../../print'); -const read = require('../../read'); - -exports.command = 'query '; -exports.desc = 'Submits a query to the Lifeomic data-lake API. A SQL query string can also be read from stdin.'; -exports.builder = yargs => { - yargs.positional('projectId', { - describe: 'The ID of the project to search within.', - type: 'string' - }).option('query', { - alias: 'q', - type: 'string', - describe: 'The SQL query to run.' - }).option('output-file-name', { - alias: 'o', - type: 'string', - describe: 'Name of the results file.', - demandOption: true - }); -}; - -exports.handler = async argv => { - const request = { - outputFileName: argv.outputFileName, - datasetId: argv.projectId - }; - - if (argv.query) { - request.query = argv.query; - } else { - request.query = await read(argv); - } - - const response = await post(argv, '/v1/analytics/data-lake/query', request); - print(response.data, argv); -}; diff --git a/test/unit/commands/data-lake-test.js b/test/unit/commands/data-lake-test.js deleted file mode 100644 index ee69510..0000000 --- a/test/unit/commands/data-lake-test.js +++ /dev/null @@ -1,214 +0,0 @@ -'use strict'; - -const uuid = require('uuid'); -const yargs = require('yargs'); -const sinon = require('sinon'); -const test = require('ava'); -const proxyquire = require('proxyquire'); - -const getStub = sinon.stub(); -const postStub = sinon.stub(); -const listStub = sinon.stub(); -const printSpy = sinon.spy(); -const readStub = sinon.stub(); -const deleteStub = sinon.stub(); -let callback; - -const queryCmd = proxyquire('../../../lib/cmds/data_lake_cmds/query', { - '../../api': { - post: postStub - }, - '../../print': (data, opts) => { - printSpy(data, opts); - callback(); - }, - '../../read': async () => readStub() -}); - -const listCmd = proxyquire('../../../lib/cmds/data_lake_cmds/list-queries', { - '../../api': { - list: listStub - }, - '../../print': (data, opts) => { - printSpy(data, opts); - callback(); - } -}); - -const getQueryCmd = proxyquire('../../../lib/cmds/data_lake_cmds/get-query', { - '../../api': { - get: getStub - }, - '../../print': (data, opts) => { - printSpy(data, opts); - callback(); - } -}); - -const getSchemasCmd = proxyquire('../../../lib/cmds/data_lake_cmds/list-schemas', { - '../../api': { - get: getStub - }, - '../../print': (data, opts) => { - printSpy(data, opts); - callback(); - } -}); - -const getSchemaCmd = proxyquire('../../../lib/cmds/data_lake_cmds/get-schema', { - '../../api': { - get: getStub - }, - '../../print': (data, opts) => { - printSpy(data, opts); - callback(); - } -}); - -const cancelQueryCmd = proxyquire('../../../lib/cmds/data_lake_cmds/cancel-query', { - '../../api': { - del: deleteStub - }, - '../../print': (data, opts) => { - printSpy(data, opts); - callback(); - } -}); - -test.afterEach.always(t => { - getStub.resetHistory(); - postStub.resetHistory(); - listStub.resetHistory(); - printSpy.resetHistory(); - readStub.resetHistory(); - deleteStub.resetHistory(); - callback = null; -}); - -test.serial.cb('The "data-lake-query" command should accept a query as an optional argument', t => { - const query = "SELECT sample_id, gene, impact, amino_acid_change, histology FROM variant WHERE tumor_site='breast'"; - const datasetId = uuid(); - const outputFileName = 'data-lake-test'; - - postStub.onFirstCall().returns({}); - - callback = () => { - t.is(postStub.callCount, 1); - t.is(postStub.getCall(0).args[1], '/v1/analytics/data-lake/query'); - t.deepEqual(postStub.getCall(0).args[2], { - query: query, - datasetId: datasetId, - outputFileName: outputFileName - }); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(queryCmd).parse(`query ${datasetId} -q "${query}" -o ${outputFileName}`); -}); - -test.serial.cb('The "data-lake-query" command should accept a query from stdin', t => { - const query = "SELECT sample_id, gene, impact, amino_acid_change, histology FROM variant WHERE tumor_site='breast'"; - const datasetId = uuid(); - const outputFileName = 'data-lake-test'; - - postStub.onFirstCall().returns({}); - readStub.onFirstCall().returns(query); - - callback = () => { - t.is(postStub.callCount, 1); - t.is(postStub.getCall(0).args[1], '/v1/analytics/data-lake/query'); - t.deepEqual(postStub.getCall(0).args[2], { - query: query, - datasetId: datasetId, - outputFileName: outputFileName - }); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(queryCmd).parse(`query ${datasetId} -o ${outputFileName}`); -}); - -test.serial.cb('The "data-lake-list-queries" command should accept page-size and next-page-token', t => { - const datasetId = uuid(); - const pageSize = 30; - const nextPageToken = uuid(); - - listStub.onFirstCall().returns({}); - const expectedPath = `/v1/analytics/data-lake/query?datasetId=${datasetId}&pageSize=${pageSize}&nextPageToken=${nextPageToken}`; - - callback = () => { - t.is(listStub.callCount, 1); - t.is(listStub.getCall(0).args[1], expectedPath); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(listCmd).parse(`list-queries ${datasetId} -n ${pageSize} -t ${nextPageToken}`); -}); - -test.serial.cb('The "data-lake-get-query" command should add query-id to path', t => { - const queryId = uuid(); - - getStub.onFirstCall().returns({}); - const expectedPath = `/v1/analytics/data-lake/query/${queryId}`; - - callback = () => { - t.is(getStub.callCount, 1); - t.is(getStub.getCall(0).args[1], expectedPath); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(getQueryCmd).parse(`get-query ${queryId}`); -}); - -test.serial.cb('The "data-lake-list-schemas" command should add dataset id to path', t => { - const datasetId = uuid(); - - getStub.onFirstCall().returns({}); - const expectedPath = `/v1/analytics/data-lake/schema?datasetId=${datasetId}`; - - callback = () => { - t.is(getStub.callCount, 1); - t.is(getStub.getCall(0).args[1], expectedPath); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(getSchemasCmd).parse(`list-schemas ${datasetId}`); -}); - -test.serial.cb('The "data-lake-get-schema" command should add dataset id and table name to path', t => { - const datasetId = uuid(); - const tableName = 'condition'; - - getStub.onFirstCall().returns({}); - const expectedPath = `/v1/analytics/data-lake/schema/${tableName}?datasetId=${datasetId}`; - - callback = () => { - t.is(getStub.callCount, 1); - t.is(getStub.getCall(0).args[1], expectedPath); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(getSchemaCmd).parse(`get-schema ${datasetId} -t ${tableName}`); -}); - -test.serial.cb('The "data-lake-cancel-query" command should add query-id to path', t => { - const queryId = uuid(); - - deleteStub.onFirstCall().returns({}); - const expectedPath = `/v1/analytics/data-lake/query/${queryId}`; - - callback = () => { - t.is(deleteStub.callCount, 1); - t.is(deleteStub.getCall(0).args[1], expectedPath); - t.is(printSpy.callCount, 1); - t.end(); - }; - - yargs.command(cancelQueryCmd).parse(`cancel-query ${queryId}`); -});