Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Database Visualizations #1335

Merged
merged 18 commits into from
Mar 25, 2021
Merged

Database Visualizations #1335

merged 18 commits into from
Mar 25, 2021

Conversation

radeusgd
Copy link
Member

@radeusgd radeusgd commented Mar 16, 2021

Pull Request Description

Implements visualizations for the Database library:

  • the Table visualization is enhanced to be able to automatically materialize database tables (so now it supports both dataframes and databases).
    • It also limits the output to at most 1000 elements and displays the count of hidden elements below the table.
  • the SQL visualization that pretty prints the query with interpolated values.

Important Notes

Checklist

Please include the following checklist in your PR:

  • The CHANGELOG.md was updated with the changes introduced in this PR.
  • The documentation has been updated if necessary.
  • All code conforms to the Rust style guide.
  • All code has automatic tests where possible.
  • All code has been profiled where possible.
  • All code has been manually tested in the IDE.
  • All code has been manually tested in the "debug/interface" scene.
  • All code has been manually tested by the PR owner against our test scenarios.
  • All code has been manually tested by at least one reviewer against our test scenarios.

@radeusgd radeusgd added Difficulty: Core Contributor Should only be attempted by a core contributor Priority: High Should be scheduled as soon as possible Type: Enhancement An enhancement to the current state of Enso IDE Category: Visualizations Visualizations embedded in Enso IDE labels Mar 16, 2021
@radeusgd radeusgd self-assigned this Mar 16, 2021
@radeusgd
Copy link
Member Author

radeusgd commented Mar 16, 2021

Below we can see an example with some filtering applied to the table. The Table visualization displays the materialized results:
image

Alternatively we can switch to the SQL visualization which shows the query that will be used to compute the results:
image

