This repository was archived by the owner on Aug 29, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 274
DB Connector for data.world #332
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e2b1f32
Add data.world to dialect selector
kndungu 08d7785
Add data.world fields
kndungu 5858033
Add data.world sample credentials
kndungu 1d18c4e
Connect data.world
kndungu dc46f92
Connect to data.world with credentials
kndungu 313e110
Add data.world tab text
kndungu f693cf5
Add editor to data world connector
kndungu 84b933b
Display tables in data world dataset
kndungu 831d33a
[WIP] Get schema of each table in dataset
kndungu 842132e
Rename id to identifier to prevent a clash
kndungu b27d62c
Finish adding UI changes
kndungu 5473fde
Implement tables function
kndungu e9535d6
Retrieve table schemas
kndungu 742ae69
Implement schema function
kndungu 5ff119d
Implement query function
kndungu 11fae2e
Replace - with _ on queries
kndungu e0424ee
Use query to get all tables
kndungu a18eee4
Remove redundant code
kndungu 78ab1e0
Use dataset URL
kndungu 1c7b19d
Get tab label from provided URL
kndungu 5b58e41
Change sample dataset URL
kndungu 3148d22
Update text on connection tab
kndungu 69a73b5
Get database name from supplied URL
kndungu 4f44902
Add preview query
kndungu 3d1b53c
Error handling
kndungu 9b510f9
Use single API call in schema function
kndungu 17fb8e6
Add a user agent to all API requests
kndungu 563112f
Remove duplicate code
kndungu a0d7021
Add data.world tests
kndungu 4805508
Specify type of token
kndungu 87ff849
Remove unnecessary promises
kndungu 2fbc1d5
Replace dashes in tables and schemas function
kndungu 1350ec8
Return promise in connect test case
kndungu 1ab33e8
Return promise in all data.world test cases
kndungu 04ad51a
Add data.world test script
kndungu de82e14
Update filename
kndungu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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,111 @@ | ||
| import fetch from 'node-fetch'; | ||
| import url from 'url'; | ||
|
|
||
| import Logger from '../../logger'; | ||
|
|
||
| function parseUrl(datasetUrl) { | ||
| const pathnameArray = url.parse(datasetUrl).pathname.split('/'); | ||
| return { | ||
| owner: pathnameArray[1], | ||
| id: pathnameArray[2] | ||
| }; | ||
| } | ||
|
|
||
| export function connect(connection) { | ||
| const { owner, id } = parseUrl(connection.url); | ||
| return fetch(`https://api.data.world/v0/datasets/${owner}/${id}/`, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Authorization': `Bearer ${connection.token}`, | ||
| 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', | ||
| 'User-Agent': `Falcon/Plotly - ${process.env.npm_package_version}` | ||
| } | ||
| }) | ||
| .then(res => res.json()) | ||
| .then(json => { | ||
| // json.code is defined only when there is an error | ||
| if (json.code) { | ||
| throw new Error(JSON.stringify(json)); | ||
| } | ||
| }) | ||
| .catch(err => { | ||
| Logger.log(err); | ||
| throw err; | ||
| }); | ||
| } | ||
|
|
||
| export function tables(connection) { | ||
| return query('SELECT * FROM Tables', connection).then((res) => { | ||
| const allTables = res.rows.map((table) => { | ||
| return table[0].replace(/-/g, '_'); | ||
| }); | ||
|
|
||
| return allTables; | ||
| }) | ||
| .catch(err => { | ||
| Logger.log(err); | ||
| throw err; | ||
| }); | ||
| } | ||
|
|
||
| export function schemas(connection) { | ||
| return query('SELECT * FROM TableColumns', connection).then((res) => { | ||
| const rows = res.rows.map((table) => { | ||
| const tableName = table[0].replace(/-/g, '_'); | ||
| const columnName = table[3]; | ||
| // Extract the datatype from datatype url e.g. http://www.w3.org/2001/XMLSchema#integer | ||
| const columnDataType = /#(.*)/.exec(table[6])[1]; | ||
|
|
||
| return [ | ||
| tableName, | ||
| columnName, | ||
| columnDataType | ||
| ]; | ||
| }); | ||
|
|
||
| return ({ | ||
| columnNames: [ 'tablename', 'column_name', 'data_type' ], | ||
| rows | ||
| }); | ||
| }) | ||
| .catch(err => { | ||
| Logger.log(err); | ||
| throw err; | ||
| }); | ||
| } | ||
|
|
||
| export function query(queryString, connection) { | ||
| const { owner, id } = parseUrl(connection.url); | ||
| const params = `${encodeURIComponent('query')}=${encodeURIComponent(queryString)}`; | ||
|
|
||
| return fetch(`https://api.data.world/v0/sql/${owner}/${id}?includeTableSchema=true`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Authorization': `Bearer ${connection.token}`, | ||
| 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', | ||
| 'User-Agent': `Falcon/Plotly - ${process.env.npm_package_version}` | ||
| }, | ||
| body: params | ||
| }) | ||
| .then(res => { | ||
| return res.json(); | ||
| }) | ||
| .then(json => { | ||
| const fields = json[0].fields; | ||
| const columnnames = fields.map((field) => { | ||
| return field.name; | ||
| }); | ||
| const rows = json.slice(1).map((row) => { | ||
| return Object.values(row); | ||
| }); | ||
|
|
||
| return ({ | ||
| columnnames, | ||
| rows | ||
| }); | ||
| }) | ||
| .catch(err => { | ||
| Logger.log(err); | ||
| throw err; | ||
| }); | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| "test-unit-all-watch": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --bail --full-trace --timeout 90000 --compilers js:babel-register --recursive test/**/*.spec.js --watch", | ||
| "test-unit-watch": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --bail --full-trace --timeout 90000 --watch --compilers js:babel-register ", | ||
| "test-unit-certificates": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/certificates.spec.js", | ||
| "test-unit-dataworld": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.dataworld.spec.js", | ||
| "test-unit-ibmdb": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.ibmdb.spec.js", | ||
| "test-unit-impala": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.impala.spec.js", | ||
| "test-unit-livy": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.livy.spec.js", | ||
|
|
@@ -168,6 +169,7 @@ | |
| "json-loader": "^0.5.4", | ||
| "minimist": "^1.2.0", | ||
| "mkdirp": "^0.5.1", | ||
| "nock": "^9.1.5", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To help with testing, could you add a script to test only this connector, i.e.: "test-unit-dataworld": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.dataworld.spec.js" |
||
| "node-fetch": "^1.7.2", | ||
| "node-impala": "^2.0.4", | ||
| "plotly.js": "^1.31.2", | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to change this. Instead of having the user to input an URL and the connector to parse the URL to determine
ownerand datasetid. I'd like the user to inputownerandid:getPathNames)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @n-riesco, unless you feel strongly about this, we would like to use the URL. That would be consistent with our other connectors work (e.g. Tableau and Google Data Studio) and is more usable, as users only have one value to copy and paste, which is readily available on the browser for the dataset they are looking at. We do a little bit of extra work in code to spare the user in real life. Also, using URIs that contain information to parse out isn't without a precedent, the most common is JDBC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't feel strongly about it.
@tarzzz @chriddyp are you OK with using an URL here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a good reason to me 👍