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

Conversation

aeisenberg
Copy link
Contributor

@aeisenberg aeisenberg commented Jun 3, 2022

Fixes two issues with CSV exporting and creates a unit test along with a generic framework for creating a mock CLI server. Commit-by-commit review is suggested.

Fixes #1377
Fixes #1376

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@aeisenberg aeisenberg requested a review from a team as a code owner June 3, 2022 23:25
If the `#select` resultset doesn't exist, arbitrarily choose the first
result set when viewing csv results. This will almost certainly be the
correct result set.

In the future, we could offer a popup if there are multiple result sets
available, but let's wait on that until someone actually asks for it.
@aeisenberg aeisenberg added the Complexity: Low A good task for newcomers to learn, or experienced team members to complete quickly. label Jun 6, 2022
1. `exportCsvResults` now no longer requires an `onFinish` callback.
2. The test adds a generic framework for creating a mock cli server.
   This should be used in future tests.
@aeisenberg
Copy link
Contributor Author

Adding @edoardopirovano as a reviewer since he is already familiar with this area.

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.

void this.tryOpenExternalFile(
query.csvPath
);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be displaying an error in the else case here? I see we reject() where we were previously using showAndLogErrorMessage() but as far as I can tell we are then swallowing that error.

Copy link
Contributor

Choose a reason for hiding this comment

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

@aeisenberg I don't think you've addressed this comment. It's less blocking the other others, so I'm happy to approve without any changes here if you don't think any changes are needed, but just checking it wasn't missed accidentally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh...sorry. I forgot to comment here. The error is not being swallowed. Take a look at commandRunnerWithProgress, you can see that there is an error barrier there that catches and logs all thrown and rejected errors. So, you don't ever need to explicitly catch and log an error when you're inside a command as long as that command is wrapped in commandRunnerWithProgress.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And, indeed, when I try this out, forcing an error inside of exportCsvResults, the error is logged appropriately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for the explanation 🙂

bqrsInfo: [{ 'result-sets': [{ name: resultSetName }, { name: 'hucairz' }] }],
bqrsDecode: [{
columns: [{ kind: 'NotString' }, { kind: 'String' }],
tuples: [['a', 'b'], ['c', 'd']],
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's expand the tuples here to include some quote characters and make sure those get escaped correctly.

@aeisenberg
Copy link
Contributor Author

@edoardopirovano can I get another look?

Copy link
Contributor

@edoardopirovano edoardopirovano left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for addressing my comments!

@aeisenberg aeisenberg merged commit d061634 into main Jun 20, 2022
@aeisenberg aeisenberg deleted the aeisenberg/fix-bqrs-decode branch June 20, 2022 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complexity: Low A good task for newcomers to learn, or experienced team members to complete quickly.
Projects
None yet
2 participants