Skip to content

Commit fd72820

Browse files
alexetjcreedcmu
authored andcommitted
Add cli bqrs -types
1 parent 8d9a470 commit fd72820

File tree

2 files changed

+116
-6
lines changed

2 files changed

+116
-6
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
export const PAGE_SIZE = 1000;
3+
4+
export type ColumnKind = "f" | "i" | "s" | "b" | "d" | "e";
5+
6+
export interface Column {
7+
name?: string,
8+
kind: ColumnKind,
9+
}
10+
11+
12+
export interface ResultSetSchema {
13+
name: string,
14+
rows: number,
15+
columns: Column[],
16+
pagination?: PaginationInfo,
17+
}
18+
19+
export function getResultSetSchema(resultSetName: string, resultSets: BQRSInfo): ResultSetSchema | undefined {
20+
for (const schema of resultSets["result-sets"]) {
21+
if (schema.name === resultSetName) {
22+
return schema;
23+
}
24+
}
25+
return undefined;
26+
}
27+
export interface PaginationInfo {
28+
"step-size": number,
29+
offsets: number[],
30+
}
31+
32+
export interface BQRSInfo {
33+
"result-sets": ResultSetSchema[]
34+
}
35+
36+
export interface EntityValue {
37+
url?: UrlValue,
38+
label?: string
39+
}
40+
41+
export interface LineColumnLocation {
42+
uri: string
43+
startLine: number,
44+
startColumn: number,
45+
endLine: number,
46+
endColumn: number,
47+
charOffset: never
48+
charLength: never
49+
}
50+
51+
export interface OffsetLengthLocation {
52+
uri: string,
53+
startLine: never,
54+
startColumn: never,
55+
endLine: never,
56+
endColumn: never,
57+
charOffset: number,
58+
charLength: number,
59+
}
60+
61+
export interface WholeFileLocation {
62+
uri: string,
63+
startLine: undefined,
64+
startColumn: undefined,
65+
endLine: undefined,
66+
endColumn: undefined,
67+
charOffset: undefined,
68+
charLength: undefined,
69+
}
70+
71+
export type UrlValue = LineColumnLocation | OffsetLengthLocation | WholeFileLocation | string;
72+
73+
74+
export type ColumnValue = EntityValue | number | string | boolean;
75+
76+
export interface DecodedBqrsChunk {
77+
tuples: ColumnValue[][],
78+
next?: number
79+
}

extensions/ql-vscode/src/cli.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import * as child_process from 'child_process';
21
import * as cpp from 'child-process-promise';
2+
import * as child_process from 'child_process';
33
import * as fs from 'fs-extra';
44
import * as path from 'path';
55
import * as sarif from 'sarif';
6+
import { Readable } from 'stream';
7+
import { StringDecoder } from 'string_decoder';
68
import * as tk from 'tree-kill';
79
import * as util from 'util';
8-
import { SortDirection, QueryMetadata } from './interface-types';
9-
import { Logger, ProgressReporter } from './logging';
10-
import { Disposable, CancellationToken } from 'vscode';
10+
import { CancellationToken, Disposable } from 'vscode';
11+
import { BQRSInfo, DecodedBqrsChunk } from "./bqrs-cli-types";
1112
import { DistributionProvider } from './distribution';
1213
import { assertNever } from './helpers-pure';
13-
import { Readable } from 'stream';
14-
import { StringDecoder } from 'string_decoder';
14+
import { QueryMetadata, SortDirection } from './interface-types';
15+
import { Logger, ProgressReporter } from './logging';
1516

1617
/**
1718
* The version of the SARIF format that we are using.
@@ -471,6 +472,36 @@ export class CodeQLCliServer implements Disposable {
471472
}
472473
return await this.runJsonCodeQlCliCommand<string[]>(['resolve', 'ram'], args, "Resolving RAM settings", progressReporter);
473474
}
475+
/**
476+
* Gets the headers (and optionally pagination info) of a bqrs.
477+
* @param config The configuration containing the path to the CLI.
478+
* @param bqrsPath The path to the vqrs.
479+
*/
480+
async bqrsInfo(bqrsPath: string, pageSize?: number): Promise<BQRSInfo> {
481+
const subcommandArgs = (
482+
pageSize ? ["--paginate-rows", pageSize.toString()] : []
483+
).concat(
484+
bqrsPath
485+
);
486+
return await this.runJsonCodeQlCliCommand<BQRSInfo>(['bqrs', 'info'], subcommandArgs, "Reading bqrs header");
487+
}
488+
489+
/**
490+
* Gets the results from a bqrs.
491+
* @param config The configuration containing the path to the CLI.
492+
* @param bqrsPath The path to the bqrs.
493+
*/
494+
async bqrsDecode(bqrsPath: string, resultSet: string, pageSize?: number, offset?: number): Promise<DecodedBqrsChunk> {
495+
const subcommandArgs = [
496+
"--entities=url,string",
497+
"--result-set", resultSet,
498+
].concat(
499+
pageSize ? ["--rows", pageSize.toString()] : []
500+
).concat(
501+
offset ? ["--start-at", offset.toString()] : []
502+
).concat([bqrsPath]);
503+
return await this.runJsonCodeQlCliCommand<DecodedBqrsChunk>(['bqrs', 'decode'], subcommandArgs, "Reading bqrs data");
504+
}
474505

475506

476507
async interpretBqrs(metadata: { kind: string, id: string }, resultsPath: string, interpretedResultsPath: string, sourceInfo?: SourceInfo): Promise<sarif.Log> {

0 commit comments

Comments
 (0)