Repository navigation
Conversation
formatSqlPredicate (the formatSqlFilter=true path of genTableCode) interpolated partition values into a SQL string with no escaping, so a value containing a single quote produced invalid SQL, an embedded double quote broke out of the surrounding Python string early, contains values with '%'/'_' were silently treated as LIKE wildcards, in/not in list values rendered via JavaScript's Array.toString() (e.g. 'id in 1,2' instead of 'id in (1, 2)'), and quoting only triggered when type_annotation was exactly 'str'/'string' rather than by the value's actual runtime type. Fixes neuralinkcorp#77. The non-SQL Filter(...) snippet path (formatFilterValue) is a different function and already has its own fix in PR neuralinkcorp#73; this is scoped to the SQL-string path only.
Contributor
Author
|
Friendly check-in — this has been open a couple of days with only automated review so far. Let me know if anything needs adjusting. |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #77.
The
formatSqlFilter: truepath ofgenTableCode(formatSqlPredicateinsrc/datarepo/export/static_site/src/lib/codegen.ts) interpolated partition values into a SQL string with no escaping:O'Brien) produced invalid SQL:name = 'O'Brien'.filters="name = 'say "hi"'".containsvalues containing%or_were silently treated asLIKEwildcards instead of literal characters.in/not inlist values rendered via JavaScript'sArray.toString():id in 1,2instead ofid in (1, 2).type_annotationwas exactly"str"/"string", so alarge_stringor date-typed string value came out unquoted.This is the SQL-string snippet path specifically. The non-SQL
Filter(...)snippet path (formatFilterValue) is a different function with its own open fix in #73; this PR doesn't touch it.Changes
escapeSqlString: doubles embedded'(standard SQL string-literal escaping).escapeSqlLikeValue: additionally escapes\,%,_forcontains, paired with an explicitESCAPE '\'clause.in/not innow render list values as a proper(a, b, c)tuple, with each element quoted/escaped individually.typeof value === 'string'), not justtype_annotation.filters="..."argument is now produced viaJSON.stringify, which yields a valid Python double-quoted string literal for any content (Python accepts the same\",\,\uXXXXescapes JSON does), instead of raw string interpolation.ExportedTablePartition.value's type to include array values, sincein/not inpartitions already carry one at runtime (the pre-fixArray.toString()behavior is direct evidence of this; the type was just stale).Test plan
test/export/test_sql_filter_codegen.pycompiles the realcodegen.ts/types.tsviatscand executes the compiled JS, covering all 5 examples from Catalog site: SQL-style code snippet does not escape filter values #77 plus anis nullregression check (7 cases total).mainby running the identical test suite against the pre-fix compiled code: all 6 content-bearing cases fail there with exactly the symptoms described in Catalog site: SQL-style code snippet does not escape filter values #77 (confirmed via a local script, not included in the PR).tsc --strictcompiles clean.black --checkclean on the new test file.test/export/andtest/tables/suites locally; no regressions (some pre-existing, unrelated failures on this Windows dev environment: Windows path-separator mismatches intest_parquet_table.py/test_parquet_pruning_or.py, and adeltalake/arro3version mismatch intest_deltalake_table.py— neither touches code this PR changes).