-
Notifications
You must be signed in to change notification settings - Fork 343
feat: add map contains when map used #1497
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
Conversation
🦋 Changeset detectedLatest commit: 6fed8ca The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Code Review
Critical Issues
-
SQL Injection vulnerability in renderChartConfig.ts:510 - Map keys are not escaped before string interpolation. Use backticks or proper SQL escaping for mapName and escape quotes in keyName
-
Feature flag logic error in renderChartConfig.ts:15-17 - || operator causes optimization to be ALWAYS enabled (truthy in non-production). Should be: process.env.NEXT_PUBLIC_MAP_CONTAINS_OPTIMIZATION_ENABLED === 'true' || process.env.NODE_ENV !== 'production'
-
Missing null safety in renderChartConfig.ts:467 - cur.default_expression could be undefined/null for materialized columns. Add null check before .indexOf()
Important Issues
-
Inconsistent error handling in renderChartConfig.ts:378, 533 - Empty catch blocks silently swallow all errors including TypeErrors. Consider logging errors in development or catching specific parser errors only
-
Missing validation in extractIdent:319 - node.array_index[0].index.value needs type validation - should verify it's a string before using as keyName
Minor Issues
- Tests are comprehensive and cover edge cases well
- CTE detection logic is correct
- Deduplication using objectHash is appropriate
Recommendation: Fix the SQL injection and feature flag logic before merge.
E2E Test Results✅ All tests passed • 46 passed • 3 skipped • 816s
Tests ran across 4 shards in parallel. |
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.
These cases never ran it through the sql parser previously, so the sql parser just capitalizes a few things. Otherwise the tests didn't change
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.
just case changes
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.
Builds ast, traverses extracting each ident, adds mapContains to the ast if the proper conditions are met, and builds back into sql
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.
Either a column or map, we want both since a materialized column could be a map key optimization in disguise
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 allows us to add mapContains even if that map entry is materialized, which is advantageous to still use the map key index
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'm not sure if the materialized field would be beneficial from this optimization. but good to know
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.
style: better to follow the pattern like (process.env.NEXT_PUBLIC_MAP_CONTAINS_OPTIMIZATION_ENABLED ?? 'false') === 'true'
and move it to config.ts
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.
perf: We can move this out of the method, and we don’t need to traverse the AST if it’s empty. Also maps is a bit ambiguous, maybe mapFieldNames ?
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.
Should we log errors during development for debugging purposes?
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.
style: We can probably move this function out instead of manipulating the AST directly
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 suggest removing this (in case somehow NODE_ENV is not set properly in prod) and add NEXT_PUBLIC_MAP_CONTAINS_OPTIMIZATION_ENABLED to your .env.local instead
Closes HDX-3070
Adding
mapContainsallows a bloom filter index to be used to not search a granule if a key for a given map is not present in that granule. In some testing I've done it yielded 40% less rows scanned