Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quoting of string columns in csv #1379

Merged
merged 5 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions extensions/ql-vscode/src/pure/bqrs-cli-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ export function transformBqrsResultSet(
};
}

type BqrsKind = 'String' | 'Float' | 'Integer' | 'String' | 'Boolean' | 'Date' | 'Entity';

interface BqrsColumn {
name: string;
kind: BqrsKind;
}
export interface DecodedBqrsChunk {
tuples: CellValue[][];
next?: number;
columns: BqrsColumn[];
}
9 changes: 6 additions & 3 deletions extensions/ql-vscode/src/run-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,12 @@ export class QueryEvaluationInfo {
pageSize: 100,
offset: nextOffset,
});
for (const tuple of chunk.tuples) {
out.write(tuple.join(',') + '\n');
}
const quotes = chunk.columns.map(col => col.kind === 'String' ? '"' : '');
chunk.tuples.forEach((tuple) => {
out.write(tuple.map((v, i) => {
return `${quotes[i]}${v}${quotes[i]}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we also need to be escaping any " characters in v when the column is a String (maybe it's safe to do this unconditionally if the other column types can't contain quote characters?). I believe this ought to be done by double quoting, but do check what the prevailing CSV convention is rather than taking my word for it 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll do that.

}).join(',') + '\n');
});
nextOffset = chunk.next;
}
out.end();
Expand Down