The interpolated values that come from Enso are highlighted and their color is based on their type (currently only basic types are supported and that is inferred from their Enso type, not from SQL - we have access to the SQL type so maybe we should switch to that - the only issue is that the representation of SQL types is based on implementation-defined numeric identifiers for each type which I didn't want to hardcode, but if we want to switch to this, I could approximate the datatype name on the backend side and send it as text to the visualization).

Note for clarity: the jdbc: prefix when opening a DB connection is not necessary, skipping it will also work.

@wdanilo
Copy link
Member

wdanilo commented Mar 17, 2021

Looks cool. Let's have a video call with @sylwiabr to see how it works and to chat about missing things. Great job with that!

@radeusgd radeusgd force-pushed the wip/rw/database-visualizations branch from dd2254b to 66d4094 Compare March 18, 2021 16:20
@radeusgd radeusgd marked this pull request as ready for review March 18, 2021 22:51
@radeusgd radeusgd requested a review from wdanilo as a code owner March 18, 2021 22:51
@wdanilo
Copy link
Member

wdanilo commented Mar 19, 2021

We are waiting for this to be finished.

@wdanilo wdanilo marked this pull request as draft March 19, 2021 09:05
@radeusgd radeusgd force-pushed the wip/rw/database-visualizations branch 2 times, most recently from 090dd8c to ca98458 Compare March 23, 2021 16:38
@radeusgd radeusgd marked this pull request as ready for review March 23, 2021 22:45
loadScript('https://cdnjs.cloudflare.com/ajax/libs/sql-formatter/4.0.2/sql-formatter.min.js')

class SqlVisualization extends Visualization {
static inputType = 'Any' // 'Standard.Database.Data.Table.Table | Standard.Database.Data.Column.Column' // TODO change this once sum types are properly supported
Copy link
Member

Choose a reason for hiding this comment

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

  1. Too long line, max 100 chars everywhere - apply to ALL files
  2. In comments always add links to issues describing them.
  3. Comments should be valid english sentences. missing dot

Apply to all your code.

this.setPreprocessorModule('Standard.Visualization.Sql.Visualization')
this.setPreprocessorCode(`x -> here.prepare_visualization x`)

// mock theme
Copy link
Member

Choose a reason for hiding this comment

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

comments should be valid sentences. Also, they should be understandable by people not familiar with codebase, thisdefinitely is not. It needs to describe why it is a mock and what issue it is waiting for with a link to the issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

This mock theme will be removed anyway before the PR is merged, as we discussed that this PR should be merged after #1337

Comment on lines 97 to 104
function splitTypeName(name) {
var ix = name.lastIndexOf('.')
if (ix < 0) {
return ['', name]
}

return [name.substr(0, ix + 1), name.substr(ix + 1)]
}
Copy link
Member

Choose a reason for hiding this comment

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

all these functions should have comments describing their behavior. Or better naming. If I see name splitTypeName I do not understand what does it do - split from what, into what? Better naming is preferred. IF its not possible, musch better and detailed docs. Thesame applies to other functions, like a super-long function rendeParameter. Its namedoesnt tell anything about what it does, and is looks complex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comments and changed names a bit.


const actualTypeColor = theme.getColorForType(actualType)
const fgColor = actualTypeColor
let bgColor = [...fgColor.slice(0, 3), bgAlpha]
Copy link
Member

Choose a reason for hiding this comment

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

magic numbers. Do not use literals like that. Extract them to well named variables. You can use 0 as it means start, but 3 is magical

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I changed this to const baseChannels = 3 since that 3 represents the RGB channels that are kept when changing opacity; it's also now a separate function so it is easier to see what it does.

I assume that I can use 2 without treating it like a magic number when I'm dividing things by two, right? (Like I want to compute the middle of something, so I have width / 2)

@wdanilo
Copy link
Member

wdanilo commented Mar 24, 2021

I'm not sure regarding the code quality - the functions are super long, lack of docs in many places, long expressions are not split into variables etc. I would like @farmaazon to review it from a perspective of someone that does not know what this code does and leave comments - this code should be understandable to every reader easily, without browisng connected code - the logic should be easy to follow. I feel it is not. Ada, would you mind looking at it please?

@radeusgd
Copy link
Member Author

I'm not sure regarding the code quality - the functions are super long, lack of docs in many places, long expressions are not split into variables etc. I would like @farmaazon to review it from a perspective of someone that does not know what this code does and leave comments - this code should be understandable to every reader easily, without browisng connected code - the logic should be easy to follow. I feel it is not. Ada, would you mind looking at it please?

I think I could refactor it a bit to make the functions a bit smaller and add docs before a re-review?

@radeusgd radeusgd force-pushed the wip/rw/database-visualizations branch 2 times, most recently from 13c2f7b to 9849cd7 Compare March 24, 2021 13:56
@radeusgd radeusgd requested a review from wdanilo March 24, 2021 14:12
@radeusgd
Copy link
Member Author

radeusgd commented Mar 24, 2021

Some screenshots on what the visualizations look like:

@radeusgd radeusgd force-pushed the wip/rw/database-visualizations branch from 05b2eb2 to 117ba73 Compare March 24, 2021 18:32
@radeusgd
Copy link
Member Author

Thanks to #1337 we now have proper colors!

Copy link
Member

@wdanilo wdanilo left a comment

Choose a reason for hiding this comment

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

This code is MUCH nicer. I was able to create a proper review of it now! Few inor things, Im accepting it. After fixing them, feel free to merge it <3

CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines +42 to +118
const formatted = sqlFormatter.format(parsedData.code, {
params: params,
language: language,
})
Copy link
Member

Choose a reason for hiding this comment

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

this line would probably fail if parsedData is for example undefined, null, or a number. We should make our visualizations as error prone as possible, so please, make more checks regarding the input data!

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, parsedData is what is returned by the visualization preprocessor which is controlled by the visualization itself, so I think we have control over what parsedData should look like.

@radeusgd radeusgd force-pushed the wip/rw/database-visualizations branch from f159037 to 69178f7 Compare March 25, 2021 14:54
@radeusgd radeusgd merged commit 132ae3e into develop Mar 25, 2021
@radeusgd radeusgd deleted the wip/rw/database-visualizations branch March 25, 2021 16:03
mwu-tow pushed a commit to enso-org/enso that referenced this pull request Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Category: Visualizations Visualizations embedded in Enso IDE Difficulty: Core Contributor Should only be attempted by a core contributor Priority: High Should be scheduled as soon as possible Type: Enhancement An enhancement to the current state of Enso IDE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants