-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Query API] Provide Access to Clustering (#1059)
* feat(cluster-query): basic testless implementation * doc(cluster-query): basic doc and test setup * doc(dataflow-query): dataflow-cluster query * refactor(wiki): only escape leading ansi spaces * refactor(query-wiki): simplify code print
- Loading branch information
1 parent
2fb47ff
commit 2a38978
Showing
12 changed files
with
363 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/queries/catalog/cluster-query/cluster-query-executor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { BasicQueryData } from '../../query'; | ||
import { log } from '../../../util/log'; | ||
import type { DataflowClusterQuery, DataflowClusterQueryResult } from './cluster-query-format'; | ||
import { findAllClusters } from '../../../dataflow/cluster'; | ||
|
||
|
||
export function executeDataflowClusterQuery({ graph }: BasicQueryData, queries: readonly DataflowClusterQuery[]): DataflowClusterQueryResult { | ||
if(queries.length !== 1) { | ||
log.warn('The dataflow cluster query expects only up to one query, but got', queries.length); | ||
} | ||
|
||
const start = Date.now(); | ||
const clusters = findAllClusters(graph); | ||
return { | ||
'.meta': { | ||
timing: Date.now() - start | ||
}, | ||
clusters | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { BaseQueryFormat, BaseQueryResult } from '../../base-query-format'; | ||
import type { DataflowGraphClusters } from '../../../dataflow/cluster'; | ||
|
||
/** | ||
* Calculates and returns all clusters encountered in the dataflow graph. | ||
*/ | ||
export interface DataflowClusterQuery extends BaseQueryFormat { | ||
readonly type: 'dataflow-cluster'; | ||
} | ||
|
||
export interface DataflowClusterQueryResult extends BaseQueryResult { | ||
/** All clusters found in the respective dataflow */ | ||
readonly clusters: DataflowGraphClusters; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/functionality/dataflow/query/dataflow-cluster-query-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { assertQuery } from '../../_helper/query'; | ||
import { label } from '../../_helper/label'; | ||
import { withShell } from '../../_helper/shell'; | ||
import { findAllClusters } from '../../../../src/dataflow/cluster'; | ||
import type { DataflowClusterQuery } from '../../../../src/queries/catalog/cluster-query/cluster-query-format'; | ||
|
||
describe('Dataflow Cluster Query', withShell(shell => { | ||
function testQuery(name: string, code: string, query: readonly DataflowClusterQuery[]) { | ||
assertQuery(label(name), shell, code, query, ({ dataflow }) => ({ 'dataflow-cluster': { clusters: findAllClusters(dataflow.graph) } })); | ||
} | ||
|
||
testQuery('Single Expression', 'x + 1', [{ type: 'dataflow-cluster' }]); | ||
testQuery('Multiple Queries', 'x + 1', [{ type: 'dataflow-cluster' }, { type: 'dataflow-cluster' }, { type: 'dataflow-cluster' }]); | ||
})); |
Oops, something went wrong.