-
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.
feat(lineage-query): impl of lineage query
- Loading branch information
1 parent
4ea237a
commit 7cf9c3c
Showing
6 changed files
with
85 additions
and
3 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
26 changes: 26 additions & 0 deletions
26
src/queries/catalog/lineage-query/lineage-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,26 @@ | ||
import type { BasicQueryData } from '../../query'; | ||
import type { | ||
LineageQuery, | ||
LineageQueryResult | ||
} from './lineage-query-format'; | ||
import { log } from '../../../util/log'; | ||
import { getLineage } from '../../../cli/repl/commands/repl-lineage'; | ||
|
||
/* TODO: deprecate the request */ | ||
export function executeLineageQuery({ graph, ast }: BasicQueryData, queries: readonly LineageQuery[]): LineageQueryResult { | ||
const start = Date.now(); | ||
const result: LineageQueryResult['lineages'] = {}; | ||
for(const { criterion } of queries) { | ||
if(result[criterion]) { | ||
log.warn('Duplicate criterion in lineage query:', criterion); | ||
} | ||
result[criterion] = getLineage(criterion, graph, ast.idMap); | ||
} | ||
|
||
return { | ||
'.meta': { | ||
timing: Date.now() - start | ||
}, | ||
lineages: result | ||
}; | ||
} |
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,16 @@ | ||
import type { BaseQueryFormat, BaseQueryResult } from '../../base-query-format'; | ||
import type { SingleSlicingCriterion } from '../../../slicing/criterion/parse'; | ||
import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id'; | ||
|
||
/** | ||
* Calculates the lineage of the given criterion. | ||
*/ | ||
export interface LineageQuery extends BaseQueryFormat { | ||
readonly type: 'lineage'; | ||
readonly criterion: SingleSlicingCriterion; | ||
} | ||
|
||
export interface LineageQueryResult extends BaseQueryResult { | ||
/** Maps each criterion to the found lineage, duplicates are ignored. */ | ||
readonly lineages: Record<SingleSlicingCriterion, Set<NodeId>>; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { assertQuery } from '../../_helper/query'; | ||
import { label } from '../../_helper/label'; | ||
import { withShell } from '../../_helper/shell'; | ||
import type { | ||
LineageQuery, | ||
LineageQueryResult | ||
} from '../../../../src/queries/catalog/lineage-query/lineage-query-format'; | ||
import { getLineage } from '../../../../src/cli/repl/commands/repl-lineage'; | ||
|
||
describe('Lineage Query', withShell(shell => { | ||
function testQuery(name: string, code: string, query: readonly LineageQuery[]) { | ||
assertQuery(label(name), shell, code, query, ({ dataflow }) => ({ | ||
'lineage': { | ||
lineages: query.reduce((acc, { criterion }) => { | ||
acc[criterion] = getLineage(criterion, dataflow.graph); | ||
return acc; | ||
}, {} as LineageQueryResult['lineages']) | ||
} | ||
})); | ||
} | ||
|
||
testQuery('Single Expression', 'x + 1', [{ type: 'lineage', criterion: '1@x' }]); | ||
testQuery('Multiple Queries', 'x + 1', [{ type: 'lineage', criterion: '1@x' }, { type: 'lineage', criterion: '1@x' }, { type: 'lineage', criterion: '1@x' }]); | ||
})); |