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

Filter by single value does not work #67

Open
domoritz opened this issue Dec 19, 2024 · 2 comments
Open

Filter by single value does not work #67

domoritz opened this issue Dec 19, 2024 · 2 comments

Comments

@domoritz
Copy link
Collaborator

If there is a unique value, the profile shows it but when I click on it, the matching row is not shown.

Screenshot 2024-12-19 at 16 17 28
@manzt
Copy link
Owner

manzt commented Dec 20, 2024

Oh, interesting! This is an edge case I hadn't considered. I'm wondering how we could make the "unique" bar more generally selectable (not just for one value).

Right now the query for the "value counts" is a bit convoluted. I tried to push down the aggregation of uniqueness to duckdb so I'd return fewer entries to the client (e.g., in the case where the data is large and all values are unique).

override query(filter: Array<SQLExpression> = []): Query {
let counts = Query
.from({ source: this.#table })
.select({
value: sql`CASE
WHEN ${column(this.#column)} IS NULL THEN '__quak_null__'
ELSE ${column(this.#column)}
END`,
count: count(),
})
.groupby("value")
.where(filter);
return Query
.with({ counts })
.select(
{
key: sql`CASE
WHEN "count" = 1 AND "value" != '__quak_null__' THEN '__quak_unique__'
ELSE "value"
END`,
total: sum("count"),
},
)
.from("counts")
.groupby("key");
}

So right now, the table I get back from duckdb looks like:

[{ "key": "A", "total": 500 }, { "key": "C", "total" 20" }, { "key": "__quak_unique__", "total": 1 }]

This structure means the client doesn't have direct access to the actual unique values.

I’m wondering whether we could rethink the approach to selecting unique values, making them more broadly selectable rather than limited to just a single unique value. For instance, we could use a predicate to exclude values like "A" and "C," allowing the "unique" bar to represent a broader, more flexible selection. Curious what you think.

@domoritz
Copy link
Collaborator Author

You could filer to the unique values with something like this maybe:

SELECT column_name
FROM table_name
GROUP BY column_name
HAVING COUNT(*) = 1;

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

No branches or pull requests

2 participants