Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

CSV connector #375

Merged
merged 2 commits into from
Feb 21, 2018
Merged

CSV connector #375

merged 2 commits into from
Feb 21, 2018

Conversation

n-riesco
Copy link
Contributor

const connectionData = {};

// define type error thrown by this connector
export function CSVError(url, errors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You created your own CSV Error with specific information. I am just trying to clarify why you needed your own error type. How will this be handled on the client?

@shannonlal
Copy link
Contributor

@n-riesco I did a review this and everything looks good with the exception of creating your own error. I just wanted to better understand this and how these errors will be displayed to the client.

@n-riesco
Copy link
Contributor Author

@shannonlal At the moment, the frontend only shows error.message.

The reason I defined a new error type was because papaparse returns a list of errors and line numbers (and I wanted to keep track of them). At the moment, I'm setting error.message to errors[0].message, but this may change in the future.

I don't know yet if I'm going to stick to papaparse, because it fails to parse many CSV files I've tested (I'm still fiddling with the settings).

The PR is still work in progress. It works, but it still has a few rough corners.

* This connector takes a URL as input, downloads the URL and parses it
  as a CSV file into a Javascript object that can be queried using
  alaSQL.

* Added test specs and the script `test-unit-csv` to run them.

* Updated `Setting.react.js` so that future connectors don't need to
  update it (updated `NEW_CONNECTION.md` accordingly).

* TODO (in future PRs):
  - `papaparse` parses CSV data only into numbers and strings. Add
     option to let the user set a date format for parsing.
  - let the user assign a table name
  - let the user upload multiple CSV files

Closes plotly#349
@n-riesco n-riesco changed the title [WIP] CSV connector CSV connector Feb 16, 2018
@n-riesco
Copy link
Contributor Author

@shannonlal I've just fixed the last few rough corners with this PR. I think the PR is ready for review. Would you like to review it?

@shannonlal
Copy link
Contributor

@n-riesco Yes I will have time to look this over on the weekend

Copy link
Contributor

@shannonlal shannonlal left a comment

Choose a reason for hiding this comment

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

All the comments I added are small and minor. Everything looks good it was just some minor suggestions. I think it is ready for a dancer. Just let me know if you think my changes make sense or if you want to merge the changes as is.

if (cell) return type(cell);
}

return 'String';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just add a quick comment to explain that default is string. Or add to JSDocs to function

CSVError.prototype.constructor = CSVError;

// the data parsed from CSV files is stored here
const connectionData = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

In #362 One of the comments was to start using JSDocs style for our code. Should we be doing this on the backend as well?

connectionData[connection.database] = data;
}

export function connect(connection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the url is bad, how will this be presented to the user on the Settings UI? will fetch throw an error and this will be gracefully passed to the UI on its own?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same behaviour for all the connectors, i.e.: fetch throws, routes.js catches the exception and replies to the connection request with a 500 status and the body {error: message: error.message}}.


export function tables() {
// To take advantage of alaSQL's parser, the table is named '?'
return Promise.resolve(['?']);
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 using '?' or a const CSV_TABLE_NAME = '?'. This way if it changes in the future you don't have to string replace to make sure we find all changes

@n-riesco n-riesco merged commit bb661bc into plotly:master Feb 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants