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

SQL examples draft #158

Merged
merged 2 commits into from
Nov 30, 2022
Merged

SQL examples draft #158

merged 2 commits into from
Nov 30, 2022

Conversation

pdobacz
Copy link
Collaborator

@pdobacz pdobacz commented Nov 30, 2022

Part of #77. I didn't test these, nor I don't know how do they present.

Edon: Feel free to just plug this into your scaffolding, and once this is somewhat working, I can pick up again and start polishing the looks and rules.

@pdobacz pdobacz requested a review from edongashi November 30, 2022 12:40
function rawGroupBySQL(column: string, table: string, displayName: string): ExampleInfo {
return {
name: `${displayName} by ${column}`,
sql: lines(`SELECT ${postgresQuote(column)}`, `FROM ${postgresQuote(table)}`),
Copy link
Member

Choose a reason for hiding this comment

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

Is GROUP BY clause missing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, lost in refactors

function countDistinctSQL(column: string, table: string): ExampleInfo {
return {
name: `Distinct ${column}`,
sql: lines(`SELECT count(distinct ${postgresQuote(column)}) as distinct_${column}`, `FROM ${postgresQuote(table)}`),
Copy link
Member

Choose a reason for hiding this comment

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

Do we handle quoting of this? If so, we might get distinct_"some col"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I checked mb reports the table unquoted here, so we should be fine. I'll check again

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unquoted, but I have to prevent distinct_some col, I'll fix this

Copy link
Member

Choose a reason for hiding this comment

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

I'll fix this

Let's fix bugs in a future PR. I want to synchronize and experiment often.

edongashi
edongashi previously approved these changes Nov 30, 2022
Comment on lines +78 to +92
try {
if (field.semantic_type === 'type/PK' || field.database_type === 'serial') {
// No sensible example for columns being just row IDs.
return [];
} else if (aidColumns.includes(field.name)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd split (in a future revision) all these into their own function, i.e. aidColumnExamples, numericColumnExamples, textColumnExamples, etc.

Also a future idea is to get some columns with very few distinct values and try grouping by 2 columns. If the values are distributed enough we might get non-suppressed results.

@pdobacz pdobacz merged commit 1370379 into master Nov 30, 2022
@pdobacz pdobacz deleted the piotr/build-example-sqls branch November 30, 2022 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants