diff --git a/coverage/translation-databricks/README.md b/coverage/translation-databricks/README.md index bdd1ad30f..d574d1d55 100644 --- a/coverage/translation-databricks/README.md +++ b/coverage/translation-databricks/README.md @@ -17,6 +17,10 @@ file lists only what differs. - `not-translatable.toml`: forms with no meaningful DuckDB translation, in groups, each with its reason. A group leaves the denominator only once `reviews/results.toml` signs off its reason and forms by SHA-256. +- `declared-refusals.toml`: the statements a loud divergence makes DuckDB raise on where Databricks + returned rows, one group per divergence. A group sets its statements aside from its forms' state + only once `reviews/results.toml` signs it off as `declared-refusal:`; until then those forms + stay `refused`. - `obligations/functions.toml`: one obligation per generated type-combination, NULL-argument and error-parity case of a live catalogue form, written from the cases' tags by `scripts/build_translation_obligations_databricks.py`; `make translation-files` fails when the diff --git a/coverage/translation-databricks/declared-refusals.toml b/coverage/translation-databricks/declared-refusals.toml new file mode 100644 index 000000000..cba20950e --- /dev/null +++ b/coverage/translation-databricks/declared-refusals.toml @@ -0,0 +1,72 @@ +# Statements a declared divergence makes DuckDB raise on where Databricks returned rows, each raise +# the converted SQL's loud failure in place of a wrong value. A group sets its statements aside from +# its forms' state once a reviewer signs it off in reviews/results.toml. + +[[declared]] +id = "collect-list-order" +divergence = "collect_list_order" +reason = "COLLECT_LIST and ARRAY_AGG return values in the order rows arrive, which neither engine defines; the converted SQL raises where the array holds several distinct values rather than return them in another order." +statements = [ + "translation/functions/array-agg.toml#t001_types_1", + "translation/functions/array-agg.toml#t002_types_2", + "translation/functions/collect-list.toml#t001_types_1", + "translation/functions/collect-list.toml#t002_types_2", +] + +[[declared]] +id = "first-last-order" +divergence = "first_last_order" +reason = "FIRST, LAST and ANY_VALUE return the value of a row neither engine orders; the converted SQL raises where the group gives several values rather than pick another one." +statements = [ + "translation/functions/any-value.toml#t001_types_1", + "translation/functions/any-value.toml#t002_types_2", + "translation/functions/first-value.toml#t001_types_1", + "translation/functions/first-value.toml#t002_types_2", + "translation/functions/first.toml#t001_types_1", + "translation/functions/first.toml#t002_types_2", + "translation/functions/last-value.toml#t001_types_1", + "translation/functions/last-value.toml#t002_types_2", + "translation/functions/last.toml#t001_types_1", + "translation/functions/last.toml#t002_types_2", +] + +[[declared]] +id = "float-sum-order" +divergence = "float_sum_order" +reason = "Databricks adds DOUBLE values in an order DuckDB does not share; the converted SQL raises where the order of addition could change the sum rather than return a different total." +statements = [ + "translation/functions/avg.p2b.hand.toml#p001", + "translation/functions/sum.pa.hand.toml#p001", + "translation/functions/sum.pa.hand.toml#p002", + "translation/functions/sum.pa.hand.toml#p003", + "translation/functions/try-sum.pa.hand.toml#p001", + "translation/functions/try-sum.pa.hand.toml#p002", + "translation/functions/try-sum.pa.hand.toml#p003", +] + +[[declared]] +id = "regex-column-pattern" +divergence = "regex_column_pattern" +reason = "Java and RE2 read some metacharacters apart; the converted SQL raises for a pattern column holding one rather than match it another way." +statements = [ + "translation/functions/rlike.p2.hand.toml#p001", + "translation/functions/rlike.p2.hand.toml#p002", + "translation/functions/rlike.p2.hand.toml#p003", + "translation/functions/rlike.p2.hand.toml#p004", +] + +[[declared]] +id = "to-binary-odd-hex" +divergence = "to_binary_odd_hex" +reason = "Databricks reads an odd count of hex digits in a way no rule explains; the converted SQL raises for one rather than return other bytes." +statements = [ + "translation/functions/to-binary.pc.hand.toml#p003", +] + +[[declared]] +id = "url-decode-invalid-utf8" +divergence = "url_decode_invalid_utf8" +reason = "Databricks decodes escapes that are not UTF-8 to the replacement character, where DuckDB's url_decode raises; the raise is the failure rather than other text." +statements = [ + "translation/functions/url-decode.pb.hand.toml#p002", +] diff --git a/coverage/translation-databricks/form-links.toml b/coverage/translation-databricks/form-links.toml index d602de227..08921a1d6 100644 --- a/coverage/translation-databricks/form-links.toml +++ b/coverage/translation-databricks/form-links.toml @@ -359,6 +359,10 @@ forms = ["db.functions.in.in.syntax"] constructs = ["node:in"] forms = ["db.functions.in.in.syntax"] +[[link]] +constructs = ["spelling:in_subquery"] +forms = ["db.functions.in.in-2"] + [[link]] constructs = ["node:is_null"] forms = ["db.functions.isnullop"] @@ -504,6 +508,16 @@ forms = ["db.expressions.window-functions"] constructs = ["node:frame"] forms = ["db.expressions.window-functions-frame"] +# MATCH_RECOGNIZE always writes its PATTERN and DEFINE, and every recorded case its MEASURES. +[[link]] +constructs = ["node:match_recognize"] +forms = ["db.query.select-match-recognize", "db.query.select-match-recognize-define", "db.query.select-match-recognize-measures", "db.query.select-match-recognize-pattern"] + +# A window with a written frame. +[[link]] +constructs = ["spelling:window_frame"] +forms = ["db.expressions.window-functions-frame"] + # Ranking functions, and FIRST_VALUE and LAST_VALUE over a window, whose forms' grammar has no OVER # and so cannot link by call shape. @@ -720,6 +734,10 @@ reason = "A subquery in FROM is part of the table-reference and query grammar of constructs = ["node:within_group"] reason = "WITHIN GROUP belongs to the aggregate that takes it." +[[no_form]] +constructs = ["node:named_argument"] +reason = "A `name => value` argument belongs to the grammar of the function that takes it, such as SEARCH's mode." + [[no_form]] constructs = ["node:var"] reason = "A datetime unit keyword such as DAY or HOUR belongs to the grammar of the function that takes it, such as TIMESTAMPADD or DATEDIFF." diff --git a/coverage/translation-databricks/not-translatable.toml b/coverage/translation-databricks/not-translatable.toml index 0b6dfeba6..ecd88a423 100644 --- a/coverage/translation-databricks/not-translatable.toml +++ b/coverage/translation-databricks/not-translatable.toml @@ -497,3 +497,22 @@ forms = [ "db.functions.current-database", "db.functions.current-schema", ] + +[[group]] +id = "row-pattern-matching" +reason = "MATCH_RECOGNIZE matches a regular expression of row patterns over ordered partitions, with CLASSIFIER and MATCH_NUMBER naming the matched variable and match. DuckDB has no row-pattern matching, and emulating it would mean writing a pattern-matching engine into the converted SQL. The recorded cases stay as evidence of Databricks's results." +forms = [ + "db.functions.classifier", + "db.functions.match-number", + "db.query.select-match-recognize", + "db.query.select-match-recognize-define", + "db.query.select-match-recognize-measures", + "db.query.select-match-recognize-pattern", +] + +[[group]] +id = "session-time-zone" +reason = "CURRENT_TIMEZONE returns the time zone of the Databricks session, which depends on the session rather than the query. A literal of one zone, such as the 'Etc/UTC' a default warehouse session gives, would be wrong for every session in another zone, so the value cannot be converted." +forms = [ + "db.functions.current-timezone", +] diff --git a/coverage/translation-databricks/obligations/expressions.toml b/coverage/translation-databricks/obligations/expressions.toml index 786a650f7..9550431be 100644 --- a/coverage/translation-databricks/obligations/expressions.toml +++ b/coverage/translation-databricks/obligations/expressions.toml @@ -91,6 +91,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/expressions/collate-lcase.np.hand.toml#p001"] required = true +[[obligation]] +id = "db.expressions.collation.order-by-collate-utf8-lcase.t002" +form = "db.expressions.collation.order-by-collate-utf8-lcase" +kind = "type_combination" +target = "STRING" +note = "ORDER BY under UTF8_LCASE over the code points it lowers otherwise than the simple mapping, and title-case and Greek letters. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/collation.lcase-special.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.expressions.collation.order-by-lower-collate.t001" +form = "db.expressions.collation.order-by-lower-collate" +kind = "type_combination" +target = "STRING" +note = "ORDER BY LOWER of a column under UTF8_BINARY. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/collation.lower-binary.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.expressions.comment.t001" form = "db.expressions.comment" @@ -410,6 +432,17 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/expressions/names.identifier-3.pe.hand.toml#p001"] required = true +[[obligation]] +id = "db.expressions.names.identifier.syntax.t001" +form = "db.expressions.names.identifier.syntax" +kind = "type_combination" +target = "INT" +note = "a table read through IDENTIFIER. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/names.table-identifier.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.expressions.names.subscript.t001" form = "db.expressions.names.subscript" @@ -443,6 +476,17 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/expressions/names.column-aliases.pf.hand.toml#p001"] required = true +[[obligation]] +id = "db.expressions.names.syntax.t001" +form = "db.expressions.names.syntax" +kind = "type_combination" +target = "INT" +note = "a table read by its name. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/names.table.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.expressions.null-type.t001" form = "db.expressions.null-type" @@ -590,6 +634,17 @@ required = true id = "db.expressions.time-type.time.syntax.t001" form = "db.expressions.time-type.time.syntax" kind = "type_combination" +target = "TIME" +note = "a cast to TIME(3). Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/time-type.precision.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.expressions.time-type.time.syntax.t002" +form = "db.expressions.time-type.time.syntax" +kind = "type_combination" target = "STRING" note = "strings cast to TIME(3), with digits past the precision. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -777,6 +832,50 @@ required = true id = "db.expressions.window-functions-frame.t002" form = "db.expressions.window-functions-frame" kind = "type_combination" +target = "BIGINT" +note = "a RANGE offset over a BIGINT key at its end. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/window-functions-frame.range-bigint.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.expressions.window-functions-frame.t003" +form = "db.expressions.window-functions-frame" +kind = "type_combination" +target = "INT" +note = "RANGE offsets over an INT key ascending and descending, and at INT's ends, where the bound passes the type. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/window-functions-frame.range-bounds.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.expressions.window-functions-frame.t004" +form = "db.expressions.window-functions-frame" +kind = "type_combination" +target = "INT" +note = "RANGE offsets over an INT key ascending and descending, and at INT's ends, where the bound passes the type. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/window-functions-frame.range-bounds.pa.hand.toml#p002"] +required = true + +[[obligation]] +id = "db.expressions.window-functions-frame.t005" +form = "db.expressions.window-functions-frame" +kind = "type_combination" +target = "INT" +note = "RANGE offsets over an INT key ascending and descending, and at INT's ends, where the bound passes the type. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/expressions/window-functions-frame.range-bounds.pa.hand.toml#p003"] +required = true + +[[obligation]] +id = "db.expressions.window-functions-frame.t006" +form = "db.expressions.window-functions-frame" +kind = "type_combination" target = "INT" note = "a RANGE frame of one either side over ties and a NULL. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -785,7 +884,7 @@ cases = ["cases/translation/expressions/window-functions-frame.range.pt.hand.tom required = true [[obligation]] -id = "db.expressions.window-functions-frame.t003" +id = "db.expressions.window-functions-frame.t007" form = "db.expressions.window-functions-frame" kind = "type_combination" target = "INT, STRING, INT" diff --git a/coverage/translation-databricks/obligations/functions.toml b/coverage/translation-databricks/obligations/functions.toml index 0aafc9763..8bee640ce 100644 --- a/coverage/translation-databricks/obligations/functions.toml +++ b/coverage/translation-databricks/obligations/functions.toml @@ -4045,6 +4045,39 @@ id = "db.functions.bitmap-construct-agg.t001" form = "db.functions.bitmap-construct-agg" kind = "type_combination" target = "INT" +note = "bitmap_construct_agg over no rows. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/bitmap-construct-agg.empty.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.bitmap-construct-agg.t002" +form = "db.functions.bitmap-construct-agg" +kind = "type_combination" +target = "BIGINT" +note = "bitmap_construct_agg of bitmap_bit_position by bucket, counted. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/bitmap-construct-agg.positioned.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.bitmap-construct-agg.t003" +form = "db.functions.bitmap-construct-agg" +kind = "type_combination" +target = "INT" +note = "bitmap_construct_agg of bit positions from 0 to 32767, one repeated. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/bitmap-construct-agg.positions.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.bitmap-construct-agg.t004" +form = "db.functions.bitmap-construct-agg" +kind = "type_combination" +target = "INT" note = "bitmap-construct-agg with arguments of type INT." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" @@ -4052,7 +4085,7 @@ cases = ["cases/translation/functions/bitmap-construct-agg.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.bitmap-construct-agg.t002" +id = "db.functions.bitmap-construct-agg.t005" form = "db.functions.bitmap-construct-agg" kind = "type_combination" target = "BIGINT" @@ -4063,7 +4096,7 @@ cases = ["cases/translation/functions/bitmap-construct-agg.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.bitmap-construct-agg.t003" +id = "db.functions.bitmap-construct-agg.t006" form = "db.functions.bitmap-construct-agg" kind = "type_combination" target = "SMALLINT" @@ -4074,7 +4107,7 @@ cases = ["cases/translation/functions/bitmap-construct-agg.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.bitmap-construct-agg.t004" +id = "db.functions.bitmap-construct-agg.t007" form = "db.functions.bitmap-construct-agg" kind = "null_argument" target = "INT" @@ -4085,7 +4118,7 @@ cases = ["cases/translation/functions/bitmap-construct-agg.toml#t004_null_1"] required = true [[obligation]] -id = "db.functions.bitmap-construct-agg.t005" +id = "db.functions.bitmap-construct-agg.t008" form = "db.functions.bitmap-construct-agg" kind = "error_parity" target = "STRING" @@ -4821,6 +4854,61 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/case.end.syntax.toml#t010_wrong_kind"] required = true +[[obligation]] +id = "db.functions.cast.t001" +form = "db.functions.cast" +kind = "type_combination" +target = "DECIMAL(10,2)" +note = "a cast of DECIMAL to BIGINT, truncating. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/cast.decimal-bigint.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.cast.t002" +form = "db.functions.cast" +kind = "type_combination" +target = "INT" +note = "a cast of INT to STRING. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/cast.int-string.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.cast.t003" +form = "db.functions.cast" +kind = "error_parity" +target = "STRING" +note = "a cast of text no number reads. Hand-written for the phase-2 recording." +catches = "a value returned where Databricks rejects the arguments, or another error kind" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/cast.malformed.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.cast.t004" +form = "db.functions.cast" +kind = "null_argument" +target = "INT" +note = "a cast of NULL. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/cast.null.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.cast.t005" +form = "db.functions.cast" +kind = "type_combination" +target = "STRING" +note = "a cast of STRING to INT. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/cast.string-int.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.cbrt.t001" form = "db.functions.cbrt" @@ -5228,6 +5316,17 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/chr.toml#t007_wrong_kind"] required = true +[[obligation]] +id = "db.functions.classifier.t001" +form = "db.functions.classifier" +kind = "type_combination" +target = "INT" +note = "CLASSIFIER naming each matched row's variable. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/classifier.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.coalesce.t001" form = "db.functions.coalesce" @@ -5272,6 +5371,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/coalesce.toml#t006_wrong_kind"] required = true +[[obligation]] +id = "db.functions.collate.t001" +form = "db.functions.collate" +kind = "type_combination" +target = "STRING" +note = "a comparison under COLLATE UTF8_BINARY, case-sensitive. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/collate.binary-equal.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.collate.t002" +form = "db.functions.collate" +kind = "type_combination" +target = "STRING" +note = "COLLATE UTF8_BINARY of a STRING column. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/collate.binary.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.collation.t001" form = "db.functions.collation" @@ -5650,6 +5771,28 @@ required = true id = "db.functions.conv.t001" form = "db.functions.conv" kind = "type_combination" +target = "DOUBLE" +note = "conv of NaN and Infinity, whose letters are base-36 digits. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/conv.double-letters.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.conv.t002" +form = "db.functions.conv" +kind = "type_combination" +target = "DOUBLE" +note = "conv of DOUBLE values Java writes plainly and in scientific form, read from base 10. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/conv.double.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.conv.t003" +form = "db.functions.conv" +kind = "type_combination" target = "STRING" note = "conv from hex, with digits past the base, a negative number and empty text. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -5658,7 +5801,7 @@ cases = ["cases/translation/functions/conv.pb.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.conv.t002" +id = "db.functions.conv.t004" form = "db.functions.conv" kind = "type_combination" target = "STRING" @@ -5669,7 +5812,7 @@ cases = ["cases/translation/functions/conv.pb2.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.conv.t003" +id = "db.functions.conv.t005" form = "db.functions.conv" kind = "type_combination" target = "INT" @@ -5680,7 +5823,7 @@ cases = ["cases/translation/functions/conv.pb3.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.conv.t004" +id = "db.functions.conv.t006" form = "db.functions.conv" kind = "type_combination" target = "STRING" @@ -5691,7 +5834,7 @@ cases = ["cases/translation/functions/conv.pb4.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.conv.t005" +id = "db.functions.conv.t007" form = "db.functions.conv" kind = "type_combination" target = "INT, INT, INT" @@ -5702,7 +5845,7 @@ cases = ["cases/translation/functions/conv.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.conv.t006" +id = "db.functions.conv.t008" form = "db.functions.conv" kind = "type_combination" target = "STRING, INT, INT" @@ -5713,7 +5856,7 @@ cases = ["cases/translation/functions/conv.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.conv.t007" +id = "db.functions.conv.t009" form = "db.functions.conv" kind = "type_combination" target = "DECIMAL(10,2), INT, INT" @@ -5724,7 +5867,7 @@ cases = ["cases/translation/functions/conv.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.conv.t008" +id = "db.functions.conv.t010" form = "db.functions.conv" kind = "type_combination" target = "DOUBLE, INT, INT" @@ -5735,7 +5878,7 @@ cases = ["cases/translation/functions/conv.toml#t004_types_4"] required = true [[obligation]] -id = "db.functions.conv.t009" +id = "db.functions.conv.t011" form = "db.functions.conv" kind = "null_argument" target = "INT, INT, INT" @@ -5746,7 +5889,7 @@ cases = ["cases/translation/functions/conv.toml#t005_null_1"] required = true [[obligation]] -id = "db.functions.conv.t010" +id = "db.functions.conv.t012" form = "db.functions.conv" kind = "null_argument" target = "INT, INT, INT" @@ -5757,7 +5900,7 @@ cases = ["cases/translation/functions/conv.toml#t006_null_2"] required = true [[obligation]] -id = "db.functions.conv.t011" +id = "db.functions.conv.t013" form = "db.functions.conv" kind = "null_argument" target = "INT, INT, INT" @@ -5768,7 +5911,7 @@ cases = ["cases/translation/functions/conv.toml#t007_null_3"] required = true [[obligation]] -id = "db.functions.conv.t012" +id = "db.functions.conv.t014" form = "db.functions.conv" kind = "error_parity" target = "STRING, INT, INT" @@ -6350,10 +6493,76 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/count.count.hand.toml#t001_star"] required = true +[[obligation]] +id = "db.functions.count.count.syntax.t001" +form = "db.functions.count.count.syntax" +kind = "null_argument" +target = "INT" +note = "count of NULLs only. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/count.null.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.count.count.syntax.t002" +form = "db.functions.count.count.syntax" +kind = "type_combination" +target = "INT, STRING" +note = "count of INT and STRING columns and of rows. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/count.types.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.counter-diff.t001" form = "db.functions.counter-diff" kind = "type_combination" +target = "DOUBLE" +note = "counter_diff of DOUBLE values. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/counter-diff.double.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.counter-diff.t002" +form = "db.functions.counter-diff" +kind = "type_combination" +target = "BIGINT" +note = "counter_diff of BIGINT values holding equal neighbours, a reset and two NULLs in a row. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/counter-diff.more.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.counter-diff.t003" +form = "db.functions.counter-diff" +kind = "error_parity" +target = "INT" +note = "counter_diff of an INT rise wider than INT. Hand-written for the phase-2 recording." +catches = "a value returned where Databricks rejects the arguments, or another error kind" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/counter-diff.overflow.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.counter-diff.t004" +form = "db.functions.counter-diff" +kind = "type_combination" +target = "STRING, INT" +note = "counter_diff in partitions. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/counter-diff.partition.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.counter-diff.t005" +form = "db.functions.counter-diff" +kind = "type_combination" target = "INT" note = "counter_diff over a counter that resets and holds a NULL. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -6362,7 +6571,7 @@ cases = ["cases/translation/functions/counter-diff.pt.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.counter-diff.t002" +id = "db.functions.counter-diff.t006" form = "db.functions.counter-diff" kind = "type_combination" target = "INT" @@ -6373,7 +6582,7 @@ cases = ["cases/translation/functions/counter-diff.pta.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.counter-diff.t003" +id = "db.functions.counter-diff.t007" form = "db.functions.counter-diff" kind = "type_combination" target = "INT, TIMESTAMP" @@ -6384,7 +6593,7 @@ cases = ["cases/translation/functions/counter-diff.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.counter-diff.t004" +id = "db.functions.counter-diff.t008" form = "db.functions.counter-diff" kind = "type_combination" target = "DECIMAL(10,2), TIMESTAMP" @@ -6395,7 +6604,7 @@ cases = ["cases/translation/functions/counter-diff.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.counter-diff.t005" +id = "db.functions.counter-diff.t009" form = "db.functions.counter-diff" kind = "type_combination" target = "DOUBLE, TIMESTAMP" @@ -6406,7 +6615,7 @@ cases = ["cases/translation/functions/counter-diff.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.counter-diff.t006" +id = "db.functions.counter-diff.t010" form = "db.functions.counter-diff" kind = "type_combination" target = "INT, TIMESTAMP_NTZ" @@ -6417,7 +6626,7 @@ cases = ["cases/translation/functions/counter-diff.toml#t004_types_4"] required = true [[obligation]] -id = "db.functions.counter-diff.t007" +id = "db.functions.counter-diff.t011" form = "db.functions.counter-diff" kind = "null_argument" target = "INT, TIMESTAMP" @@ -6428,7 +6637,7 @@ cases = ["cases/translation/functions/counter-diff.toml#t005_null_1"] required = true [[obligation]] -id = "db.functions.counter-diff.t008" +id = "db.functions.counter-diff.t012" form = "db.functions.counter-diff" kind = "null_argument" target = "INT, TIMESTAMP" @@ -6439,7 +6648,7 @@ cases = ["cases/translation/functions/counter-diff.toml#t006_null_2"] required = true [[obligation]] -id = "db.functions.counter-diff.t009" +id = "db.functions.counter-diff.t013" form = "db.functions.counter-diff" kind = "error_parity" target = "STRING, TIMESTAMP" @@ -6608,6 +6817,17 @@ id = "db.functions.crc32.t001" form = "db.functions.crc32" kind = "type_combination" target = "BINARY" +note = "crc32 of byte strings, empty and with high bytes. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/crc32.more.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.crc32.t002" +form = "db.functions.crc32" +kind = "type_combination" +target = "BINARY" note = "crc32 with arguments of type BINARY." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" @@ -6615,7 +6835,7 @@ cases = ["cases/translation/functions/crc32.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.crc32.t002" +id = "db.functions.crc32.t003" form = "db.functions.crc32" kind = "null_argument" target = "BINARY" @@ -6626,7 +6846,7 @@ cases = ["cases/translation/functions/crc32.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.crc32.t003" +id = "db.functions.crc32.t004" form = "db.functions.crc32" kind = "error_parity" target = "STRING" @@ -6768,6 +6988,17 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/cume-dist.pd.hand.toml#p001"] required = true +[[obligation]] +id = "db.functions.current-timezone.t001" +form = "db.functions.current-timezone" +kind = "type_combination" +target = "INT" +note = "current_timezone in the session's pinned time zone. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/current-timezone.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.date.t001" form = "db.functions.date" @@ -7846,6 +8077,39 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/decimal.toml#t005_wrong_kind"] required = true +[[obligation]] +id = "db.functions.decode.t001" +form = "db.functions.decode" +kind = "type_combination" +target = "INT" +note = "decode of INT keys with a default. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/decode.keys.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.decode.t002" +form = "db.functions.decode" +kind = "type_combination" +target = "STRING" +note = "decode of STRING keys without a default, NULL where none matches. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/decode.no-default.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.decode.t003" +form = "db.functions.decode" +kind = "null_argument" +target = "INT" +note = "decode whose NULL key matches a NULL value. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/decode.null-key.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.decode-cs.t001" form = "db.functions.decode-cs" @@ -9522,6 +9786,39 @@ required = true id = "db.functions.format-number.t001" form = "db.functions.format-number" kind = "type_combination" +target = "DECIMAL(10,0), INT" +note = "format_number of a DECIMAL without places. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.decimal-whole.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.format-number.t002" +form = "db.functions.format-number" +kind = "type_combination" +target = "DECIMAL(20,3), INT" +note = "format_number of DECIMAL values rounding ties half to even, a negative value rounding to zero, and padding past the scale. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.decimal.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.format-number.t003" +form = "db.functions.format-number" +kind = "type_combination" +target = "DOUBLE, INT" +note = "format_number of DOUBLE values whose exact value has more digits than Java's shortest ones. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.double-digits.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.format-number.t004" +form = "db.functions.format-number" +kind = "type_combination" target = "BIGINT, INT" note = "format_number of BIGINT values. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -9530,7 +9827,7 @@ cases = ["cases/translation/functions/format-number.int.np.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.format-number.t002" +id = "db.functions.format-number.t005" form = "db.functions.format-number" kind = "type_combination" target = "DOUBLE, INT" @@ -9541,7 +9838,40 @@ cases = ["cases/translation/functions/format-number.negative-scale.np.hand.toml# required = true [[obligation]] -id = "db.functions.format-number.t003" +id = "db.functions.format-number.t006" +form = "db.functions.format-number" +kind = "type_combination" +target = "DOUBLE" +note = "format_number of NaN and infinities. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.non-finite.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.format-number.t007" +form = "db.functions.format-number" +kind = "type_combination" +target = "DOUBLE" +note = "format_number of NaN and infinities. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.non-finite.pa.hand.toml#p002"] +required = true + +[[obligation]] +id = "db.functions.format-number.t008" +form = "db.functions.format-number" +kind = "type_combination" +target = "DOUBLE" +note = "format_number of NaN and infinities. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.non-finite.pa.hand.toml#p003"] +required = true + +[[obligation]] +id = "db.functions.format-number.t009" form = "db.functions.format-number" kind = "type_combination" target = "DOUBLE, INT" @@ -9552,7 +9882,29 @@ cases = ["cases/translation/functions/format-number.np.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.format-number.t004" +id = "db.functions.format-number.t010" +form = "db.functions.format-number" +kind = "type_combination" +target = "INT, INT" +note = "format_number with more than 100 places. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.places.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.format-number.t011" +form = "db.functions.format-number" +kind = "type_combination" +target = "INT, INT" +note = "format_number with more than 100 places. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/format-number.places.pa.hand.toml#p002"] +required = true + +[[obligation]] +id = "db.functions.format-number.t012" form = "db.functions.format-number" kind = "type_combination" target = "INT, INT" @@ -9563,7 +9915,7 @@ cases = ["cases/translation/functions/format-number.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.format-number.t005" +id = "db.functions.format-number.t013" form = "db.functions.format-number" kind = "type_combination" target = "DECIMAL(10,2), INT" @@ -9574,7 +9926,7 @@ cases = ["cases/translation/functions/format-number.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.format-number.t006" +id = "db.functions.format-number.t014" form = "db.functions.format-number" kind = "type_combination" target = "DOUBLE, INT" @@ -9585,7 +9937,7 @@ cases = ["cases/translation/functions/format-number.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.format-number.t007" +id = "db.functions.format-number.t015" form = "db.functions.format-number" kind = "type_combination" target = "INT, BIGINT" @@ -9596,7 +9948,7 @@ cases = ["cases/translation/functions/format-number.toml#t004_types_4"] required = true [[obligation]] -id = "db.functions.format-number.t008" +id = "db.functions.format-number.t016" form = "db.functions.format-number" kind = "null_argument" target = "INT, INT" @@ -9607,7 +9959,7 @@ cases = ["cases/translation/functions/format-number.toml#t005_null_1"] required = true [[obligation]] -id = "db.functions.format-number.t009" +id = "db.functions.format-number.t017" form = "db.functions.format-number" kind = "null_argument" target = "INT, INT" @@ -9618,7 +9970,7 @@ cases = ["cases/translation/functions/format-number.toml#t006_null_2"] required = true [[obligation]] -id = "db.functions.format-number.t010" +id = "db.functions.format-number.t018" form = "db.functions.format-number" kind = "error_parity" target = "STRING, INT" @@ -13566,6 +13918,17 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/hash.hand.toml#t002_null"] required = true +[[obligation]] +id = "db.functions.hash.t003" +form = "db.functions.hash" +kind = "type_combination" +target = "BIGINT, STRING, BINARY" +note = "hash of BIGINT, multi-byte STRING and BINARY values, one past 32 bytes. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/hash.more.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.hex.t001" form = "db.functions.hex" @@ -13989,6 +14352,17 @@ id = "db.functions.hmac.t001" form = "db.functions.hmac" kind = "type_combination" target = "BINARY, BINARY" +note = "hmac of byte strings, keys at, one past and well past the 64-byte block. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/hmac.more.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.hmac.t002" +form = "db.functions.hmac" +kind = "type_combination" +target = "BINARY, BINARY" note = "hmac with arguments of type BINARY, BINARY." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" @@ -13996,7 +14370,7 @@ cases = ["cases/translation/functions/hmac.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.hmac.t002" +id = "db.functions.hmac.t003" form = "db.functions.hmac" kind = "null_argument" target = "BINARY, BINARY" @@ -14007,7 +14381,7 @@ cases = ["cases/translation/functions/hmac.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.hmac.t003" +id = "db.functions.hmac.t004" form = "db.functions.hmac" kind = "null_argument" target = "BINARY, BINARY" @@ -14018,7 +14392,7 @@ cases = ["cases/translation/functions/hmac.toml#t003_null_2"] required = true [[obligation]] -id = "db.functions.hmac.t004" +id = "db.functions.hmac.t005" form = "db.functions.hmac" kind = "error_parity" target = "STRING, BINARY" @@ -14539,6 +14913,17 @@ id = "db.functions.in.in-2.t001" form = "db.functions.in.in-2" kind = "type_combination" target = "INT" +note = "IN a subquery holding a NULL inside CASE. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/in-2.more.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.in.in-2.t002" +form = "db.functions.in.in-2" +kind = "type_combination" +target = "INT" note = "IN a subquery without a NULL. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" @@ -14546,7 +14931,7 @@ cases = ["cases/translation/functions/in-2.no-null.np.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.in.in-2.t002" +id = "db.functions.in.in-2.t003" form = "db.functions.in.in-2" kind = "type_combination" target = "INT" @@ -14556,6 +14941,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/in-2.np.hand.toml#p001"] required = true +[[obligation]] +id = "db.functions.in.in-2.t004" +form = "db.functions.in.in-2" +kind = "type_combination" +target = "STRING" +note = "IN a subquery of STRING values, case-sensitive. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/in-2.string.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.in.in-2.t005" +form = "db.functions.in.in-2" +kind = "type_combination" +target = "INT" +note = "IN a subquery holding a NULL as a filter. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/in-2.where.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.in.in.syntax.t001" form = "db.functions.in.in.syntax" @@ -15711,6 +16118,39 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/isdistinct.toml#t010_wrong_kind"] required = true +[[obligation]] +id = "db.functions.isearch.t001" +form = "db.functions.isearch" +kind = "type_combination" +target = "STRING, STRING" +note = "isearch ignoring ASCII case across two columns. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/isearch.ascii.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.isearch.t002" +form = "db.functions.isearch" +kind = "type_combination" +target = "STRING" +note = "isearch of capital I with dot above, which UTF8_LCASE lowers to i and a combining dot. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/isearch.dotted.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.isearch.t003" +form = "db.functions.isearch" +kind = "type_combination" +target = "STRING" +note = "isearch folding capital, small and final sigma. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/isearch.sigma.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.isfalse.t001" form = "db.functions.isfalse" @@ -20276,6 +20716,39 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/mask.toml#t005_wrong_kind"] required = true +[[obligation]] +id = "db.functions.match-number.t001" +form = "db.functions.match-number" +kind = "type_combination" +target = "INT" +note = "MATCH_NUMBER counting matches from one. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/match-number.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.match-recognize-next.t001" +form = "db.functions.match-recognize-next" +kind = "type_combination" +target = "INT" +note = "NEXT with an offset of two rows. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/match-recognize-next.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.match-recognize-prev.t001" +form = "db.functions.match-recognize-prev" +kind = "type_combination" +target = "INT" +note = "PREV with an offset of two rows. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/match-recognize.prev-offset.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.max.t001" form = "db.functions.max" @@ -20320,6 +20793,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/max.toml#t006_wrong_kind"] required = true +[[obligation]] +id = "db.functions.max-by.max-by.t001" +form = "db.functions.max-by.max-by" +kind = "null_argument" +target = "STRING, INT" +note = "max_by whose largest ordering has a NULL value. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/max-by.null.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.max-by.max-by.t002" +form = "db.functions.max-by.max-by" +kind = "type_combination" +target = "STRING, INT, DATE" +note = "max_by of STRING by INT and INT by DATE. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/max-by.types.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.max-by.max-by.syntax.t001" form = "db.functions.max-by.max-by.syntax" @@ -20639,6 +21134,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/min.toml#t006_wrong_kind"] required = true +[[obligation]] +id = "db.functions.min-by.min-by.t001" +form = "db.functions.min-by.min-by" +kind = "null_argument" +target = "STRING, INT" +note = "min_by whose smallest ordering has a NULL value. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/min-by.null.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.min-by.min-by.t002" +form = "db.functions.min-by.min-by" +kind = "type_combination" +target = "STRING, INT, DATE" +note = "min_by of STRING by INT and INT by DATE. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/min-by.types.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.min-by.min-by.syntax.t001" form = "db.functions.min-by.min-by.syntax" @@ -23228,6 +23745,17 @@ required = true id = "db.functions.pipesign.syntax.t001" form = "db.functions.pipesign.syntax" kind = "type_combination" +target = "STRING, STRING" +note = "|| of two STRING operands, one NULL. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/pipesign.strings.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.pipesign.syntax.t002" +form = "db.functions.pipesign.syntax" +kind = "type_combination" target = "INT" note = "pipesign with arguments of type INT." catches = "the argument types read another way, or the result typed otherwise" @@ -23236,7 +23764,7 @@ cases = ["cases/translation/functions/pipesign.syntax.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.t002" +id = "db.functions.pipesign.syntax.t003" form = "db.functions.pipesign.syntax" kind = "type_combination" target = "BIGINT" @@ -23247,7 +23775,7 @@ cases = ["cases/translation/functions/pipesign.syntax.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.t003" +id = "db.functions.pipesign.syntax.t004" form = "db.functions.pipesign.syntax" kind = "type_combination" target = "SMALLINT" @@ -23258,7 +23786,7 @@ cases = ["cases/translation/functions/pipesign.syntax.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.t004" +id = "db.functions.pipesign.syntax.t005" form = "db.functions.pipesign.syntax" kind = "null_argument" target = "INT" @@ -23269,7 +23797,7 @@ cases = ["cases/translation/functions/pipesign.syntax.toml#t004_null_1"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.t005" +id = "db.functions.pipesign.syntax.t006" form = "db.functions.pipesign.syntax" kind = "error_parity" target = "STRING" @@ -23283,6 +23811,17 @@ required = true id = "db.functions.pipesign.syntax.syntax.t001" form = "db.functions.pipesign.syntax.syntax" kind = "type_combination" +target = "INT, STRING" +note = "|| of an INT and a STRING operand. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/pipesign.mixed.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.pipesign.syntax.syntax.t002" +form = "db.functions.pipesign.syntax.syntax" +kind = "type_combination" target = "INT" note = "pipesign with arguments of type INT." catches = "the argument types read another way, or the result typed otherwise" @@ -23291,7 +23830,7 @@ cases = ["cases/translation/functions/pipesign.syntax.syntax.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.syntax.t002" +id = "db.functions.pipesign.syntax.syntax.t003" form = "db.functions.pipesign.syntax.syntax" kind = "type_combination" target = "BIGINT" @@ -23302,7 +23841,7 @@ cases = ["cases/translation/functions/pipesign.syntax.syntax.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.syntax.t003" +id = "db.functions.pipesign.syntax.syntax.t004" form = "db.functions.pipesign.syntax.syntax" kind = "type_combination" target = "SMALLINT" @@ -23313,7 +23852,7 @@ cases = ["cases/translation/functions/pipesign.syntax.syntax.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.syntax.t004" +id = "db.functions.pipesign.syntax.syntax.t005" form = "db.functions.pipesign.syntax.syntax" kind = "null_argument" target = "INT" @@ -23324,7 +23863,7 @@ cases = ["cases/translation/functions/pipesign.syntax.syntax.toml#t004_null_1"] required = true [[obligation]] -id = "db.functions.pipesign.syntax.syntax.t005" +id = "db.functions.pipesign.syntax.syntax.t006" form = "db.functions.pipesign.syntax.syntax" kind = "error_parity" target = "STRING" @@ -24093,6 +24632,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/questiondoublecolonsign.hand.toml#t002_null"] required = true +[[obligation]] +id = "db.functions.questiondoublecolonsign.t003" +form = "db.functions.questiondoublecolonsign" +kind = "null_argument" +target = "STRING" +note = "the ?:: operator of NULL. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/questiondoublecolonsign.null.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.questiondoublecolonsign.t004" +form = "db.functions.questiondoublecolonsign" +kind = "type_combination" +target = "STRING" +note = "the ?:: operator casting STRING to INT, NULL where the text reads as none. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/questiondoublecolonsign.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.radians.t001" form = "db.functions.radians" @@ -24152,6 +24713,17 @@ required = true id = "db.functions.raise-error.t001" form = "db.functions.raise-error" kind = "type_combination" +target = "INT" +note = "raise_error in a CASE branch no row takes. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/raise-error.guarded.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.raise-error.t002" +form = "db.functions.raise-error" +kind = "type_combination" target = "STRING" note = "raise_error of a message and of NULL. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -24160,7 +24732,7 @@ cases = ["cases/translation/functions/raise-error.np.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.raise-error.t002" +id = "db.functions.raise-error.t003" form = "db.functions.raise-error" kind = "type_combination" target = "STRING" @@ -24171,7 +24743,7 @@ cases = ["cases/translation/functions/raise-error.np.hand.toml#p002"] required = true [[obligation]] -id = "db.functions.raise-error.t003" +id = "db.functions.raise-error.t004" form = "db.functions.raise-error" kind = "type_combination" target = "STRING" @@ -24182,7 +24754,7 @@ cases = ["cases/translation/functions/raise-error.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.raise-error.t004" +id = "db.functions.raise-error.t005" form = "db.functions.raise-error" kind = "null_argument" target = "STRING" @@ -24193,7 +24765,7 @@ cases = ["cases/translation/functions/raise-error.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.raise-error.t005" +id = "db.functions.raise-error.t006" form = "db.functions.raise-error" kind = "error_parity" target = "ARRAY" @@ -26403,6 +26975,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/schema-of-xml.toml#t005_wrong_kind"] required = true +[[obligation]] +id = "db.functions.search.t001" +form = "db.functions.search" +kind = "type_combination" +target = "INT, STRING" +note = "search skips an INT argument, with the mode named in mixed case. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/search.skipped.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.search.t002" +form = "db.functions.search" +kind = "type_combination" +target = "STRING, STRING" +note = "search for a literal pattern in two STRING columns, NULL where none matches and one is NULL. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/search.strings.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.sec.t001" form = "db.functions.sec" @@ -26605,6 +27199,50 @@ required = true id = "db.functions.sequence.t007" form = "db.functions.sequence" kind = "type_combination" +target = "STRING, STRING" +note = "sequence of two STRING bounds. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/sequence.text-both.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.sequence.t008" +form = "db.functions.sequence" +kind = "type_combination" +target = "STRING, INT" +note = "sequence of a STRING start that reads as a number. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/sequence.text.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.sequence.t009" +form = "db.functions.sequence" +kind = "type_combination" +target = "STRING, INT" +note = "sequence of a STRING start that reads as a number. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/sequence.text.pa.hand.toml#p002"] +required = true + +[[obligation]] +id = "db.functions.sequence.t010" +form = "db.functions.sequence" +kind = "type_combination" +target = "STRING, INT" +note = "sequence of a STRING start that reads as a number. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/sequence.text.pa.hand.toml#p003"] +required = true + +[[obligation]] +id = "db.functions.sequence.t011" +form = "db.functions.sequence" +kind = "type_combination" target = "INT, INT" note = "sequence with arguments of type INT, INT." catches = "the argument types read another way, or the result typed otherwise" @@ -26613,7 +27251,7 @@ cases = ["cases/translation/functions/sequence.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.sequence.t008" +id = "db.functions.sequence.t012" form = "db.functions.sequence" kind = "type_combination" target = "DATE, INT" @@ -26624,7 +27262,7 @@ cases = ["cases/translation/functions/sequence.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.sequence.t009" +id = "db.functions.sequence.t013" form = "db.functions.sequence" kind = "type_combination" target = "TIMESTAMP, INT" @@ -26635,7 +27273,7 @@ cases = ["cases/translation/functions/sequence.toml#t003_types_3"] required = true [[obligation]] -id = "db.functions.sequence.t010" +id = "db.functions.sequence.t014" form = "db.functions.sequence" kind = "type_combination" target = "BIGINT, INT" @@ -26646,7 +27284,7 @@ cases = ["cases/translation/functions/sequence.toml#t004_types_4"] required = true [[obligation]] -id = "db.functions.sequence.t011" +id = "db.functions.sequence.t015" form = "db.functions.sequence" kind = "null_argument" target = "INT, INT" @@ -26657,7 +27295,7 @@ cases = ["cases/translation/functions/sequence.toml#t005_null_1"] required = true [[obligation]] -id = "db.functions.sequence.t012" +id = "db.functions.sequence.t016" form = "db.functions.sequence" kind = "null_argument" target = "INT, INT" @@ -26668,7 +27306,7 @@ cases = ["cases/translation/functions/sequence.toml#t006_null_2"] required = true [[obligation]] -id = "db.functions.sequence.t013" +id = "db.functions.sequence.t017" form = "db.functions.sequence" kind = "error_parity" target = "STRING, INT" @@ -34174,12 +34812,56 @@ id = "db.functions.time-diff.t001" form = "db.functions.time-diff" kind = "type_combination" target = "TIME, TIME" +note = "time_diff in hours. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/time-diff.hour.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.time-diff.t002" +form = "db.functions.time-diff" +kind = "type_combination" +target = "TIME, TIME" +note = "time_diff with a lower-case unit. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/time-diff.lower.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.time-diff.t003" +form = "db.functions.time-diff" +kind = "type_combination" +target = "TIME, TIME" +note = "time_diff in milliseconds, truncating either way. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/time-diff.micro.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.time-diff.t004" +form = "db.functions.time-diff" +kind = "type_combination" +target = "TIME, TIME" note = "time_diff with unit keywords, which Databricks reads as columns it cannot resolve. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/time-diff.pt.hand.toml#p001"] required = true +[[obligation]] +id = "db.functions.time-diff.t005" +form = "db.functions.time-diff" +kind = "type_combination" +target = "TIME, TIME" +note = "time_diff in seconds with the unit as a string, truncating and negative. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/time-diff.strings.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.time-from-micros.t001" form = "db.functions.time-from-micros" @@ -36963,6 +37645,28 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/functions/try-avg.toml#t008_wrong_kind"] required = true +[[obligation]] +id = "db.functions.try-cast.t001" +form = "db.functions.try-cast" +kind = "null_argument" +target = "STRING" +note = "try_cast of NULL. Hand-written for the phase-2 recording." +catches = "a NULL argument returning a value, or raising where Databricks returns NULL" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/try-cast.null.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.try-cast.t002" +form = "db.functions.try-cast" +kind = "type_combination" +target = "STRING" +note = "try_cast of STRING to INT, NULL where the text reads as none. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/try-cast.string-int.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.functions.try-divide.t001" form = "db.functions.try-divide" @@ -40917,6 +41621,17 @@ id = "db.functions.vector-avg.t001" form = "db.functions.vector-avg" kind = "type_combination" target = "ARRAY" +note = "vector_avg of FLOAT arrays whose float and double means round apart. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/vector-avg.precision.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.vector-avg.t002" +form = "db.functions.vector-avg" +kind = "type_combination" +target = "ARRAY" note = "vector-avg with arguments of type ARRAY." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" @@ -40924,7 +41639,7 @@ cases = ["cases/translation/functions/vector-avg.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.vector-avg.t002" +id = "db.functions.vector-avg.t003" form = "db.functions.vector-avg" kind = "null_argument" target = "ARRAY" @@ -40935,7 +41650,7 @@ cases = ["cases/translation/functions/vector-avg.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.vector-avg.t003" +id = "db.functions.vector-avg.t004" form = "db.functions.vector-avg" kind = "error_parity" target = "STRING" @@ -41124,6 +41839,17 @@ required = true [[obligation]] id = "db.functions.vector-l2-distance.t001" form = "db.functions.vector-l2-distance" +kind = "error_parity" +target = "ARRAY, ARRAY" +note = "vector_l2_distance of arrays of different lengths. Hand-written for the phase-2 recording." +catches = "a value returned where Databricks rejects the arguments, or another error kind" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/vector-l2-distance.lengths.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.vector-l2-distance.t002" +form = "db.functions.vector-l2-distance" kind = "type_combination" target = "ARRAY, ARRAY" note = "distances whose squared differences overflow FLOAT, or round in it. Hand-written for the phase-2 recording." @@ -41133,7 +41859,18 @@ cases = ["cases/translation/functions/vector-l2-distance.pf.hand.toml#p001"] required = true [[obligation]] -id = "db.functions.vector-l2-distance.t002" +id = "db.functions.vector-l2-distance.t003" +form = "db.functions.vector-l2-distance" +kind = "type_combination" +target = "ARRAY, ARRAY" +note = "vector_l2_distance of FLOAT arrays whose float and double sums of squares or differences round apart, and of empty arrays. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/vector-l2-distance.precision.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.vector-l2-distance.t004" form = "db.functions.vector-l2-distance" kind = "type_combination" target = "ARRAY, ARRAY" @@ -41144,7 +41881,7 @@ cases = ["cases/translation/functions/vector-l2-distance.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.vector-l2-distance.t003" +id = "db.functions.vector-l2-distance.t005" form = "db.functions.vector-l2-distance" kind = "null_argument" target = "ARRAY, ARRAY" @@ -41155,7 +41892,7 @@ cases = ["cases/translation/functions/vector-l2-distance.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.vector-l2-distance.t004" +id = "db.functions.vector-l2-distance.t006" form = "db.functions.vector-l2-distance" kind = "null_argument" target = "ARRAY, ARRAY" @@ -41166,7 +41903,7 @@ cases = ["cases/translation/functions/vector-l2-distance.toml#t003_null_2"] required = true [[obligation]] -id = "db.functions.vector-l2-distance.t005" +id = "db.functions.vector-l2-distance.t007" form = "db.functions.vector-l2-distance" kind = "error_parity" target = "STRING, ARRAY" @@ -41247,6 +41984,17 @@ id = "db.functions.vector-normalize.t003" form = "db.functions.vector-normalize" kind = "type_combination" target = "ARRAY" +note = "vector_normalize of FLOAT arrays whose float and double norms round apart, of a zero and an empty vector. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/vector-normalize.precision.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.vector-normalize.t004" +form = "db.functions.vector-normalize" +kind = "type_combination" +target = "ARRAY" note = "vector-normalize with arguments of type ARRAY." catches = "the argument types read another way, or the result typed otherwise" reading = "the argument types the generator read from the function's page" @@ -41254,7 +42002,7 @@ cases = ["cases/translation/functions/vector-normalize.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.vector-normalize.t004" +id = "db.functions.vector-normalize.t005" form = "db.functions.vector-normalize" kind = "null_argument" target = "ARRAY" @@ -41265,7 +42013,7 @@ cases = ["cases/translation/functions/vector-normalize.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.vector-normalize.t005" +id = "db.functions.vector-normalize.t006" form = "db.functions.vector-normalize" kind = "error_parity" target = "STRING" @@ -41278,6 +42026,28 @@ required = true [[obligation]] id = "db.functions.vector-sum.t001" form = "db.functions.vector-sum" +kind = "error_parity" +target = "ARRAY" +note = "vector_sum of arrays of different lengths. Hand-written for the phase-2 recording." +catches = "a value returned where Databricks rejects the arguments, or another error kind" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/vector-sum.lengths.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.vector-sum.t002" +form = "db.functions.vector-sum" +kind = "type_combination" +target = "ARRAY" +note = "vector_sum of FLOAT arrays whose float and double element sums round apart. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/vector-sum.precision.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.vector-sum.t003" +form = "db.functions.vector-sum" kind = "type_combination" target = "ARRAY" note = "vector-sum with arguments of type ARRAY." @@ -41287,7 +42057,7 @@ cases = ["cases/translation/functions/vector-sum.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.vector-sum.t002" +id = "db.functions.vector-sum.t004" form = "db.functions.vector-sum" kind = "null_argument" target = "ARRAY" @@ -41298,7 +42068,7 @@ cases = ["cases/translation/functions/vector-sum.toml#t002_null_1"] required = true [[obligation]] -id = "db.functions.vector-sum.t003" +id = "db.functions.vector-sum.t005" form = "db.functions.vector-sum" kind = "error_parity" target = "STRING" @@ -42555,6 +43325,17 @@ required = true id = "db.functions.xxhash64.t001" form = "db.functions.xxhash64" kind = "type_combination" +target = "BIGINT, STRING, BINARY" +note = "xxhash64 of BIGINT, multi-byte STRING and BINARY values, two past 32 bytes. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/functions/xxhash64.more.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.functions.xxhash64.t002" +form = "db.functions.xxhash64" +kind = "type_combination" target = "INT" note = "xxhash64 with arguments of type INT." catches = "the argument types read another way, or the result typed otherwise" @@ -42563,7 +43344,7 @@ cases = ["cases/translation/functions/xxhash64.toml#t001_types_1"] required = true [[obligation]] -id = "db.functions.xxhash64.t002" +id = "db.functions.xxhash64.t003" form = "db.functions.xxhash64" kind = "type_combination" target = "STRING" @@ -42574,7 +43355,7 @@ cases = ["cases/translation/functions/xxhash64.toml#t002_types_2"] required = true [[obligation]] -id = "db.functions.xxhash64.t003" +id = "db.functions.xxhash64.t004" form = "db.functions.xxhash64" kind = "null_argument" target = "INT" @@ -42585,7 +43366,7 @@ cases = ["cases/translation/functions/xxhash64.toml#t003_null_1"] required = true [[obligation]] -id = "db.functions.xxhash64.t004" +id = "db.functions.xxhash64.t005" form = "db.functions.xxhash64" kind = "error_parity" target = "STRING" diff --git a/coverage/translation-databricks/obligations/query.toml b/coverage/translation-databricks/obligations/query.toml index 29264030b..c0d3bf91c 100644 --- a/coverage/translation-databricks/obligations/query.toml +++ b/coverage/translation-databricks/obligations/query.toml @@ -3,6 +3,28 @@ # one case. Written by scripts/build_translation_obligations_databricks.py from the # published cases' tags; boundary cases are uncited. See README.md. +[[obligation]] +id = "db.query.pipeline.table.t001" +form = "db.query.pipeline.table" +kind = "type_combination" +target = "INT" +note = "a pipeline starting FROM a relation. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/pipeline.from.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.query.pipeline.table.syntax.t001" +form = "db.query.pipeline.table.syntax" +kind = "type_combination" +target = "INT" +note = "a pipeline starting TABLE a relation. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/pipeline.table.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.query.query.t001" form = "db.query.query" @@ -73,6 +95,17 @@ required = true id = "db.query.select-column-list.t001" form = "db.query.select-column-list" kind = "type_combination" +target = "INT" +note = "a column read by name. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/names.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.query.select-column-list.t002" +form = "db.query.select-column-list" +kind = "type_combination" target = "INT, STRING, INT" note = "SELECT DISTINCT of two columns holding NULLs. Hand-written for the phase-2 recording." catches = "the argument types read another way, or the result typed otherwise" @@ -81,7 +114,7 @@ cases = ["cases/translation/query/select-column-list.distinct.pe.hand.toml#p001" required = true [[obligation]] -id = "db.query.select-column-list.t002" +id = "db.query.select-column-list.t003" form = "db.query.select-column-list" kind = "type_combination" target = "INT, STRING, INT" @@ -839,6 +872,50 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/query/select-limit.zero.pe.hand.toml#p001"] required = true +[[obligation]] +id = "db.query.select-match-recognize.t001" +form = "db.query.select-match-recognize" +kind = "type_combination" +target = "INT" +note = "runs of rising values, one row per match. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/match-recognize.rises.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.query.select-match-recognize-define.t001" +form = "db.query.select-match-recognize-define" +kind = "type_combination" +target = "INT, STRING" +note = "partitioned matches whose first row looks ahead with NEXT. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/match-recognize.partition.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.query.select-match-recognize-measures.t001" +form = "db.query.select-match-recognize-measures" +kind = "type_combination" +target = "INT" +note = "every matched row with its variable and match number. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/match-recognize.all-rows.pa.hand.toml#p001"] +required = true + +[[obligation]] +id = "db.query.select-match-recognize-pattern.t001" +form = "db.query.select-match-recognize-pattern" +kind = "type_combination" +target = "INT" +note = "a pattern with alternation and quantifiers. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/match-recognize.pattern.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.query.select-named-window.t001" form = "db.query.select-named-window" @@ -1488,6 +1565,17 @@ reading = "the argument types the generator read from the function's page" cases = ["cases/translation/query/select-unpivot.plain.pe.hand.toml#p002"] required = true +[[obligation]] +id = "db.query.select-values.select.t001" +form = "db.query.select-values.select" +kind = "type_combination" +target = "INT" +note = "a SELECT of expressions without FROM. Hand-written for the phase-2 recording." +catches = "the argument types read another way, or the result typed otherwise" +reading = "the argument types the generator read from the function's page" +cases = ["cases/translation/query/select-values.select.pa.hand.toml#p001"] +required = true + [[obligation]] id = "db.query.select-values.values.t001" form = "db.query.select-values.values" diff --git a/coverage/translation-databricks/results-baseline.json b/coverage/translation-databricks/results-baseline.json index baf13052f..c23776fbf 100644 --- a/coverage/translation-databricks/results-baseline.json +++ b/coverage/translation-databricks/results-baseline.json @@ -63,7 +63,9 @@ "translation/expressions/binary-type.x.pe.hand.toml#p001": "matching", "translation/expressions/boolean-type.pe.hand.toml#p001": "matching", "translation/expressions/boolean-type.true-false.pe.hand.toml#p001": "matching", - "translation/expressions/collate-lcase.np.hand.toml#p001": "refused", + "translation/expressions/collate-lcase.np.hand.toml#p001": "matching", + "translation/expressions/collation.lcase-special.pa.hand.toml#p001": "matching", + "translation/expressions/collation.lower-binary.pa.hand.toml#p001": "matching", "translation/expressions/comment.pe.hand.toml#p001": "matching", "translation/expressions/date-type.date.pt.hand.toml#p001": "matching", "translation/expressions/date-type.date.short.pt.hand.toml#p001": "matching", @@ -96,6 +98,8 @@ "translation/expressions/names.identifier-3.pe.hand.toml#p001": "matching", "translation/expressions/names.subscript-dot-2.pe.hand.toml#p001": "matching", "translation/expressions/names.subscript.pe.hand.toml#p001": "matching", + "translation/expressions/names.table-identifier.pa.hand.toml#p001": "matching", + "translation/expressions/names.table.pa.hand.toml#p001": "matching", "translation/expressions/null-type.void.pf.hand.toml#p001": "matching", "translation/expressions/smallint-type.pe.hand.toml#p001": "matching", "translation/expressions/smallint-type.s.pe.hand.toml#p001": "matching", @@ -104,8 +108,9 @@ "translation/expressions/string-type.raw.pe.hand.toml#p001": "matching", "translation/expressions/struct-type.np.hand.toml#p001": "refused", "translation/expressions/struct-type.pe.hand.toml#p001": "refused", + "translation/expressions/time-type.precision.pa.hand.toml#p001": "refused", "translation/expressions/time-type.time.literals.pt.hand.toml#p001": "matching", - "translation/expressions/time-type.time.literals.short.pt.hand.toml#p001": "refused", + "translation/expressions/time-type.time.literals.short.pt.hand.toml#p001": "matching", "translation/expressions/time-type.time.pt.hand.toml#p001": "matching", "translation/expressions/time-type.time.pt.hand.toml#p002": "matching", "translation/expressions/time-type.time.pt.hand.toml#p003": "matching_error", @@ -121,7 +126,11 @@ "translation/expressions/tinyint-type.y.pe.hand.toml#p001": "matching", "translation/expressions/variant-type.pe.hand.toml#p001": "refused", "translation/expressions/window-functions-frame.pt.hand.toml#p001": "matching", - "translation/expressions/window-functions-frame.range.pt.hand.toml#p001": "refused", + "translation/expressions/window-functions-frame.range-bigint.pa.hand.toml#p001": "matching_error", + "translation/expressions/window-functions-frame.range-bounds.pa.hand.toml#p001": "matching", + "translation/expressions/window-functions-frame.range-bounds.pa.hand.toml#p002": "matching_error", + "translation/expressions/window-functions-frame.range-bounds.pa.hand.toml#p003": "matching_error", + "translation/expressions/window-functions-frame.range.pt.hand.toml#p001": "matching", "translation/expressions/window-functions-frame.rows.pf.hand.toml#p001": "matching", "translation/expressions/window-functions.pd.hand.toml#p001": "matching", "translation/expressions/window-functions.pd2.hand.toml#p001": "matching", @@ -193,12 +202,12 @@ "translation/functions/and.toml#t002_null_1": "matching", "translation/functions/and.toml#t003_null_2": "matching", "translation/functions/and.toml#t004_wrong_kind": "matching_rejection", - "translation/functions/any-value.toml#t001_types_1": "refused", - "translation/functions/any-value.toml#t002_types_2": "refused", - "translation/functions/any-value.toml#t003_null_1": "refused", - "translation/functions/any-value.toml#t004_boundary_1": "refused", - "translation/functions/any-value.toml#t005_boundary_2": "refused", - "translation/functions/any-value.toml#t006_wrong_kind": "refused", + "translation/functions/any-value.toml#t001_types_1": "declared_divergence", + "translation/functions/any-value.toml#t002_types_2": "declared_divergence", + "translation/functions/any-value.toml#t003_null_1": "matching", + "translation/functions/any-value.toml#t004_boundary_1": "matching", + "translation/functions/any-value.toml#t005_boundary_2": "matching", + "translation/functions/any-value.toml#t006_wrong_kind": "matching", "translation/functions/any.toml#t001_types_1": "matching", "translation/functions/any.toml#t002_null_1": "matching", "translation/functions/any.toml#t003_wrong_kind": "matching_rejection", @@ -649,12 +658,15 @@ "translation/functions/bitmap-bucket-number.toml#t005_boundary_1": "matching", "translation/functions/bitmap-bucket-number.toml#t006_boundary_2": "matching", "translation/functions/bitmap-bucket-number.toml#t007_wrong_kind": "matching_error", - "translation/functions/bitmap-construct-agg.toml#t001_types_1": "refused", - "translation/functions/bitmap-construct-agg.toml#t002_types_2": "refused", - "translation/functions/bitmap-construct-agg.toml#t003_types_3": "refused", - "translation/functions/bitmap-construct-agg.toml#t004_null_1": "refused", - "translation/functions/bitmap-construct-agg.toml#t005_boundary_1": "refused", - "translation/functions/bitmap-construct-agg.toml#t006_boundary_2": "refused", + "translation/functions/bitmap-construct-agg.empty.pa.hand.toml#p001": "matching", + "translation/functions/bitmap-construct-agg.positioned.pa.hand.toml#p001": "matching", + "translation/functions/bitmap-construct-agg.positions.pa.hand.toml#p001": "matching", + "translation/functions/bitmap-construct-agg.toml#t001_types_1": "matching_error", + "translation/functions/bitmap-construct-agg.toml#t002_types_2": "matching_error", + "translation/functions/bitmap-construct-agg.toml#t003_types_3": "matching_error", + "translation/functions/bitmap-construct-agg.toml#t004_null_1": "matching", + "translation/functions/bitmap-construct-agg.toml#t005_boundary_1": "matching_error", + "translation/functions/bitmap-construct-agg.toml#t006_boundary_2": "matching_error", "translation/functions/bitmap-construct-agg.toml#t007_wrong_kind": "refused", "translation/functions/bitmap-count.toml#t001_types_1": "matching", "translation/functions/bitmap-count.toml#t002_null_1": "matching", @@ -744,6 +756,11 @@ "translation/functions/case.end.toml#t010_boundary_3": "matching", "translation/functions/case.end.toml#t011_boundary_4": "matching", "translation/functions/case.end.toml#t012_wrong_kind": "matching_error", + "translation/functions/cast.decimal-bigint.pa.hand.toml#p001": "matching", + "translation/functions/cast.int-string.pa.hand.toml#p001": "matching", + "translation/functions/cast.malformed.pa.hand.toml#p001": "matching_error", + "translation/functions/cast.null.pa.hand.toml#p001": "matching", + "translation/functions/cast.string-int.pa.hand.toml#p001": "matching", "translation/functions/cbrt.toml#t001_types_1": "refused", "translation/functions/cbrt.toml#t002_types_2": "refused", "translation/functions/cbrt.toml#t003_types_3": "refused", @@ -799,12 +816,15 @@ "translation/functions/chr.toml#t005_boundary_1": "matching", "translation/functions/chr.toml#t006_boundary_2": "matching", "translation/functions/chr.toml#t007_wrong_kind": "matching_error", + "translation/functions/classifier.pa.hand.toml#p001": "refused", "translation/functions/coalesce.toml#t001_types_1": "matching", "translation/functions/coalesce.toml#t002_types_2": "matching", "translation/functions/coalesce.toml#t003_null_1": "matching", "translation/functions/coalesce.toml#t004_boundary_1": "matching", "translation/functions/coalesce.toml#t005_boundary_2": "matching", "translation/functions/coalesce.toml#t006_wrong_kind": "matching", + "translation/functions/collate.binary-equal.pa.hand.toml#p001": "matching", + "translation/functions/collate.binary.pa.hand.toml#p001": "refused", "translation/functions/collation.toml#t001_types_1": "matching", "translation/functions/collation.toml#t002_null_1": "matching", "translation/functions/collation.toml#t003_boundary_1": "matching", @@ -850,6 +870,8 @@ "translation/functions/contains.toml#t008_boundary_3": "matching", "translation/functions/contains.toml#t009_boundary_4": "matching", "translation/functions/contains.toml#t010_wrong_kind": "matching_rejection", + "translation/functions/conv.double-letters.pa.hand.toml#p001": "refused", + "translation/functions/conv.double.pa.hand.toml#p001": "refused", "translation/functions/conv.pb.hand.toml#p001": "matching", "translation/functions/conv.pb2.hand.toml#p001": "matching", "translation/functions/conv.pb3.hand.toml#p001": "matching", @@ -941,7 +963,13 @@ "translation/functions/count-min-sketch.toml#t013_wrong_kind": "refused", "translation/functions/count.count.hand.toml#t001_star": "matching", "translation/functions/count.count.hand.toml#t002_empty": "matching", - "translation/functions/counter-diff.pt.hand.toml#p001": "refused", + "translation/functions/count.null.pa.hand.toml#p001": "matching", + "translation/functions/count.types.pa.hand.toml#p001": "matching", + "translation/functions/counter-diff.double.pa.hand.toml#p001": "matching", + "translation/functions/counter-diff.more.pa.hand.toml#p001": "matching", + "translation/functions/counter-diff.overflow.pa.hand.toml#p001": "matching_error", + "translation/functions/counter-diff.partition.pa.hand.toml#p001": "matching", + "translation/functions/counter-diff.pt.hand.toml#p001": "matching", "translation/functions/counter-diff.pta.hand.toml#p001": "matching_rejection", "translation/functions/counter-diff.toml#t001_types_1": "matching_rejection", "translation/functions/counter-diff.toml#t002_types_2": "matching_rejection", @@ -976,9 +1004,10 @@ "translation/functions/covar-samp.toml#t009_boundary_3": "refused", "translation/functions/covar-samp.toml#t010_boundary_4": "refused", "translation/functions/covar-samp.toml#t011_wrong_kind": "refused", - "translation/functions/crc32.toml#t001_types_1": "refused", - "translation/functions/crc32.toml#t002_null_1": "refused", - "translation/functions/crc32.toml#t003_boundary_1": "refused", + "translation/functions/crc32.more.pa.hand.toml#p001": "matching", + "translation/functions/crc32.toml#t001_types_1": "matching", + "translation/functions/crc32.toml#t002_null_1": "matching", + "translation/functions/crc32.toml#t003_boundary_1": "matching", "translation/functions/crc32.toml#t004_wrong_kind": "refused", "translation/functions/csc.toml#t001_types_1": "refused", "translation/functions/csc.toml#t002_types_2": "refused", @@ -996,6 +1025,7 @@ "translation/functions/cube.toml#t006_wrong_kind": "matching_rejection", "translation/functions/cume-dist.hand.toml#t001_window": "matching", "translation/functions/cume-dist.pd.hand.toml#p001": "matching", + "translation/functions/current-timezone.pa.hand.toml#p001": "refused", "translation/functions/date-add.toml#t001_types_1": "matching", "translation/functions/date-add.toml#t002_types_2": "matching_rejection", "translation/functions/date-add.toml#t003_types_3": "matching", @@ -1021,7 +1051,7 @@ "translation/functions/date-format.pb3.hand.toml#p001": "matching", "translation/functions/date-format.pb4.hand.toml#p001": "matching", "translation/functions/date-format.pb5.hand.toml#p001": "matching", - "translation/functions/date-format.pt.hand.toml#p001": "refused", + "translation/functions/date-format.pt.hand.toml#p001": "matching", "translation/functions/date-format.toml#t001_types_1": "refused", "translation/functions/date-format.toml#t002_types_2": "refused", "translation/functions/date-format.toml#t003_types_3": "refused", @@ -1151,6 +1181,9 @@ "translation/functions/decode-cs.toml#t005_boundary_2": "matching_error", "translation/functions/decode-cs.toml#t006_boundary_3": "matching_error", "translation/functions/decode-cs.toml#t007_wrong_kind": "matching_error", + "translation/functions/decode.keys.pa.hand.toml#p001": "matching", + "translation/functions/decode.no-default.pa.hand.toml#p001": "matching", + "translation/functions/decode.null-key.pa.hand.toml#p001": "matching", "translation/functions/degrees.toml#t001_types_1": "matching", "translation/functions/degrees.toml#t002_types_2": "matching", "translation/functions/degrees.toml#t003_types_3": "matching", @@ -1360,19 +1393,27 @@ "translation/functions/forall.hand.toml#t003_null_array": "matching", "translation/functions/forall.hand.toml#t004_empty_array": "matching", "translation/functions/forall.short-circuit.pf.hand.toml#p001": "matching", - "translation/functions/format-number.int.np.hand.toml#p001": "refused", + "translation/functions/format-number.decimal-whole.pa.hand.toml#p001": "matching", + "translation/functions/format-number.decimal.pa.hand.toml#p001": "matching", + "translation/functions/format-number.double-digits.pa.hand.toml#p001": "refused", + "translation/functions/format-number.int.np.hand.toml#p001": "matching", "translation/functions/format-number.negative-scale.np.hand.toml#p001": "refused", + "translation/functions/format-number.non-finite.pa.hand.toml#p001": "refused", + "translation/functions/format-number.non-finite.pa.hand.toml#p002": "refused", + "translation/functions/format-number.non-finite.pa.hand.toml#p003": "refused", "translation/functions/format-number.np.hand.toml#p001": "refused", - "translation/functions/format-number.toml#t001_types_1": "refused", - "translation/functions/format-number.toml#t002_types_2": "refused", + "translation/functions/format-number.places.pa.hand.toml#p001": "matching", + "translation/functions/format-number.places.pa.hand.toml#p002": "matching", + "translation/functions/format-number.toml#t001_types_1": "matching", + "translation/functions/format-number.toml#t002_types_2": "matching", "translation/functions/format-number.toml#t003_types_3": "refused", "translation/functions/format-number.toml#t004_types_4": "refused", - "translation/functions/format-number.toml#t005_null_1": "refused", - "translation/functions/format-number.toml#t006_null_2": "refused", - "translation/functions/format-number.toml#t007_boundary_1": "refused", - "translation/functions/format-number.toml#t008_boundary_2": "refused", - "translation/functions/format-number.toml#t009_boundary_3": "unrecorded_refused", - "translation/functions/format-number.toml#t010_boundary_4": "refused", + "translation/functions/format-number.toml#t005_null_1": "matching", + "translation/functions/format-number.toml#t006_null_2": "matching", + "translation/functions/format-number.toml#t007_boundary_1": "matching", + "translation/functions/format-number.toml#t008_boundary_2": "matching", + "translation/functions/format-number.toml#t009_boundary_3": "unrecorded_translates", + "translation/functions/format-number.toml#t010_boundary_4": "matching", "translation/functions/format-number.toml#t011_wrong_kind": "refused", "translation/functions/format-string.pc.hand.toml#p001": "matching", "translation/functions/format-string.pcx.hand.toml#p001": "matching", @@ -1492,10 +1533,10 @@ "translation/functions/greatest.hand.toml#t001_int": "matching", "translation/functions/greatest.hand.toml#t002_mixed": "matching", "translation/functions/greatest.hand.toml#t003_null": "matching", - "translation/functions/grouping-id.args.np.hand.toml#p001": "refused", - "translation/functions/grouping-id.hand.toml#t001_rollup": "refused", - "translation/functions/grouping-id.np.hand.toml#p001": "refused", - "translation/functions/grouping.np.hand.toml#p001": "refused", + "translation/functions/grouping-id.args.np.hand.toml#p001": "matching_rejection", + "translation/functions/grouping-id.hand.toml#t001_rollup": "matching", + "translation/functions/grouping-id.np.hand.toml#p001": "matching", + "translation/functions/grouping.np.hand.toml#p001": "matching", "translation/functions/gteqsign.toml#t001_types_1": "matching", "translation/functions/gteqsign.toml#t002_types_2": "matching_error", "translation/functions/gteqsign.toml#t003_types_3": "matching_error", @@ -1921,8 +1962,9 @@ "translation/functions/h3-validate.toml#t006_boundary_1": "refused", "translation/functions/h3-validate.toml#t007_boundary_2": "refused", "translation/functions/h3-validate.toml#t008_wrong_kind": "refused", - "translation/functions/hash.hand.toml#t001_int": "refused", - "translation/functions/hash.hand.toml#t002_null": "refused", + "translation/functions/hash.hand.toml#t001_int": "matching", + "translation/functions/hash.hand.toml#t002_null": "matching", + "translation/functions/hash.more.pa.hand.toml#p001": "matching", "translation/functions/hex.toml#t001_types_1": "matching", "translation/functions/hex.toml#t002_types_2": "matching", "translation/functions/hex.toml#t003_types_3": "matching", @@ -1976,11 +2018,12 @@ "translation/functions/hll-union.toml#t003_null_2": "refused", "translation/functions/hll-union.toml#t004_boundary_1": "refused", "translation/functions/hll-union.toml#t005_wrong_kind": "refused", - "translation/functions/hmac.toml#t001_types_1": "refused", - "translation/functions/hmac.toml#t002_null_1": "refused", - "translation/functions/hmac.toml#t003_null_2": "refused", - "translation/functions/hmac.toml#t004_boundary_1": "refused", - "translation/functions/hmac.toml#t005_boundary_2": "refused", + "translation/functions/hmac.more.pa.hand.toml#p001": "matching", + "translation/functions/hmac.toml#t001_types_1": "matching", + "translation/functions/hmac.toml#t002_null_1": "matching", + "translation/functions/hmac.toml#t003_null_2": "matching", + "translation/functions/hmac.toml#t004_boundary_1": "matching_error", + "translation/functions/hmac.toml#t005_boundary_2": "matching", "translation/functions/hmac.toml#t006_wrong_kind": "refused", "translation/functions/hour.toml#t001_types_1": "matching", "translation/functions/hour.toml#t002_types_2": "matching", @@ -2063,8 +2106,13 @@ "translation/functions/ilike.subscript.toml#t007_boundary_3": "matching_rejection", "translation/functions/ilike.subscript.toml#t008_boundary_4": "matching_rejection", "translation/functions/ilike.subscript.toml#t009_wrong_kind": "matching_rejection", - "translation/functions/in-2.no-null.np.hand.toml#p001": "refused", - "translation/functions/in-2.np.hand.toml#p001": "refused", + "translation/functions/in-2.more.pa.hand.toml#p001": "matching", + "translation/functions/in-2.more.pa.hand.toml#p002": "matching", + "translation/functions/in-2.more.pa.hand.toml#p003": "matching", + "translation/functions/in-2.no-null.np.hand.toml#p001": "matching", + "translation/functions/in-2.np.hand.toml#p001": "matching", + "translation/functions/in-2.string.pa.hand.toml#p001": "matching", + "translation/functions/in-2.where.pa.hand.toml#p001": "matching", "translation/functions/in.in.syntax.toml#t001_types_1": "matching", "translation/functions/in.in.syntax.toml#t002_types_2": "matching_error", "translation/functions/in.in.syntax.toml#t003_types_3": "matching_error", @@ -2085,7 +2133,7 @@ "translation/functions/in.in.toml#t008_boundary_3": "matching", "translation/functions/in.in.toml#t009_boundary_4": "matching", "translation/functions/in.in.toml#t010_wrong_kind": "matching_error", - "translation/functions/in.subscript-dot.hand.toml#t001_subquery": "refused", + "translation/functions/in.subscript-dot.hand.toml#t001_subquery": "matching", "translation/functions/in.syntax.hand.toml#t001_list": "matching", "translation/functions/in.syntax.hand.toml#t002_not": "matching", "translation/functions/initcap.pc.hand.toml#p001": "matching", @@ -2232,6 +2280,9 @@ "translation/functions/isdistinct.toml#t008_boundary_3": "matching", "translation/functions/isdistinct.toml#t009_boundary_4": "matching", "translation/functions/isdistinct.toml#t010_wrong_kind": "matching_error", + "translation/functions/isearch.ascii.pa.hand.toml#p001": "matching", + "translation/functions/isearch.dotted.pa.hand.toml#p001": "matching", + "translation/functions/isearch.sigma.pa.hand.toml#p001": "matching", "translation/functions/isfalse.pc.hand.toml#p001": "matching", "translation/functions/isfalse.toml#t001_types_1": "matching_error", "translation/functions/isfalse.toml#t002_types_2": "matching", @@ -2852,8 +2903,13 @@ "translation/functions/mask.toml#t003_boundary_1": "matching", "translation/functions/mask.toml#t004_boundary_2": "matching", "translation/functions/mask.toml#t005_wrong_kind": "matching_rejection", + "translation/functions/match-number.pa.hand.toml#p001": "refused", + "translation/functions/match-recognize-next.pa.hand.toml#p001": "refused", + "translation/functions/match-recognize.prev-offset.pa.hand.toml#p001": "refused", "translation/functions/max-by.max-by.syntax.hand.toml#t001_pairs": "matching", "translation/functions/max-by.max-by.syntax.hand.toml#t002_n": "matching", + "translation/functions/max-by.null.pa.hand.toml#p001": "matching", + "translation/functions/max-by.types.pa.hand.toml#p001": "matching", "translation/functions/max.toml#t001_types_1": "matching", "translation/functions/max.toml#t002_types_2": "matching", "translation/functions/max.toml#t003_null_1": "matching", @@ -2890,6 +2946,8 @@ "translation/functions/median.toml#t008_wrong_kind": "matching_error", "translation/functions/min-by.min-by.syntax.hand.toml#t001_pairs": "matching", "translation/functions/min-by.min-by.syntax.hand.toml#t002_n": "matching", + "translation/functions/min-by.null.pa.hand.toml#p001": "matching", + "translation/functions/min-by.types.pa.hand.toml#p001": "matching", "translation/functions/min.toml#t001_types_1": "matching", "translation/functions/min.toml#t002_types_2": "matching", "translation/functions/min.toml#t003_null_1": "matching", @@ -3227,6 +3285,8 @@ "translation/functions/pipepipesign.hand.toml#t002_int": "matching", "translation/functions/pipepipesign.hand.toml#t003_null": "matching", "translation/functions/pipepipesign.pc.hand.toml#p001": "matching", + "translation/functions/pipesign.mixed.pa.hand.toml#p001": "matching", + "translation/functions/pipesign.strings.pa.hand.toml#p001": "matching", "translation/functions/pipesign.syntax.syntax.toml#t001_types_1": "matching", "translation/functions/pipesign.syntax.syntax.toml#t002_types_2": "matching", "translation/functions/pipesign.syntax.syntax.toml#t003_types_3": "matching", @@ -3346,6 +3406,8 @@ "translation/functions/quarter.toml#t007_wrong_kind": "matching_error", "translation/functions/questiondoublecolonsign.hand.toml#t001_int": "matching", "translation/functions/questiondoublecolonsign.hand.toml#t002_null": "matching", + "translation/functions/questiondoublecolonsign.null.pa.hand.toml#p001": "matching", + "translation/functions/questiondoublecolonsign.pa.hand.toml#p001": "matching", "translation/functions/radians.toml#t001_types_1": "matching", "translation/functions/radians.toml#t002_types_2": "matching", "translation/functions/radians.toml#t003_types_3": "matching", @@ -3353,6 +3415,7 @@ "translation/functions/radians.toml#t005_boundary_1": "matching", "translation/functions/radians.toml#t006_boundary_2": "matching", "translation/functions/radians.toml#t007_wrong_kind": "matching_error", + "translation/functions/raise-error.guarded.pa.hand.toml#p001": "matching", "translation/functions/raise-error.np.hand.toml#p001": "matching_error", "translation/functions/raise-error.np.hand.toml#p002": "matching_error", "translation/functions/raise-error.toml#t001_types_1": "matching_error", @@ -3672,6 +3735,8 @@ "translation/functions/schema-of-xml.toml#t003_boundary_1": "refused", "translation/functions/schema-of-xml.toml#t004_boundary_2": "refused", "translation/functions/schema-of-xml.toml#t005_wrong_kind": "refused", + "translation/functions/search.skipped.pa.hand.toml#p001": "matching", + "translation/functions/search.strings.pa.hand.toml#p001": "matching", "translation/functions/sec.toml#t001_types_1": "refused", "translation/functions/sec.toml#t002_types_2": "refused", "translation/functions/sec.toml#t003_types_3": "refused", @@ -3696,6 +3761,10 @@ "translation/functions/sequence.step-errors.np.hand.toml#p002": "matching_error", "translation/functions/sequence.step-errors.np.hand.toml#p003": "matching_error", "translation/functions/sequence.step.np.hand.toml#p001": "matching", + "translation/functions/sequence.text-both.pa.hand.toml#p001": "matching_rejection", + "translation/functions/sequence.text.pa.hand.toml#p001": "matching", + "translation/functions/sequence.text.pa.hand.toml#p002": "matching", + "translation/functions/sequence.text.pa.hand.toml#p003": "matching_error", "translation/functions/sequence.toml#t001_types_1": "matching", "translation/functions/sequence.toml#t002_types_2": "matching_rejection", "translation/functions/sequence.toml#t003_types_3": "matching_rejection", @@ -3706,7 +3775,7 @@ "translation/functions/sequence.toml#t008_boundary_2": "matching_error", "translation/functions/sequence.toml#t009_boundary_3": "matching_error", "translation/functions/sequence.toml#t010_boundary_4": "matching_error", - "translation/functions/sequence.toml#t011_wrong_kind": "refused", + "translation/functions/sequence.toml#t011_wrong_kind": "matching_error", "translation/functions/session-window.toml#t001_types_1": "refused", "translation/functions/session-window.toml#t002_types_2": "refused", "translation/functions/session-window.toml#t003_null_1": "refused", @@ -4578,7 +4647,11 @@ "translation/functions/time-bucket.toml#t006_boundary_1": "matching_rejection", "translation/functions/time-bucket.toml#t007_boundary_2": "matching_rejection", "translation/functions/time-bucket.toml#t008_wrong_kind": "matching_rejection", - "translation/functions/time-diff.pt.hand.toml#p001": "refused", + "translation/functions/time-diff.hour.pa.hand.toml#p001": "matching", + "translation/functions/time-diff.lower.pa.hand.toml#p001": "matching", + "translation/functions/time-diff.micro.pa.hand.toml#p001": "matching", + "translation/functions/time-diff.pt.hand.toml#p001": "matching_rejection", + "translation/functions/time-diff.strings.pa.hand.toml#p001": "matching", "translation/functions/time-from-micros.toml#t001_types_1": "matching_error", "translation/functions/time-from-micros.toml#t002_types_2": "matching_error", "translation/functions/time-from-micros.toml#t003_types_3": "matching_error", @@ -4958,6 +5031,8 @@ "translation/functions/try-avg.toml#t006_boundary_1": "matching", "translation/functions/try-avg.toml#t007_boundary_2": "matching", "translation/functions/try-avg.toml#t008_wrong_kind": "matching_error", + "translation/functions/try-cast.null.pa.hand.toml#p001": "matching", + "translation/functions/try-cast.string-int.pa.hand.toml#p001": "matching", "translation/functions/try-divide.toml#t001_types_1": "matching", "translation/functions/try-divide.toml#t002_types_2": "matching", "translation/functions/try-divide.toml#t003_types_3": "matching", @@ -5484,6 +5559,7 @@ "translation/functions/variant-get.toml#t007_boundary_3": "refused", "translation/functions/variant-get.toml#t008_boundary_4": "refused", "translation/functions/variant-get.toml#t009_wrong_kind": "refused", + "translation/functions/vector-avg.precision.pa.hand.toml#p001": "refused", "translation/functions/vector-avg.toml#t001_types_1": "refused", "translation/functions/vector-avg.toml#t002_null_1": "refused", "translation/functions/vector-avg.toml#t003_boundary_1": "refused", @@ -5508,13 +5584,15 @@ "translation/functions/vector-inner-product.toml#t004_boundary_1": "matching", "translation/functions/vector-inner-product.toml#t005_boundary_2": "matching", "translation/functions/vector-inner-product.toml#t006_wrong_kind": "matching_rejection", - "translation/functions/vector-l2-distance.pf.hand.toml#p001": "refused", - "translation/functions/vector-l2-distance.toml#t001_types_1": "refused", - "translation/functions/vector-l2-distance.toml#t002_null_1": "refused", - "translation/functions/vector-l2-distance.toml#t003_null_2": "refused", - "translation/functions/vector-l2-distance.toml#t004_boundary_1": "refused", - "translation/functions/vector-l2-distance.toml#t005_boundary_2": "refused", - "translation/functions/vector-l2-distance.toml#t006_wrong_kind": "refused", + "translation/functions/vector-l2-distance.lengths.pa.hand.toml#p001": "matching_error", + "translation/functions/vector-l2-distance.pf.hand.toml#p001": "matching", + "translation/functions/vector-l2-distance.precision.pa.hand.toml#p001": "refused", + "translation/functions/vector-l2-distance.toml#t001_types_1": "matching", + "translation/functions/vector-l2-distance.toml#t002_null_1": "matching", + "translation/functions/vector-l2-distance.toml#t003_null_2": "matching", + "translation/functions/vector-l2-distance.toml#t004_boundary_1": "matching", + "translation/functions/vector-l2-distance.toml#t005_boundary_2": "matching", + "translation/functions/vector-l2-distance.toml#t006_wrong_kind": "matching_rejection", "translation/functions/vector-norm.pf.hand.toml#p001": "matching", "translation/functions/vector-norm.toml#t001_types_1": "matching", "translation/functions/vector-norm.toml#t002_null_1": "matching", @@ -5522,10 +5600,13 @@ "translation/functions/vector-norm.toml#t004_wrong_kind": "matching_rejection", "translation/functions/vector-normalize.pf.hand.toml#p001": "refused", "translation/functions/vector-normalize.pf.hand.toml#p002": "refused", + "translation/functions/vector-normalize.precision.pa.hand.toml#p001": "refused", "translation/functions/vector-normalize.toml#t001_types_1": "refused", "translation/functions/vector-normalize.toml#t002_null_1": "refused", "translation/functions/vector-normalize.toml#t003_boundary_1": "refused", "translation/functions/vector-normalize.toml#t004_wrong_kind": "refused", + "translation/functions/vector-sum.lengths.pa.hand.toml#p001": "refused", + "translation/functions/vector-sum.precision.pa.hand.toml#p001": "refused", "translation/functions/vector-sum.toml#t001_types_1": "refused", "translation/functions/vector-sum.toml#t002_null_1": "refused", "translation/functions/vector-sum.toml#t003_boundary_1": "refused", @@ -5727,12 +5808,13 @@ "translation/functions/xpath.toml#t006_boundary_3": "refused", "translation/functions/xpath.toml#t007_boundary_4": "refused", "translation/functions/xpath.toml#t008_wrong_kind": "refused", - "translation/functions/xxhash64.toml#t001_types_1": "refused", - "translation/functions/xxhash64.toml#t002_types_2": "refused", - "translation/functions/xxhash64.toml#t003_null_1": "refused", - "translation/functions/xxhash64.toml#t004_boundary_1": "refused", - "translation/functions/xxhash64.toml#t005_boundary_2": "refused", - "translation/functions/xxhash64.toml#t006_wrong_kind": "refused", + "translation/functions/xxhash64.more.pa.hand.toml#p001": "matching", + "translation/functions/xxhash64.toml#t001_types_1": "matching", + "translation/functions/xxhash64.toml#t002_types_2": "matching", + "translation/functions/xxhash64.toml#t003_null_1": "matching", + "translation/functions/xxhash64.toml#t004_boundary_1": "matching", + "translation/functions/xxhash64.toml#t005_boundary_2": "matching", + "translation/functions/xxhash64.toml#t006_wrong_kind": "matching", "translation/functions/year.toml#t001_types_1": "matching", "translation/functions/year.toml#t002_types_2": "matching", "translation/functions/year.toml#t003_types_3": "matching", @@ -5779,9 +5861,18 @@ "translation/query/hive-grouping-sets.one.pe.hand.toml#p001": "matching", "translation/query/hive-grouping-sets.three.pe.hand.toml#p001": "matching", "translation/query/hive-grouping-sets.three.pe.hand.toml#p002": "matching", + "translation/query/match-recognize.all-rows.pa.hand.toml#p001": "refused", + "translation/query/match-recognize.partition.pa.hand.toml#p001": "refused", + "translation/query/match-recognize.pattern.pa.hand.toml#p001": "refused", + "translation/query/match-recognize.rises.pa.hand.toml#p001": "refused", + "translation/query/names.pa.hand.toml#p001": "matching", + "translation/query/names.pa.hand.toml#p002": "matching", + "translation/query/names.pa.hand.toml#p003": "matching", "translation/query/nested-grouping-sets.rollup.pe.hand.toml#p001": "matching", "translation/query/nested-grouping-sets.sets.pe.hand.toml#p001": "matching", "translation/query/nested-grouping-sets.sets.pe.hand.toml#p002": "matching", + "translation/query/pipeline.from.pa.hand.toml#p001": "matching", + "translation/query/pipeline.table.pa.hand.toml#p001": "matching", "translation/query/query.window.pe.hand.toml#p001": "matching", "translation/query/select-clusterby.pe.hand.toml#p001": "matching", "translation/query/select-clusterby.pe.hand.toml#p002": "matching", @@ -5893,6 +5984,7 @@ "translation/query/select-unpivot.plain.pe.hand.toml#p002": "matching", "translation/query/select-values.named.pe.hand.toml#p001": "matching", "translation/query/select-values.rows.pf.hand.toml#p001": "matching", + "translation/query/select-values.select.pa.hand.toml#p001": "matching", "translation/query/select-values.unnamed.pe.hand.toml#p001": "matching", "translation/query/select-where.pe.hand.toml#p001": "matching", "translation/query/select-where.pe.hand.toml#p002": "matching", @@ -6081,7 +6173,7 @@ "db.expressions.interval-type.interval": "matching", "db.expressions.interval-type.interval.literals": "matching", "db.expressions.json-path-expression": "unmeasured", - "db.expressions.lambda-functions": "refused", + "db.expressions.lambda-functions": "no_obligations", "db.expressions.map-type": "matching", "db.expressions.names-identifier-clause.identifier": "matching", "db.expressions.names-identifier-clause.identifier.syntax": "matching", @@ -6111,7 +6203,7 @@ "db.expressions.string-type.subscript-dot": "matching", "db.expressions.struct-type": "refused", "db.expressions.time-type.time": "refused", - "db.expressions.time-type.time.literals": "refused", + "db.expressions.time-type.time.literals": "matching", "db.expressions.time-type.time.syntax": "unmeasured", "db.expressions.timestamp-ntz-type.timestamp-ntz": "matching", "db.expressions.timestamp-ntz-type.timestamp-ntz.literals": "matching", @@ -6124,7 +6216,7 @@ "db.expressions.tinyint-type.y": "matching", "db.expressions.variant-type": "refused", "db.expressions.window-functions": "matching", - "db.expressions.window-functions-frame": "refused", + "db.expressions.window-functions-frame": "matching", "db.functions.abs": "matching", "db.functions.acos": "refused", "db.functions.acosh": "refused", @@ -6182,7 +6274,7 @@ "db.functions.array-remove": "matching", "db.functions.array-repeat": "matching", "db.functions.array-size": "matching", - "db.functions.array-sort": "unmet_obligations", + "db.functions.array-sort": "refused", "db.functions.array-union": "matching", "db.functions.arrays-overlap": "matching", "db.functions.arrays-zip": "refused", @@ -6225,7 +6317,7 @@ "db.functions.caretsign": "matching", "db.functions.case.end": "matching", "db.functions.case.end.syntax": "matching", - "db.functions.cast": "no_obligations", + "db.functions.cast": "refused", "db.functions.cbrt": "refused", "db.functions.ceil": "matching", "db.functions.ceiling": "matching", @@ -6257,8 +6349,8 @@ "db.functions.count-if": "matching", "db.functions.count-min-sketch": "not_translatable", "db.functions.count.count": "matching", - "db.functions.count.count.syntax": "no_obligations", - "db.functions.counter-diff": "refused", + "db.functions.count.count.syntax": "matching", + "db.functions.counter-diff": "matching", "db.functions.covar-pop": "refused", "db.functions.covar-samp": "refused", "db.functions.crc32": "refused", @@ -6278,7 +6370,7 @@ "db.functions.current-snapshot-version": "not_translatable", "db.functions.current-time": "unmeasured", "db.functions.current-timestamp": "unmeasured", - "db.functions.current-timezone": "unmeasured", + "db.functions.current-timezone": "refused", "db.functions.current-user": "not_translatable", "db.functions.current-version": "not_translatable", "db.functions.data-skipping-summary": "not_translatable", @@ -6301,7 +6393,7 @@ "db.functions.dayofweek": "matching", "db.functions.dayofyear": "matching", "db.functions.decimal": "matching", - "db.functions.decode": "no_obligations", + "db.functions.decode": "matching", "db.functions.decode-cs": "matching", "db.functions.degrees": "matching", "db.functions.dense-rank": "matching", @@ -6348,8 +6440,8 @@ "db.functions.getbit": "matching", "db.functions.getdate": "unmeasured", "db.functions.greatest": "matching", - "db.functions.grouping": "refused", - "db.functions.grouping-id": "refused", + "db.functions.grouping": "matching", + "db.functions.grouping-id": "matching", "db.functions.gteqsign": "matching", "db.functions.gtgtgtsign": "matching", "db.functions.gtgtsign": "matching", @@ -6393,7 +6485,7 @@ "db.functions.h3-try-validate": "not_translatable", "db.functions.h3-uncompact": "not_translatable", "db.functions.h3-validate": "not_translatable", - "db.functions.hash": "refused", + "db.functions.hash": "matching", "db.functions.hex": "matching", "db.functions.histogram-numeric": "refused", "db.functions.hll-sketch-agg": "not_translatable", @@ -6410,8 +6502,8 @@ "db.functions.ilike.ilike": "matching", "db.functions.ilike.ilike-any-some-all": "matching", "db.functions.in.in": "matching", - "db.functions.in.in-2": "unmeasured", - "db.functions.in.in.syntax": "refused", + "db.functions.in.in-2": "matching", + "db.functions.in.in.syntax": "matching", "db.functions.initcap": "matching", "db.functions.inline": "refused", "db.functions.inline-outer": "refused", @@ -6435,7 +6527,7 @@ "db.functions.is-valid-utf8": "matching", "db.functions.is-variant-null": "refused", "db.functions.isdistinct": "matching", - "db.functions.isearch": "unmeasured", + "db.functions.isearch": "matching", "db.functions.isfalse": "matching", "db.functions.isnan": "matching", "db.functions.isnotnull": "matching", @@ -6529,14 +6621,14 @@ "db.functions.match-recognize-next": "unmeasured", "db.functions.match-recognize-prev": "unmeasured", "db.functions.max": "matching", - "db.functions.max-by.max-by": "no_obligations", + "db.functions.max-by.max-by": "matching", "db.functions.max-by.max-by.syntax": "matching", "db.functions.md5": "matching", "db.functions.mean": "matching", "db.functions.measure": "not_translatable", "db.functions.median": "matching", "db.functions.min": "matching", - "db.functions.min-by.min-by": "no_obligations", + "db.functions.min-by.min-by": "matching", "db.functions.min-by.min-by.syntax": "matching", "db.functions.minussign": "matching", "db.functions.minussignunary": "matching", @@ -6590,7 +6682,7 @@ "db.functions.quarter": "matching", "db.functions.questiondoublecolonsign": "unmeasured", "db.functions.radians": "matching", - "db.functions.raise-error": "syntax_only", + "db.functions.raise-error": "matching", "db.functions.rand": "unmeasured", "db.functions.randn": "unmeasured", "db.functions.random": "unmeasured", @@ -6641,12 +6733,12 @@ "db.functions.schema-of-variant": "refused", "db.functions.schema-of-variant-agg": "refused", "db.functions.schema-of-xml": "refused", - "db.functions.search": "unmeasured", + "db.functions.search": "matching", "db.functions.sec": "refused", "db.functions.second": "matching", "db.functions.secret": "not_translatable", "db.functions.sentences": "refused", - "db.functions.sequence": "refused", + "db.functions.sequence": "matching", "db.functions.session-user": "not_translatable", "db.functions.session-window": "refused", "db.functions.sha": "matching", @@ -6800,7 +6892,7 @@ "db.functions.tildesign": "matching", "db.functions.time": "matching", "db.functions.time-bucket": "matching", - "db.functions.time-diff": "refused", + "db.functions.time-diff": "matching", "db.functions.time-from-micros": "matching", "db.functions.time-from-millis": "matching", "db.functions.time-from-seconds": "matching", @@ -6853,7 +6945,7 @@ "db.functions.try-add": "matching", "db.functions.try-aes-decrypt": "refused", "db.functions.try-avg": "matching", - "db.functions.try-cast": "no_obligations", + "db.functions.try-cast": "matching", "db.functions.try-copy-file": "not_translatable", "db.functions.try-divide": "matching", "db.functions.try-element-at": "matching", @@ -6935,7 +7027,7 @@ "db.functions.vector-avg": "refused", "db.functions.vector-cosine-similarity": "matching", "db.functions.vector-inner-product": "matching", - "db.functions.vector-l2-distance": "refused", + "db.functions.vector-l2-distance": "unmet_obligations", "db.functions.vector-norm": "matching", "db.functions.vector-normalize": "refused", "db.functions.vector-search.query-num-results": "not_translatable", @@ -6956,7 +7048,7 @@ "db.functions.xpath-number": "refused", "db.functions.xpath-short": "refused", "db.functions.xpath-string": "refused", - "db.functions.xxhash64": "refused", + "db.functions.xxhash64": "matching", "db.functions.year": "matching", "db.functions.zeroifnull": "matching", "db.functions.zip-with": "matching", @@ -6982,10 +7074,10 @@ "db.query.select-join": "matching", "db.query.select-lateral-view": "matching", "db.query.select-limit": "matching", - "db.query.select-match-recognize": "unmeasured", - "db.query.select-match-recognize-define": "unmeasured", - "db.query.select-match-recognize-measures": "unmeasured", - "db.query.select-match-recognize-pattern": "unmeasured", + "db.query.select-match-recognize": "refused", + "db.query.select-match-recognize-define": "refused", + "db.query.select-match-recognize-measures": "refused", + "db.query.select-match-recognize-pattern": "refused", "db.query.select-named-window": "matching", "db.query.select-nearest-by": "not_translatable", "db.query.select-offset": "matching", @@ -7208,7 +7300,9 @@ "db.expressions.binary-type.x.t001": "met", "db.expressions.boolean-type.t001": "met", "db.expressions.boolean-type.true-false.t001": "met", - "db.expressions.collation.order-by-collate-utf8-lcase.t001": "unmet", + "db.expressions.collation.order-by-collate-utf8-lcase.t001": "met", + "db.expressions.collation.order-by-collate-utf8-lcase.t002": "met", + "db.expressions.collation.order-by-lower-collate.t001": "met", "db.expressions.comment.t001": "met", "db.expressions.date-type.date.t001": "met", "db.expressions.date-type.date.t002": "met", @@ -7238,9 +7332,11 @@ "db.expressions.names-identifier-clause.identifier.syntax.t001": "met", "db.expressions.names-identifier-clause.identifier.t001": "met", "db.expressions.names.identifier-3.t001": "met", + "db.expressions.names.identifier.syntax.t001": "met", "db.expressions.names.subscript-dot-2.t001": "met", "db.expressions.names.subscript-dot-3.t001": "met", "db.expressions.names.subscript.t001": "met", + "db.expressions.names.syntax.t001": "met", "db.expressions.null-type.t001": "met", "db.expressions.smallint-type.s.t001": "met", "db.expressions.smallint-type.t001": "met", @@ -7250,8 +7346,9 @@ "db.expressions.struct-type.t001": "unmet", "db.expressions.struct-type.t002": "unmet", "db.expressions.time-type.time.literals.t001": "met", - "db.expressions.time-type.time.literals.t002": "unmet", + "db.expressions.time-type.time.literals.t002": "met", "db.expressions.time-type.time.syntax.t001": "unmet", + "db.expressions.time-type.time.syntax.t002": "unmet", "db.expressions.time-type.time.t001": "met", "db.expressions.time-type.time.t002": "met", "db.expressions.time-type.time.t003": "met", @@ -7266,8 +7363,12 @@ "db.expressions.tinyint-type.y.t001": "met", "db.expressions.variant-type.t001": "unmet", "db.expressions.window-functions-frame.t001": "met", - "db.expressions.window-functions-frame.t002": "unmet", + "db.expressions.window-functions-frame.t002": "met", "db.expressions.window-functions-frame.t003": "met", + "db.expressions.window-functions-frame.t004": "met", + "db.expressions.window-functions-frame.t005": "met", + "db.expressions.window-functions-frame.t006": "met", + "db.expressions.window-functions-frame.t007": "met", "db.expressions.window-functions.t001": "met", "db.expressions.window-functions.t002": "met", "db.expressions.window-functions.t003": "met", @@ -7321,8 +7422,8 @@ "db.functions.and.t004": "met", "db.functions.any-value.t001": "unmet", "db.functions.any-value.t002": "unmet", - "db.functions.any-value.t003": "unmet", - "db.functions.any-value.t004": "unmet", + "db.functions.any-value.t003": "met", + "db.functions.any-value.t004": "met", "db.functions.any.t001": "met", "db.functions.any.t002": "met", "db.functions.any.t003": "met", @@ -7640,11 +7741,14 @@ "db.functions.bitmap-bucket-number.t003": "met", "db.functions.bitmap-bucket-number.t004": "met", "db.functions.bitmap-bucket-number.t005": "met", - "db.functions.bitmap-construct-agg.t001": "unmet", - "db.functions.bitmap-construct-agg.t002": "unmet", - "db.functions.bitmap-construct-agg.t003": "unmet", - "db.functions.bitmap-construct-agg.t004": "unmet", - "db.functions.bitmap-construct-agg.t005": "unmet", + "db.functions.bitmap-construct-agg.t001": "met", + "db.functions.bitmap-construct-agg.t002": "met", + "db.functions.bitmap-construct-agg.t003": "met", + "db.functions.bitmap-construct-agg.t004": "met", + "db.functions.bitmap-construct-agg.t005": "met", + "db.functions.bitmap-construct-agg.t006": "met", + "db.functions.bitmap-construct-agg.t007": "met", + "db.functions.bitmap-construct-agg.t008": "unmet", "db.functions.bitmap-count.t001": "met", "db.functions.bitmap-count.t002": "met", "db.functions.bitmap-count.t003": "met", @@ -7711,6 +7815,11 @@ "db.functions.case.end.t006": "met", "db.functions.case.end.t007": "met", "db.functions.case.end.t008": "met", + "db.functions.cast.t001": "met", + "db.functions.cast.t002": "met", + "db.functions.cast.t003": "met", + "db.functions.cast.t004": "met", + "db.functions.cast.t005": "met", "db.functions.cbrt.t001": "unmet", "db.functions.cbrt.t002": "unmet", "db.functions.cbrt.t003": "unmet", @@ -7748,10 +7857,13 @@ "db.functions.chr.t003": "met", "db.functions.chr.t004": "met", "db.functions.chr.t005": "met", + "db.functions.classifier.t001": "unmet", "db.functions.coalesce.t001": "met", "db.functions.coalesce.t002": "met", "db.functions.coalesce.t003": "met", "db.functions.coalesce.t004": "met", + "db.functions.collate.t001": "met", + "db.functions.collate.t002": "unmet", "db.functions.collation.t001": "met", "db.functions.collation.t002": "met", "db.functions.collation.t003": "met", @@ -7786,18 +7898,20 @@ "db.functions.contains.t006": "met", "db.functions.contains.t007": "met", "db.functions.contains.t008": "met", - "db.functions.conv.t001": "met", - "db.functions.conv.t002": "met", + "db.functions.conv.t001": "unmet", + "db.functions.conv.t002": "unmet", "db.functions.conv.t003": "met", "db.functions.conv.t004": "met", "db.functions.conv.t005": "met", "db.functions.conv.t006": "met", "db.functions.conv.t007": "met", - "db.functions.conv.t008": "unmet", + "db.functions.conv.t008": "met", "db.functions.conv.t009": "met", - "db.functions.conv.t010": "met", + "db.functions.conv.t010": "unmet", "db.functions.conv.t011": "met", "db.functions.conv.t012": "met", + "db.functions.conv.t013": "met", + "db.functions.conv.t014": "met", "db.functions.convert-timezone.t001": "met", "db.functions.convert-timezone.t002": "met", "db.functions.convert-timezone.t003": "met", @@ -7849,8 +7963,10 @@ "db.functions.count-min-sketch.t018": "unmet", "db.functions.count-min-sketch.t019": "unmet", "db.functions.count-min-sketch.t020": "unmet", + "db.functions.count.count.syntax.t001": "met", + "db.functions.count.count.syntax.t002": "met", "db.functions.count.count.t001": "met", - "db.functions.counter-diff.t001": "unmet", + "db.functions.counter-diff.t001": "met", "db.functions.counter-diff.t002": "met", "db.functions.counter-diff.t003": "met", "db.functions.counter-diff.t004": "met", @@ -7859,6 +7975,10 @@ "db.functions.counter-diff.t007": "met", "db.functions.counter-diff.t008": "met", "db.functions.counter-diff.t009": "met", + "db.functions.counter-diff.t010": "met", + "db.functions.counter-diff.t011": "met", + "db.functions.counter-diff.t012": "met", + "db.functions.counter-diff.t013": "met", "db.functions.covar-pop.t001": "unmet", "db.functions.covar-pop.t002": "unmet", "db.functions.covar-pop.t003": "unmet", @@ -7873,9 +7993,10 @@ "db.functions.covar-samp.t005": "unmet", "db.functions.covar-samp.t006": "unmet", "db.functions.covar-samp.t007": "unmet", - "db.functions.crc32.t001": "unmet", - "db.functions.crc32.t002": "unmet", - "db.functions.crc32.t003": "unmet", + "db.functions.crc32.t001": "met", + "db.functions.crc32.t002": "met", + "db.functions.crc32.t003": "met", + "db.functions.crc32.t004": "unmet", "db.functions.csc.t001": "unmet", "db.functions.csc.t002": "unmet", "db.functions.csc.t003": "unmet", @@ -7888,6 +8009,7 @@ "db.functions.cube.t005": "met", "db.functions.cume-dist.t001": "met", "db.functions.cume-dist.t002": "met", + "db.functions.current-timezone.t001": "unmet", "db.functions.date-add.t001": "met", "db.functions.date-add.t002": "met", "db.functions.date-add.t003": "met", @@ -7905,7 +8027,7 @@ "db.functions.date-format.t003": "met", "db.functions.date-format.t004": "met", "db.functions.date-format.t005": "met", - "db.functions.date-format.t006": "unmet", + "db.functions.date-format.t006": "met", "db.functions.date-format.t007": "unmet", "db.functions.date-format.t008": "unmet", "db.functions.date-format.t009": "unmet", @@ -7992,6 +8114,9 @@ "db.functions.decode-cs.t004": "met", "db.functions.decode-cs.t005": "met", "db.functions.decode-cs.t006": "met", + "db.functions.decode.t001": "met", + "db.functions.decode.t002": "met", + "db.functions.decode.t003": "met", "db.functions.degrees.t001": "met", "db.functions.degrees.t002": "met", "db.functions.degrees.t003": "met", @@ -8138,16 +8263,24 @@ "db.functions.forall.t002": "met", "db.functions.forall.t003": "met", "db.functions.forall.t004": "met", - "db.functions.format-number.t001": "unmet", - "db.functions.format-number.t002": "unmet", + "db.functions.format-number.t001": "met", + "db.functions.format-number.t002": "met", "db.functions.format-number.t003": "unmet", - "db.functions.format-number.t004": "unmet", + "db.functions.format-number.t004": "met", "db.functions.format-number.t005": "unmet", "db.functions.format-number.t006": "unmet", "db.functions.format-number.t007": "unmet", "db.functions.format-number.t008": "unmet", "db.functions.format-number.t009": "unmet", - "db.functions.format-number.t010": "unmet", + "db.functions.format-number.t010": "met", + "db.functions.format-number.t011": "met", + "db.functions.format-number.t012": "met", + "db.functions.format-number.t013": "met", + "db.functions.format-number.t014": "unmet", + "db.functions.format-number.t015": "unmet", + "db.functions.format-number.t016": "met", + "db.functions.format-number.t017": "met", + "db.functions.format-number.t018": "unmet", "db.functions.format-string.t001": "met", "db.functions.format-string.t002": "met", "db.functions.format-string.t003": "met", @@ -8219,10 +8352,10 @@ "db.functions.greatest.t001": "met", "db.functions.greatest.t002": "met", "db.functions.greatest.t003": "met", - "db.functions.grouping-id.t001": "unmet", - "db.functions.grouping-id.t002": "unmet", - "db.functions.grouping-id.t003": "unmet", - "db.functions.grouping.t001": "unmet", + "db.functions.grouping-id.t001": "met", + "db.functions.grouping-id.t002": "met", + "db.functions.grouping-id.t003": "met", + "db.functions.grouping.t001": "met", "db.functions.gteqsign.t001": "met", "db.functions.gteqsign.t002": "met", "db.functions.gteqsign.t003": "met", @@ -8504,8 +8637,9 @@ "db.functions.h3-validate.t004": "unmet", "db.functions.h3-validate.t005": "unmet", "db.functions.h3-validate.t006": "unmet", - "db.functions.hash.t001": "unmet", - "db.functions.hash.t002": "unmet", + "db.functions.hash.t001": "met", + "db.functions.hash.t002": "met", + "db.functions.hash.t003": "met", "db.functions.hex.t001": "met", "db.functions.hex.t002": "met", "db.functions.hex.t003": "met", @@ -8544,10 +8678,11 @@ "db.functions.hll-union.t002": "unmet", "db.functions.hll-union.t003": "unmet", "db.functions.hll-union.t004": "unmet", - "db.functions.hmac.t001": "unmet", - "db.functions.hmac.t002": "unmet", - "db.functions.hmac.t003": "unmet", - "db.functions.hmac.t004": "unmet", + "db.functions.hmac.t001": "met", + "db.functions.hmac.t002": "met", + "db.functions.hmac.t003": "met", + "db.functions.hmac.t004": "met", + "db.functions.hmac.t005": "unmet", "db.functions.hour.t001": "met", "db.functions.hour.t002": "met", "db.functions.hour.t003": "met", @@ -8588,8 +8723,11 @@ "db.functions.ilike.ilike.t003": "met", "db.functions.ilike.ilike.t004": "met", "db.functions.ilike.ilike.t005": "met", - "db.functions.in.in-2.t001": "unmet", - "db.functions.in.in-2.t002": "unmet", + "db.functions.in.in-2.t001": "met", + "db.functions.in.in-2.t002": "met", + "db.functions.in.in-2.t003": "met", + "db.functions.in.in-2.t004": "met", + "db.functions.in.in-2.t005": "met", "db.functions.in.in.syntax.t001": "met", "db.functions.in.in.syntax.t002": "met", "db.functions.in.in.syntax.t003": "met", @@ -8701,6 +8839,9 @@ "db.functions.isdistinct.t004": "met", "db.functions.isdistinct.t005": "met", "db.functions.isdistinct.t006": "met", + "db.functions.isearch.t001": "met", + "db.functions.isearch.t002": "met", + "db.functions.isearch.t003": "met", "db.functions.isfalse.t001": "met", "db.functions.isfalse.t002": "met", "db.functions.isfalse.t003": "met", @@ -9116,8 +9257,13 @@ "db.functions.mask.t004": "met", "db.functions.mask.t005": "met", "db.functions.mask.t006": "met", + "db.functions.match-number.t001": "unmet", + "db.functions.match-recognize-next.t001": "unmet", + "db.functions.match-recognize-prev.t001": "unmet", "db.functions.max-by.max-by.syntax.t001": "met", "db.functions.max-by.max-by.syntax.t002": "met", + "db.functions.max-by.max-by.t001": "met", + "db.functions.max-by.max-by.t002": "met", "db.functions.max.t001": "met", "db.functions.max.t002": "met", "db.functions.max.t003": "met", @@ -9147,6 +9293,8 @@ "db.functions.median.t015": "met", "db.functions.min-by.min-by.syntax.t001": "met", "db.functions.min-by.min-by.syntax.t002": "met", + "db.functions.min-by.min-by.t001": "met", + "db.functions.min-by.min-by.t002": "met", "db.functions.min.t001": "met", "db.functions.min.t002": "met", "db.functions.min.t003": "met", @@ -9389,11 +9537,13 @@ "db.functions.pipesign.syntax.syntax.t003": "met", "db.functions.pipesign.syntax.syntax.t004": "met", "db.functions.pipesign.syntax.syntax.t005": "met", + "db.functions.pipesign.syntax.syntax.t006": "met", "db.functions.pipesign.syntax.t001": "met", "db.functions.pipesign.syntax.t002": "met", "db.functions.pipesign.syntax.t003": "met", "db.functions.pipesign.syntax.t004": "met", "db.functions.pipesign.syntax.t005": "met", + "db.functions.pipesign.syntax.t006": "met", "db.functions.plussign.t001": "met", "db.functions.plussign.t002": "met", "db.functions.plussign.t003": "met", @@ -9463,6 +9613,8 @@ "db.functions.quarter.t005": "met", "db.functions.questiondoublecolonsign.t001": "met", "db.functions.questiondoublecolonsign.t002": "met", + "db.functions.questiondoublecolonsign.t003": "met", + "db.functions.questiondoublecolonsign.t004": "met", "db.functions.radians.t001": "met", "db.functions.radians.t002": "met", "db.functions.radians.t003": "met", @@ -9473,6 +9625,7 @@ "db.functions.raise-error.t003": "met", "db.functions.raise-error.t004": "met", "db.functions.raise-error.t005": "met", + "db.functions.raise-error.t006": "met", "db.functions.range.t001": "met", "db.functions.range.t002": "met", "db.functions.range.t003": "met", @@ -9673,6 +9826,8 @@ "db.functions.schema-of-xml.t002": "unmet", "db.functions.schema-of-xml.t003": "unmet", "db.functions.schema-of-xml.t004": "unmet", + "db.functions.search.t001": "met", + "db.functions.search.t002": "met", "db.functions.sec.t001": "unmet", "db.functions.sec.t002": "unmet", "db.functions.sec.t003": "unmet", @@ -9697,7 +9852,11 @@ "db.functions.sequence.t010": "met", "db.functions.sequence.t011": "met", "db.functions.sequence.t012": "met", - "db.functions.sequence.t013": "unmet", + "db.functions.sequence.t013": "met", + "db.functions.sequence.t014": "met", + "db.functions.sequence.t015": "met", + "db.functions.sequence.t016": "met", + "db.functions.sequence.t017": "met", "db.functions.session-window.t001": "unmet", "db.functions.session-window.t002": "unmet", "db.functions.session-window.t003": "unmet", @@ -10373,7 +10532,11 @@ "db.functions.time-bucket.t012": "met", "db.functions.time-bucket.t013": "met", "db.functions.time-bucket.t014": "met", - "db.functions.time-diff.t001": "unmet", + "db.functions.time-diff.t001": "met", + "db.functions.time-diff.t002": "met", + "db.functions.time-diff.t003": "met", + "db.functions.time-diff.t004": "met", + "db.functions.time-diff.t005": "met", "db.functions.time-from-micros.t001": "met", "db.functions.time-from-micros.t002": "met", "db.functions.time-from-micros.t003": "met", @@ -10633,6 +10796,8 @@ "db.functions.try-avg.t004": "met", "db.functions.try-avg.t005": "met", "db.functions.try-avg.t006": "met", + "db.functions.try-cast.t001": "met", + "db.functions.try-cast.t002": "met", "db.functions.try-divide.t001": "met", "db.functions.try-divide.t002": "met", "db.functions.try-divide.t003": "met", @@ -10995,6 +11160,7 @@ "db.functions.vector-avg.t001": "unmet", "db.functions.vector-avg.t002": "unmet", "db.functions.vector-avg.t003": "unmet", + "db.functions.vector-avg.t004": "unmet", "db.functions.vector-cosine-similarity.t001": "met", "db.functions.vector-cosine-similarity.t002": "met", "db.functions.vector-cosine-similarity.t003": "met", @@ -11011,11 +11177,13 @@ "db.functions.vector-inner-product.t006": "met", "db.functions.vector-inner-product.t007": "met", "db.functions.vector-inner-product.t008": "met", - "db.functions.vector-l2-distance.t001": "unmet", - "db.functions.vector-l2-distance.t002": "unmet", + "db.functions.vector-l2-distance.t001": "met", + "db.functions.vector-l2-distance.t002": "met", "db.functions.vector-l2-distance.t003": "unmet", - "db.functions.vector-l2-distance.t004": "unmet", - "db.functions.vector-l2-distance.t005": "unmet", + "db.functions.vector-l2-distance.t004": "met", + "db.functions.vector-l2-distance.t005": "met", + "db.functions.vector-l2-distance.t006": "met", + "db.functions.vector-l2-distance.t007": "met", "db.functions.vector-norm.t001": "met", "db.functions.vector-norm.t002": "met", "db.functions.vector-norm.t003": "met", @@ -11025,9 +11193,12 @@ "db.functions.vector-normalize.t003": "unmet", "db.functions.vector-normalize.t004": "unmet", "db.functions.vector-normalize.t005": "unmet", + "db.functions.vector-normalize.t006": "unmet", "db.functions.vector-sum.t001": "unmet", "db.functions.vector-sum.t002": "unmet", "db.functions.vector-sum.t003": "unmet", + "db.functions.vector-sum.t004": "unmet", + "db.functions.vector-sum.t005": "unmet", "db.functions.weekday.t001": "met", "db.functions.weekday.t002": "met", "db.functions.weekday.t003": "met", @@ -11141,10 +11312,11 @@ "db.functions.xpath.t008": "unmet", "db.functions.xpath.t009": "unmet", "db.functions.xpath.t010": "unmet", - "db.functions.xxhash64.t001": "unmet", - "db.functions.xxhash64.t002": "unmet", - "db.functions.xxhash64.t003": "unmet", - "db.functions.xxhash64.t004": "unmet", + "db.functions.xxhash64.t001": "met", + "db.functions.xxhash64.t002": "met", + "db.functions.xxhash64.t003": "met", + "db.functions.xxhash64.t004": "met", + "db.functions.xxhash64.t005": "met", "db.functions.year.t001": "met", "db.functions.year.t002": "met", "db.functions.year.t003": "met", @@ -11164,11 +11336,14 @@ "db.functions.zstd-decompress.t001": "unmet", "db.functions.zstd-decompress.t002": "unmet", "db.functions.zstd-decompress.t003": "unmet", + "db.query.pipeline.table.syntax.t001": "met", + "db.query.pipeline.table.t001": "met", "db.query.query.t001": "met", "db.query.select-clusterby.t001": "met", "db.query.select-clusterby.t002": "met", "db.query.select-column-list.t001": "met", "db.query.select-column-list.t002": "met", + "db.query.select-column-list.t003": "met", "db.query.select-cte.t001": "met", "db.query.select-cte.t002": "met", "db.query.select-cte.t003": "met", @@ -11237,6 +11412,10 @@ "db.query.select-limit.t004": "met", "db.query.select-limit.t005": "met", "db.query.select-limit.t006": "met", + "db.query.select-match-recognize-define.t001": "unmet", + "db.query.select-match-recognize-measures.t001": "unmet", + "db.query.select-match-recognize-pattern.t001": "unmet", + "db.query.select-match-recognize.t001": "unmet", "db.query.select-named-window.t001": "met", "db.query.select-offset.t001": "met", "db.query.select-offset.t002": "met", @@ -11315,6 +11494,7 @@ "db.query.select-unpivot.t002": "met", "db.query.select-unpivot.t003": "met", "db.query.select-unpivot.t004": "met", + "db.query.select-values.select.t001": "met", "db.query.select-values.values.t001": "met", "db.query.select-values.values.t002": "met", "db.query.select-values.values.t003": "met", diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/catalog.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/catalog.rs index 5b15956ca..8aca6ce12 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/catalog.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/catalog.rs @@ -74,7 +74,7 @@ impl Catalog { .ok_or_else(|| { refused( "table", - format!("`{name}` is no table or view the case's statements define"), + format!("this script doesn't define the table or view `{name}`"), ) }) } @@ -87,7 +87,7 @@ impl Catalog { .ok_or_else(|| { refused( "table", - format!("`{name}` is no table or view the case's statements define"), + format!("this script doesn't define the table or view `{name}`"), ) }) } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/session.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/session.rs index 1df9115f0..cbe17d83d 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/session.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/session.rs @@ -106,7 +106,7 @@ fn drop_variable( return Err(refused( "utility_statement", format!( - "`{name}` is no variable the case declared, so Databricks raises an error DuckDB lacks" + "this script doesn't declare the variable `{name}`, so Databricks raises an error DuckDB lacks" ), )); } @@ -329,7 +329,7 @@ fn declared<'a>(column: &Value, catalog: &'a Catalog) -> Result<&'a Variable, Re catalog.variable(&name).ok_or_else(|| { refused( "set_statement", - format!("`{name}` is no variable the case declared"), + format!("this script doesn't declare the variable `{name}`"), ) }) } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/statements.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/statements.rs index 64c7d7a88..351934f0f 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/statements.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/effects/statements.rs @@ -56,7 +56,7 @@ pub(crate) fn effect_statement( kind => { return Err(refused( kind, - format!("no rule converts a {kind} statement in an effect case"), + format!("no rule converts a {kind} statement"), )); } }; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/dispatch.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/dispatch.rs index 95bd255e9..2fd29c02b 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/dispatch.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/dispatch.rs @@ -22,8 +22,8 @@ use crate::databricks::conversion::_helpers::support::scope::Site; use crate::databricks::conversion::_helpers::support::tree::{ field, identifier, node_kind, quoted, refused, understood, }; -use crate::databricks::conversion::constants::{COLUMN_RULE, INDEX_RULE}; -use crate::databricks::conversion::models::Emitted; +use crate::databricks::conversion::constants::{COLLATION_KIND, COLUMN_RULE, INDEX_RULE}; +use crate::databricks::conversion::models::{DatabricksType, Emitted}; /// `node` as DuckDB SQL with its Databricks type, or the refusal of the first unhandled part. pub(crate) fn expression(node: &Value, site: Site<'_>) -> Result { @@ -79,10 +79,46 @@ pub(crate) fn expression(node: &Value, site: Site<'_>) -> Result extract(payload, site), "window_function" => window(payload, site), "subscript" => subscript(payload, site), + COLLATION_KIND => collate(payload, site), _ => Err(refused(kind, format!("no rule converts {kind}"))), } } +/// `x COLLATE name` as a value, which Databricks types `STRING COLLATE name`, a type no rule claims; ORDER BY and comparisons read a collation themselves. +fn collate(payload: &Value, site: Site<'_>) -> Result { + let (name, _) = collation(payload, site)?; + Err(refused( + COLLATION_KIND, + format!( + "no rule types a value under the collation {name}, which Databricks types STRING COLLATE {name}" + ), + )) +} + +/// The upper-cased collation name of `x COLLATE name` and `x`, refused unless `x` is a STRING. +pub(crate) fn collation(payload: &Value, site: Site<'_>) -> Result<(String, Emitted), Refusal> { + let collation = understood( + payload, + COLLATION_KIND, + &["this", "collation", "quoted", "double_quoted"], + )?; + let name = field(collation, "collation") + .as_str() + .unwrap_or_default() + .to_ascii_uppercase(); + let text = expression(field(collation, "this"), site)?; + if text.data_type != DatabricksType::String { + return Err(refused( + COLLATION_KIND, + format!( + "no rule gives a {} a collation, which Databricks gives only strings", + text.data_type.name() + ), + )); + } + Ok((name, text)) +} + /// `value[index]` of an array or a map. fn subscript(payload: &Value, site: Site<'_>) -> Result { let subscript = understood(payload, "subscript", &["this", "index"])?; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/literals.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/literals.rs index 0d83c40b4..9042ff57e 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/literals.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/literals.rs @@ -18,10 +18,10 @@ use crate::databricks::conversion::_helpers::support::typing::{ databricks_type, rejected_cast, same_cast, }; use crate::databricks::conversion::constants::{ - CAST_RULE, CLOCK_TEXT_LENGTH, DATE_TEXT_LENGTH, DOUBLE_EXACT_DIGITS, DOUBLE_MANTISSA_BITS, - EPOCH_DATE, FLOAT_MANTISSA_BITS, FLOAT_MAX, FLOAT_OVERFLOW, FLOAT_RANGE_ERROR, LAMBDA_ELEMENT, - LITERAL_RULE, MAX_DECIMAL_PRECISION, MAX_FRACTION_DIGITS, MICROS_PER_SECOND, - SPECIAL_DOUBLE_TEXTS, TIME_LITERAL_SPELLING, + BIGINT_WHOLE_DIGITS, CAST_RULE, CLOCK_TEXT_LENGTH, DATE_TEXT_LENGTH, DOUBLE_EXACT_DIGITS, + DOUBLE_MANTISSA_BITS, EPOCH_DATE, FLOAT_MANTISSA_BITS, FLOAT_MAX, FLOAT_OVERFLOW, + FLOAT_RANGE_ERROR, HOURS_MINUTES_LENGTH, LAMBDA_ELEMENT, LITERAL_RULE, MAX_DECIMAL_PRECISION, + MAX_FRACTION_DIGITS, MICROS_PER_SECOND, SPECIAL_DOUBLE_TEXTS, TIME_LITERAL_SPELLING, }; use crate::databricks::conversion::models::{DatabricksType, Element, Emitted, Literal}; @@ -63,6 +63,12 @@ pub(crate) fn literal(payload: &Value, site: Site<'_>) -> Result { + Ok(typed( + format!("TIME {}", quoted_text(&format!("{value}:00"))), + DatabricksType::Time, + )) + } Some("time") => Err(refused_syntax( TIME_LITERAL_SPELLING, format!("no rule reads the time literal `{value}`"), @@ -142,7 +148,7 @@ pub(crate) fn try_cast(payload: &Value, site: Site<'_>) -> Result Option { if source.data_type.is_ansi_interval() { return interval_cast(source, target); @@ -169,6 +175,15 @@ pub(crate) fn cast_value(source: &Emitted, target: DatabricksType) -> Option) -> Result`, `<`, `<=`, `>`, `>=` or `<=>` on values both engines compare the same way. pub(crate) fn comparison(kind: &str, payload: &Value, site: Site<'_>) -> Result { - let (left, right) = operands(kind, payload, site)?; + let operator = understood(payload, kind, &["left", "right"])?; + let left = compared(field(operator, "left"), site)?; + let right = compared(field(operator, "right"), site)?; let _rule = site.log.rule(COMPARISON_RULE); let symbol = match kind { "eq" => "=", @@ -161,6 +165,21 @@ pub(crate) fn comparison(kind: &str, payload: &Value, site: Site<'_>) -> Result< )) } +/// One side of a comparison: `x COLLATE UTF8_BINARY` compares as `x`, byte by byte as every string without a collation does; another collation is refused. +fn compared(node: &Value, site: Site<'_>) -> Result { + let Some((COLLATION_KIND, payload)) = node_kind(node) else { + return expression(node, site); + }; + let (name, text) = collation(payload, site)?; + match name.as_str() { + BINARY_COLLATION => Ok(text), + _ => Err(refused( + COLLATION_KIND, + format!("no rule compares under the collation {name}"), + )), + } +} + /// `AND` or `OR` on booleans. pub(crate) fn logical(kind: &str, payload: &Value, site: Site<'_>) -> Result { let (left, right) = operands(kind, payload, site)?; @@ -182,6 +201,14 @@ pub(crate) fn logical(kind: &str, payload: &Value, site: Site<'_>) -> Result) -> Result { let not = understood(payload, "not", &["this"])?; + if let Some(test) = subquery_test(field(not, "this")) { + let test = understood(test, "in", &["this", "expressions", "not", "query"])?; + if flag(test, "not") { + return Err(refused("in", IN_SUBQUERY_NEGATED.to_owned())); + } + let operand = expression(field(test, "this"), site)?; + return in_subquery(operand, field(test, "query"), true, site); + } let operand = expression(field(not, "this"), site)?; let _rule = site.log.rule(BOOLEAN_RULE); Ok(typed( @@ -226,8 +253,11 @@ pub(crate) fn between(payload: &Value, site: Site<'_>) -> Result) -> Result { - let test = understood(payload, "in", &["this", "expressions", "not"])?; + let test = understood(payload, "in", &["this", "expressions", "not", "query"])?; let operand = expression(field(test, "this"), site)?; + if let Some(query) = test.get("query").filter(|query| !query.is_null()) { + return in_subquery(operand, query, flag(test, "not"), site); + } let mut values = vec![operand]; for item in list(test, "expressions") { values.push(expression(item, site)?); @@ -236,6 +266,59 @@ pub(crate) fn in_list(payload: &Value, site: Site<'_>) -> Result Option<&Value> { + match node_kind(node) { + Some(("paren", payload)) => payload.get("this").and_then(subquery_test), + Some(("in", payload)) if payload.get("query").is_some_and(|query| !query.is_null()) => { + Some(payload) + } + _ => None, + } +} + +/// `IN`, or with `negated` `NOT IN`, a subquery that reads nothing of the query around it, whose one column has the operand's type: the SQL test with a NULL answer read as FALSE, as Databricks answers both in a filter and in the select list. +fn in_subquery( + operand: Emitted, + query: &Value, + negated: bool, + site: Site<'_>, +) -> Result { + let query = match node_kind(query) { + Some(("subquery", payload)) => field(understood(payload, "subquery", &["this"])?, "this"), + _ => query, + }; + let (sql, columns) = subquery(query, site.log)?; + let [(_, column_type)] = columns.as_slice() else { + return Err(refused( + "in", + "no rule converts IN a subquery of other than one column".to_owned(), + )); + }; + if *column_type != operand.data_type || operand.data_type == DatabricksType::CalendarInterval { + return Err(refused( + "in", + format!( + "no rule converts a {} IN a subquery of a {} column", + operand.data_type.name(), + column_type.name() + ), + )); + } + let _rule = site.log.rule(IN_LIST_RULE); + Ok(typed( + format!( + "coalesce({}{} IN ({sql}), false)", + operand.sql, + match negated { + true => " NOT", + false => "", + } + ), + DatabricksType::Boolean, + )) +} + /// Whether the first of `values` is [not] among the rest, as `x IN (...)` and the function `in(x, ...)` test it. pub(crate) fn membership(values: &[Emitted], not: bool) -> Result { if common_type(values).is_none() { @@ -402,6 +485,65 @@ pub(crate) fn conditional(values: &[Emitted]) -> Option { )) } +/// `DECODE(x, key, result, ..., [default])` as a CASE on `x IS NOT DISTINCT FROM key`, a NULL key matching a NULL `x`: keys of `x`'s type, and STRING results, or integer literals without a default, which Databricks widens to BIGINT beside the STRING NULL it defaults to; NULL where no key matches and no default is given. +pub(crate) fn decoded(values: &[Emitted]) -> Option { + let (value, rest) = values.split_first()?; + if matches!(rest, [] | [_]) || value.data_type == DatabricksType::Null { + return None; + } + let (pairs, default) = match rest.len() % 2 { + 0 => (rest, None), + _ => rest + .split_last() + .map(|(default, pairs)| (pairs, Some(default)))?, + }; + let results: Vec<&Emitted> = pairs + .chunks(2) + .filter_map(|pair| pair.get(1)) + .chain(default) + .collect(); + let null = |result: &Emitted| result.data_type == DatabricksType::Null; + let integer_literal = |result: &Emitted| { + result.data_type.is_integral() && matches!(result.literal, Some(Literal::Number(_))) + }; + let target = if results.iter().all(|result| null(result)) { + return None; + } else if results + .iter() + .all(|result| null(result) || result.data_type == DatabricksType::String) + { + DatabricksType::String + } else if default.is_none() + && results + .iter() + .all(|result| null(result) || integer_literal(result)) + { + DatabricksType::BigInt + } else { + return None; + }; + let mut sql = "(CASE".to_owned(); + for pair in pairs.chunks(2) { + let [key, result] = pair else { + return None; + }; + if key.data_type != value.data_type && !null(key) { + return None; + } + sql.push_str(&format!( + " WHEN {} IS NOT DISTINCT FROM {} THEN {}", + value.sql, + key.sql, + as_type(result, target) + )); + } + if let Some(default) = default { + sql.push_str(&format!(" ELSE {}", as_type(default, target))); + } + sql.push_str(" END)"); + Some(typed(sql, target)) +} + /// The type a list of values compares or unifies as: one shared type, the widest integer, or DOUBLE for integers beside a DOUBLE. pub(crate) fn common_type(values: &[Emitted]) -> Option { use DatabricksType as T; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/patterns.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/patterns.rs index 16404561f..97f35b690 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/patterns.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/patterns.rs @@ -11,8 +11,8 @@ use crate::databricks::conversion::_helpers::support::tree::{ field, flag, list, node_kind, outside, refused, understood, }; use crate::databricks::conversion::constants::{ - ASCII_CHARACTERS, CASE_MAPPING_ERROR, ILIKE_KIND, ILIKE_RULE, LIKE_ESCAPE_ERROR, LIKE_ESCAPES, - LIKE_RULE, LOWERED_CHARACTERS, TRIM_RULE, + ASCII_CHARACTERS, CAPITAL_SIGMA, CASE_MAPPING_ERROR, ILIKE_KIND, ILIKE_RULE, LIKE_ESCAPE_ERROR, + LIKE_ESCAPES, LIKE_RULE, LOWER_CASE_EXCEPTIONS, LOWERED_CHARACTERS, TRIM_RULE, }; use crate::databricks::conversion::models::{DatabricksType, Emitted, Literal}; @@ -138,6 +138,36 @@ fn folded(text: &Emitted) -> String { case_mapped(text, "lower", LOWERED_CHARACTERS) } +/// `text` lowered as UTF8_LCASE lowers it, one code point at a time: capital I with dot above and final sigma as [`LOWER_CASE_EXCEPTIONS`] map them, raising for a character outside those whose lowering was seen to agree. +pub(crate) fn lower_cased(text: Emitted) -> Emitted { + let literal = match &text.literal { + Some(Literal::Text(value)) => Some(Literal::Text( + LOWER_CASE_EXCEPTIONS + .iter() + .fold(value.clone(), |value, (from, to)| value.replace(from, to)), + )), + _ => None, + }; + let replaced = Emitted { + sql: LOWER_CASE_EXCEPTIONS + .iter() + .fold(text.sql, |sql, (from, to)| { + format!("replace({sql}, '{from}', '{to}')") + }), + literal, + ..text + }; + Emitted { + sql: case_mapped( + &replaced, + "lower", + &format!("{LOWERED_CHARACTERS}{CAPITAL_SIGMA}"), + ), + literal: None, + ..replaced + } +} + /// `text` mapped by DuckDB's `function`, raising for a character outside `characters`, the class body it maps as Java does: a literal is checked here, and a column reaches the long class only past an ASCII check. pub(crate) fn case_mapped(text: &Emitted, function: &str, characters: &str) -> String { let t = &text.sql; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/windows.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/windows.rs index fa8adec1c..6fd384746 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/windows.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/expressions/windows.rs @@ -1,6 +1,7 @@ //! Window functions over an ordered window, with Databricks's null ordering and frames written out. use serde_json::Value; +use sqlbabel_diagnostics::failures::constants::ARGUMENT_REJECTED; use sqlbabel_diagnostics::refusals::models::Refusal; use crate::databricks::conversion::_helpers::expressions::dispatch::expression; @@ -13,10 +14,11 @@ use crate::databricks::conversion::_helpers::support::tree::{ refused_function, understood, }; use crate::databricks::conversion::constants::{ - AGGREGATES, CUME_DIST_NAME, CURRENT_ROW, FRACTION_WINDOWS, FRAME_KIND, INTEGER_WINDOWS, - MAX_WINDOW_COUNT, NTH_VALUE_NAME, NTILE_NAME, OFFSET_WINDOWS, QUERY_BLOCK_FIELD, RANGE_FRAME, - RANK_WINDOWS, ROWS_FRAME, SELECT_LIST_FIELD, WINDOW_CLAUSE_FIELD, WINDOW_NAME_FIELD, - WINDOW_RULE, + AGGREGATES, COLUMN_KIND, COUNTER_DIFF_NAME, COUNTER_TYPES, CUME_DIST_NAME, CURRENT_ROW, + FRACTION_WINDOWS, FRAME_KIND, FUNCTION_KIND, INTEGER_WINDOWS, LITERAL_KIND, MAX_WINDOW_COUNT, + NAMED_AGGREGATES, NEGATIVE_COUNTER_ERROR, NTH_VALUE_NAME, NTILE_NAME, OFFSET_WINDOWS, + PREVIOUS_ROWS, QUERY_BLOCK_FIELD, RANGE_FRAME, RANK_WINDOWS, ROWS_FRAME, SELECT_LIST_FIELD, + WINDOW_CLAUSE_FIELD, WINDOW_NAME_FIELD, WINDOW_RULE, }; use crate::databricks::conversion::models::{DatabricksType, Emitted, Literal}; @@ -73,7 +75,7 @@ pub(crate) fn window(payload: &Value, site: Site<'_>) -> Result) -> Result format!("OVER ({keys})"), }; let value = |node: &Value| expression(node, inner); + let integer_key = integer_key(window.over, inner)?; match (name, window.args) { (_, []) if INTEGER_WINDOWS.contains(&name) => Ok(typed( format!( @@ -149,6 +152,30 @@ pub(crate) fn window(payload: &Value, site: Site<'_>) -> Result { + let input = valued(value(input)?, name)?; + if !COUNTER_TYPES.contains(&input.data_type) { + return Err(refused_function( + name, + format!("no rule converts {name} of a {}", input.data_type.name()), + )); + } + let previous = format!( + "last_value({} IGNORE NULLS) {}", + input.sql, + over(Some(PREVIOUS_ROWS.to_owned())) + ); + Ok(Emitted { + sql: format!( + "CASE WHEN {value} < 0 THEN CAST(error('{ARGUMENT_REJECTED}: {NEGATIVE_COUNTER_ERROR}') AS {type_name}) \ + WHEN {value} >= {previous} THEN {value} - {previous} END", + value = input.sql, + type_name = input.data_type.duckdb_name() + ), + literal: None, + ..input + }) + } ("FIRST_VALUE" | "LAST_VALUE", [input, rest @ ..]) => { let input = valued(value(input)?, name)?; let ignore_nulls = match rest { @@ -174,7 +201,7 @@ pub(crate) fn window(payload: &Value, site: Site<'_>) -> Result return Err(arity(name, window.args)), }; - let frame = written_frame(frame, name)?; + let frame = written_frame(frame, name, integer_key)?; Ok(Emitted { sql: format!( "{}({}{}) {}", @@ -190,7 +217,7 @@ pub(crate) fn window(payload: &Value, site: Site<'_>) -> Result { let input = valued(value(input)?, name)?; let position = positive(&value(position)?, name)?; - let frame = written_frame(frame, name)?; + let frame = written_frame(frame, name, integer_key)?; Ok(Emitted { sql: format!( "nth_value({}, {position}{}) {}", @@ -230,7 +257,10 @@ fn aggregate_window( ), )); } - (false, frame) => format!(" OVER ({keys} {})", written_frame(frame, name)?), + (false, frame) => format!( + " OVER ({keys} {})", + written_frame(frame, name, integer_key(window.over, site)?)? + ), }; let aggregating = Site { aggregates: true, @@ -328,6 +358,35 @@ pub(crate) fn spelled(node: &Value, scope: &Scope) -> Result, Ref ))) } +/// The name Databricks gives an unaliased integer literal, its digits, or call of one of NAMED_AGGREGATES on a column, such as `sum(x2)`; `None` for anything else. +pub(crate) fn spelled_item(node: &Value, scope: &Scope) -> Result, Refusal> { + if node_kind(node).is_some_and(|(kind, _)| kind == LITERAL_KIND) { + return spelled_part(node, scope); + } + let Some(call) = node_kind(node) + .filter(|(kind, _)| *kind == FUNCTION_KIND) + .and_then(|(_, call)| call.as_object()) + else { + return Ok(None); + }; + let name = field(call, "name") + .as_str() + .unwrap_or_default() + .to_ascii_uppercase(); + let plain = field(call, "filter").is_null() + && matches!(field(call, "set_quantifier").as_str(), None | Some("none")); + match ( + NAMED_AGGREGATES.contains(&name.as_str()) && plain, + list(call, "args"), + ) { + (true, [column]) if node_kind(column).is_some_and(|(kind, _)| kind == COLUMN_KIND) => { + Ok(spelled_part(column, scope)? + .map(|column| format!("{}({column})", name.to_ascii_lowercase()))) + } + _ => Ok(None), + } +} + /// Whether `name` is a ranking function, which takes no frame and no IGNORE NULLS. fn ranking(name: &str) -> bool { INTEGER_WINDOWS.contains(&name) || FRACTION_WINDOWS.contains(&name) || name == NTILE_NAME @@ -623,8 +682,21 @@ fn ignoring(ignore_nulls: bool) -> &'static str { } } -/// The frame written out: Databricks's default over an ordered window, or a written ROWS or RANGE frame. -fn written_frame(frame: Option<&Value>, name: &str) -> Result { +/// Whether the window orders by a lone INT or BIGINT key, the only keys a RANGE frame's offsets are converted over: Databricks adds an offset in the key's own type, where DuckDB widens a TINYINT or SMALLINT key. +fn integer_key(over: &serde_json::Map, site: Site<'_>) -> Result { + let [ordered] = list(over, "order_by") else { + return Ok(false); + }; + let ordered = understood(ordered, "ordered", &["this", "desc", "nulls_first"])?; + let key = expression(field(ordered, "this"), site)?; + Ok(matches!( + key.data_type, + DatabricksType::Int | DatabricksType::BigInt + )) +} + +/// The frame written out: Databricks's default over an ordered window, or a written ROWS or RANGE frame, offsets in RANGE only over a lone integer key. +fn written_frame(frame: Option<&Value>, name: &str, integer_key: bool) -> Result { let Some(frame) = frame else { return Ok(format!( "{RANGE_FRAME} BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW" @@ -635,7 +707,7 @@ fn written_frame(frame: Option<&Value>, name: &str) -> Result { FRAME_KIND, format!( "no rule converts {name} over a frame other than ROWS with literal bounds or RANGE \ - without offsets, from no later than it ends" + without offsets or over one integer key, from no later than it ends" ), ) }; @@ -657,7 +729,7 @@ fn written_frame(frame: Option<&Value>, name: &str) -> Result { if start.place > end.place || start.place == i128::MAX || end.place == -i128::MAX - || (kind == RANGE_FRAME && (offset(&start) || offset(&end))) + || (kind == RANGE_FRAME && !integer_key && (offset(&start) || offset(&end))) { return Err(unsupported()); } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/arrays.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/arrays.rs index 46b887bbe..3296a5a45 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/arrays.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/arrays.rs @@ -2,6 +2,7 @@ use crate::databricks::conversion::_helpers::expressions::literals::typed; use crate::databricks::conversion::_helpers::expressions::operators::{as_type, common_type}; +use crate::databricks::conversion::_helpers::expressions::texts::beside_integer; use crate::databricks::conversion::_helpers::functions::rewrites::Rewrite; use crate::databricks::conversion::_helpers::support::typing::wider_integer; use crate::databricks::conversion::constants::{ @@ -177,10 +178,14 @@ pub(crate) fn array_length_rewrite(name: &str) -> Option { Some(rewrite) } -/// `SEQUENCE(start, stop[, step])` of INT or BIGINT bounds, BIGINT when any is: every value from `start` to `stop` inclusive, by 1 or -1 toward `stop` without a step; a step of 0 only when the bounds are equal; a step away from `stop`, or more elements than an array holds, rejected. +/// `SEQUENCE(start, stop[, step])` of INT or BIGINT bounds, BIGINT when any is, and without a step a STRING column bound beside an integer one read as BIGINT, as Databricks casts it: every value from `start` to `stop` inclusive, by 1 or -1 toward `stop` without a step; a step of 0 only when the bounds are equal; a step away from `stop`, or more elements than an array holds, rejected. fn sequence(values: &[Emitted]) -> Option { + let bounds; let (start, stop, step) = match values { - [start, stop] => (start, stop, None), + [start, stop] => { + bounds = beside_integer((start.clone(), stop.clone()), DatabricksType::BigInt); + (&bounds.0, &bounds.1, None) + } [start, stop, step] => (start, stop, Some(step)), _ => return None, }; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/calls.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/calls.rs index 471aba823..2b0869b4d 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/calls.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/calls.rs @@ -4,6 +4,7 @@ use serde_json::{Value, json}; use sqlbabel_blocks::floats::constants::FLOAT_SUM_ORDER; use sqlbabel_blocks::floats::main::exact_float_sum::exact_float_sum; use sqlbabel_blocks::raises::main::raised::raised; +use sqlbabel_diagnostics::failures::constants::ARGUMENT_REJECTED; use sqlbabel_diagnostics::refusals::models::Refusal; use crate::databricks::conversion::_helpers::expressions::dispatch::expression; @@ -11,7 +12,7 @@ use crate::databricks::conversion::_helpers::expressions::literals::{ cast_value, quoted_text, typed, }; use crate::databricks::conversion::_helpers::expressions::operators::{ - as_type, common_type, conditional, membership, + as_type, common_type, conditional, decoded, membership, }; use crate::databricks::conversion::_helpers::expressions::texts::{ as_number, narrowed_arguments, text_arguments, @@ -21,7 +22,8 @@ use crate::databricks::conversion::_helpers::functions::lambdas::higher_order; use crate::databricks::conversion::_helpers::functions::numbers::decimal_average; use crate::databricks::conversion::_helpers::functions::rewrites::small_integer; use crate::databricks::conversion::_helpers::functions::rewrites::{applied, rewrite}; -use crate::databricks::conversion::_helpers::functions::units::unit_call; +use crate::databricks::conversion::_helpers::functions::strings::search; +use crate::databricks::conversion::_helpers::functions::units::{bare_unit_rejection, unit_call}; use crate::databricks::conversion::_helpers::support::scope::Site; use crate::databricks::conversion::_helpers::support::tree::{ Payload, constant_text, field, flag, identifier_parts, list, node_kind, outside, @@ -29,16 +31,16 @@ use crate::databricks::conversion::_helpers::support::tree::{ }; use crate::databricks::conversion::_helpers::support::typing::rejected_cast; use crate::databricks::conversion::constants::{ - AGGREGATE_RULE, AGGREGATES, ARRAY_SORT_NAME, BITMAP_BITS, CASE_RULE, CAST_FUNCTIONS, CAST_RULE, - COALESCE_NAME, COLLECT_ORDER, COLLECT_ORDER_ERROR, CONCAT_RULE, COUNT_NAME, - DECODE_CHARSET_ARGUMENTS, DOUBLE_EXACT_DIGITS, DOUBLE_EXACT_INTEGERS, EXACT_FRACTION_STEPS, - FLOAT_ELEMENTS, IDENTIFIER_NAME, IN_LIST_RULE, INEXACT_SUM_ERROR, LAMBDA_ELEMENT, - LAMBDA_FUNCTIONS, MAX_DECIMAL_PRECISION, MEDIAN_ZERO_ERROR, MIN_IN_ARGUMENTS, - MIN_LIST_ARGUMENTS, MODE_TIES, MODE_TIES_ERROR, NANOS_TIMESTAMP_ERROR, ORDER_FREE_READERS, - ORDERED_PICKS, ORDERING_FUNCTIONS, PERCENTILE_NAME, PICK_COUNT_EMPTY_ERROR, PICK_ORDER, - PICK_ORDER_ERROR, PICK_TIES, PICK_TIES_ERROR, RANGE_NAME, SAME_FUNCTION_RULE, SAME_FUNCTIONS, - STRING_AGG_FUNCTION, UNIT_ARGUMENTS, UNIT_FUNCTIONS, UNWINDOWED_COUNTER_ERROR, - WHOLE_AGGREGATES, WITHIN_GROUP_KIND, + AGGREGATE_RULE, AGGREGATES, ARRAY_SORT_NAME, BITMAP_BITS, BITMAP_POSITION_ERROR, CASE_RULE, + CAST_FUNCTIONS, CAST_RULE, COALESCE_NAME, COLLECT_ORDER, COLLECT_ORDER_ERROR, CONCAT_RULE, + COUNT_NAME, COUNTER_DIFF_NAME, DECODE_CHARSET_ARGUMENTS, DOUBLE_EXACT_DIGITS, + DOUBLE_EXACT_INTEGERS, EXACT_FRACTION_STEPS, FLOAT_ELEMENTS, IDENTIFIER_NAME, IN_LIST_RULE, + INEXACT_SUM_ERROR, LAMBDA_ELEMENT, LAMBDA_FUNCTIONS, MAX_DECIMAL_PRECISION, MEDIAN_ZERO_ERROR, + MIN_IN_ARGUMENTS, MIN_LIST_ARGUMENTS, MODE_TIES, MODE_TIES_ERROR, NANOS_TIMESTAMP_ERROR, + ORDER_FREE_READERS, ORDERED_PICKS, ORDERING_FUNCTIONS, PERCENTILE_NAME, PICK_COUNT_EMPTY_ERROR, + PICK_ORDER, PICK_ORDER_ERROR, PICK_TIES, PICK_TIES_ERROR, RANGE_NAME, SAME_FUNCTION_RULE, + SAME_FUNCTIONS, STRING_AGG_FUNCTION, TIME_DIFF_NAME, UNIT_ARGUMENTS, UNIT_FUNCTIONS, + UNWINDOWED_COUNTER_ERROR, WHOLE_AGGREGATES, WITHIN_GROUP_KIND, }; use crate::databricks::conversion::models::{DatabricksType, Element, Emitted, Literal, Signature}; @@ -91,12 +93,26 @@ pub(crate) fn call(kind: &str, payload: &Value, site: Site<'_>) -> Result Err(refused_function( &name, format!("{name} is no aggregate DISTINCT applies to"), )), "CONCAT" => concat(args, site), + "SEARCH" => search(&name, args, false, site), + "ISEARCH" => search(&name, args, true, site), IDENTIFIER_NAME => match args { [text] => match constant_text(text).as_deref().and_then(identifier_parts).as_deref() { Some([name]) => expression(&json!({ "column": { "name": { "name": name, "quoted": true } } }), site), @@ -144,7 +160,8 @@ pub(crate) fn call(kind: &str, payload: &Value, site: Site<'_>) -> Result { + "GROUPING" | "GROUPING_ID" => grouping(&name, args, site), + COUNTER_DIFF_NAME => { arguments(args, site)?; Err(outside_function(&name, UNWINDOWED_COUNTER_ERROR.to_owned())) } @@ -187,10 +204,20 @@ pub(crate) fn call(kind: &str, payload: &Value, site: Site<'_>) -> Result picked_by(&name, args, site), "MODE" => mode(args, site), "TYPEOF" => type_of(&name, args, site), - "DECODE" if args.len() != DECODE_CHARSET_ARGUMENTS => Err(refused_function( - &name, - "no rule converts DECODE of a value and its search results".to_owned(), - )), + "DECODE" if args.len() != DECODE_CHARSET_ARGUMENTS => { + let values = arguments(args, site)?; + let _rule = site.log.rule(CASE_RULE); + decoded(&values).ok_or_else(|| { + let names: Vec = values.iter().map(|value| value.data_type.name()).collect(); + refused_function( + &name, + format!( + "no rule converts DECODE of ({}): only keys of the value's type and STRING or integer literal results convert", + names.join(", ") + ), + ) + }) + } _ if args.len() == UNIT_ARGUMENTS && UNIT_FUNCTIONS.contains(&name.as_str()) => { unit_call(&name, args, site) } @@ -209,6 +236,53 @@ pub(crate) fn call(kind: &str, payload: &Value, site: Site<'_>) -> Result) -> Result { + let Some(columns) = + (site.scope.grouping.as_ref()).filter(|columns| site.aggregates && !columns.is_empty()) + else { + return Err(refused_function( + name, + format!( + "no rule converts {name} outside the results of a block grouping by ROLLUP, CUBE or GROUPING SETS of columns" + ), + )); + }; + let keys = Site { + outputs: false, + ..site.without_aggregates() + }; + let named: Vec = arguments(args, keys)? + .into_iter() + .map(|argument| argument.sql) + .collect(); + let (read, data_type) = match (name, named.as_slice()) { + ("GROUPING", [column]) if columns.contains(column) => (&named, DatabricksType::TinyInt), + ("GROUPING_ID", []) => (columns, DatabricksType::BigInt), + ("GROUPING_ID", _) if named == *columns => (columns, DatabricksType::BigInt), + _ => { + return Err(outside_function( + name, + format!( + "Databricks rejects {name} of anything but {}", + match name { + "GROUPING" => "one of the grouping columns", + _ => "all the grouping columns in their order", + } + ), + )); + } + }; + Ok(typed( + format!( + "CAST(GROUPING({}) AS {})", + read.join(", "), + data_type.duckdb_name() + ), + data_type, + )) +} + /// An aggregate call: its name, arguments, set quantifier, and `OVER` clause when it is a window function. pub(crate) struct Aggregate<'a> { pub(crate) name: &'a str, @@ -496,6 +570,11 @@ pub(crate) fn aggregate(call: &Aggregate<'_>, site: Site<'_>) -> Result { Some(bitmap_aggregate(function, &value.sql)) } + ("BITMAP_CONSTRUCT_AGG", data_type) + if data_type.is_integral() && over.is_none() && !distinct => + { + Some(bitmap_construct(&value.sql)) + } _ => None, }; result.ok_or_else(|| { @@ -529,6 +608,21 @@ fn bitmap_aggregate(function: &str, x: &str) -> Emitted { ) } +/// `BITMAP_CONSTRUCT_AGG` as DuckDB's `bitstring_agg` of each position with its bit order within its byte reversed, since Databricks sets bit `p % 8` from the lowest; all zero bits when no position remains, raising for a position outside the bitmap. +fn bitmap_construct(x: &str) -> Emitted { + let last = BITMAP_BITS - 1; + let position = format!( + "CASE WHEN {x} < 0 OR {x} > {last} THEN {raise} ELSE {x} // 8 * 8 + 7 - {x} % 8 END", + raise = raised(&format!("{ARGUMENT_REJECTED}: {BITMAP_POSITION_ERROR}")) + ); + typed( + format!( + "CAST(coalesce(bitstring_agg({position}, 0, {last}), CAST(repeat('0', {BITMAP_BITS}) AS BIT)) AS BLOB)" + ), + DatabricksType::Binary, + ) +} + /// MEDIAN of DOUBLE values as Spark's percentile computes it: the middle value, or between two middle values `lo + 0.5 * (hi - lo)` in doubles unless they are the same value; NaN sorts last in both engines. Where a middle value is zero and the values hold zeros of both signs, which Spark orders as equal and DuckDB apart, it raises. fn double_median(x: &str) -> Emitted { let e = LAMBDA_ELEMENT; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/dates.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/dates.rs index e6fe45ce2..0969ed129 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/dates.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/dates.rs @@ -10,6 +10,7 @@ use crate::databricks::conversion::_helpers::expressions::operators::as_type; use crate::databricks::conversion::_helpers::expressions::patterns::case_mapped; use crate::databricks::conversion::_helpers::expressions::texts::read_text; use crate::databricks::conversion::_helpers::functions::rewrites::{Rewrite, small_integer}; +use crate::databricks::conversion::_helpers::functions::units::time_difference; use crate::databricks::conversion::_helpers::support::scope::Site; use crate::databricks::conversion::_helpers::support::tree::{ digits_value, field as member, flag, refused, understood, @@ -51,6 +52,7 @@ pub(crate) fn date_rewrite(name: &str) -> Option { "DATE_PART" => date_part, "TIME_BUCKET" => time_bucket, "DATEDIFF" | "DATE_DIFF" => date_diff, + "TIME_DIFF" => time_difference, "DATE_ADD" | "DATEADD" => |values| days_added(values, ""), "DATE_SUB" => |values| days_added(values, "- "), "ADD_MONTHS" => add_months, diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/digests.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/digests.rs new file mode 100644 index 000000000..6bcada615 --- /dev/null +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/digests.rs @@ -0,0 +1,367 @@ +//! Hashes of byte strings: HMAC, CRC32, and Spark's Murmur3 and xxHash64 of a value's bytes, each written out in DuckDB integer arithmetic. + +use sqlbabel_diagnostics::failures::constants::ARGUMENT_REJECTED; + +use crate::databricks::conversion::_helpers::expressions::literals::typed; +use crate::databricks::conversion::_helpers::functions::arrays::captured; +use crate::databricks::conversion::_helpers::functions::rewrites::Rewrite; +use crate::databricks::conversion::constants::{ + BIGINT_SIGN, CRC32_ALL_ONES, CRC32_POLYNOMIAL, HASH_SEED, HMAC_BLOCK, HMAC_EMPTY_KEY_ERROR, + HMAC_PADS, INT_SIGN, LAMBDA_ACCUMULATORS, LAMBDA_ELEMENT, LAMBDA_HASHED, LAMBDA_INDEX, + LAMBDA_TOTAL, MURMUR3_BLOCK, MURMUR3_FINISH, SIGN_EXTENSION, XXHASH64_PRIMES, +}; +use crate::databricks::conversion::models::{DatabricksType, Emitted}; + +/// The rewrite of the hash function `name`, `None` when none handles it. +pub(crate) fn digest_rewrite(name: &str) -> Option { + let rewrite: Rewrite = match name { + "HMAC" => hmac, + "CRC32" => crc32, + "HASH" => murmur3, + "XXHASH64" => xxhash64, + _ => return None, + }; + Some(rewrite) +} + +/// `HMAC(key, message)` of byte strings: HMAC-SHA256, its key padded to the block and XORed byte by byte, raising for an empty key. +fn hmac(values: &[Emitted]) -> Option { + let [key, message] = values else { return None }; + let binary = |value: &Emitted| value.data_type == DatabricksType::Binary; + if !binary(key) || !binary(message) || held(&key.sql) { + return None; + } + let (k, block, slot) = (&key.sql, HMAC_BLOCK, LAMBDA_INDEX); + let hex_width = 2 * u16::from(block); + let padded = format!( + "rpad(hex(CASE WHEN octet_length({k}) > {block} THEN unhex(sha256({k})) ELSE {k} END), {hex_width}, '0')" + ); + let pad = |byte: u8| { + format!( + "unhex(array_to_string(list_transform(range({block}), lambda {slot}: printf('%02X', \ + xor(CAST('0x' || substr({padded}, CAST(2 * {slot} + 1 AS INTEGER), 2) AS INTEGER), {byte}))), ''))" + ) + }; + let (inner, outer) = HMAC_PADS; + let inner = format!("sha256({} || {})", pad(inner), message.sql); + Some(typed( + format!( + "CASE WHEN octet_length({k}) = 0 THEN error('{ARGUMENT_REJECTED}: {HMAC_EMPTY_KEY_ERROR}') \ + ELSE unhex(sha256({} || unhex({inner}))) END", + pad(outer) + ), + DatabricksType::Binary, + )) +} + +/// `CRC32` of a byte string as BIGINT: the reflected polynomial applied bit by bit, from and to all ones. +fn crc32(values: &[Emitted]) -> Option { + let [value] = values else { return None }; + if value.data_type != DatabricksType::Binary || held(&value.sql) { + return None; + } + let (total, element, hashed, slot) = + (LAMBDA_TOTAL, LAMBDA_ELEMENT, LAMBDA_HASHED, LAMBDA_INDEX); + let bits = format!( + "list_reduce(range(8), lambda {hashed}, {slot}: xor({hashed} >> 1, ({hashed} & 1) * {CRC32_POLYNOMIAL}), \ + xor({total}, {element}))" + ); + Some(typed( + format!( + "CAST(xor(list_reduce({}, lambda {total}, {element}: {bits}, CAST({CRC32_ALL_ONES} AS UBIGINT)), {CRC32_ALL_ONES}) AS BIGINT)", + bytes(value)? + ), + DatabricksType::BigInt, + )) +} + +/// `HASH(...)` as INT: Spark's Murmur3_x86_32 of each argument's bytes, each hash the seed of the next and a NULL passing it on; Spark reads each byte past the last whole word as a signed word of its own. +fn murmur3(values: &[Emitted]) -> Option { + let (c1, c2, mix, f1, f2) = ( + MURMUR3_BLOCK.0, + MURMUR3_BLOCK.1, + MURMUR3_BLOCK.2, + MURMUR3_FINISH.0, + MURMUR3_FINISH.1, + ); + let (element, hashed, slot) = (LAMBDA_ELEMENT, LAMBDA_HASHED, LAMBDA_INDEX); + let step = |word: &str| { + let k = wrap32(&format!( + "{} * {c2}", + rotate32(&wrap32(&format!("({word}) * {c1}")), 15) + )); + wrap32(&format!( + "{} * 5 + {mix}", + rotate32(&format!("xor({hashed}, {k})"), 13) + )) + }; + let word = (0..4) + .map(|byte| format!("({element}[4 * {slot} + {}] << {})", byte + 1, 8 * byte)) + .collect::>() + .join(" | "); + let tail_byte = format!( + "(CASE WHEN {element}[{slot} + 1] >= 128 THEN {element}[{slot} + 1] + {SIGN_EXTENSION} ELSE {element}[{slot} + 1] END)" + ); + let blocks = format!( + "list_reduce(range(len({element}) // 4), lambda {hashed}, {slot}: {}, {LAMBDA_TOTAL})", + step(&word) + ); + let tail = format!( + "list_reduce(range(len({element}) // 4 * 4, len({element})), lambda {hashed}, {slot}: {}, {blocks})", + step(&tail_byte) + ); + let finished = format!( + "list_reduce([0, 1, 2], lambda {hashed}, {slot}: CASE {slot} \ + WHEN 0 THEN {} WHEN 1 THEN {} ELSE xor({hashed}, {hashed} >> 16) END, \ + xor({tail}, CAST(len({element}) AS UBIGINT)))", + wrap32(&format!("xor({hashed}, {hashed} >> 16) * {f1}")), + wrap32(&format!("xor({hashed}, {hashed} >> 13) * {f2}")), + ); + let folded = chained(values, &finished, &format!("CAST({HASH_SEED} AS UBIGINT)"))?; + Some(typed( + format!( + "CAST(CAST(xor({folded}, CAST({INT_SIGN} AS UBIGINT)) AS BIGINT) - {INT_SIGN} AS INTEGER)" + ), + DatabricksType::Int, + )) +} + +/// `XXHASH64(...)` as BIGINT: xxHash64 of each argument's bytes, each hash the seed of the next and a NULL passing it on. +fn xxhash64(values: &[Emitted]) -> Option { + let [p1, p2, p3, p4, p5] = XXHASH64_PRIMES; + let (total, element, hashed, slot, accumulators) = ( + LAMBDA_TOTAL, + LAMBDA_ELEMENT, + LAMBDA_HASHED, + LAMBDA_INDEX, + LAMBDA_ACCUMULATORS, + ); + let round = |accumulated: &str, input_word: &str| { + wrap64(&format!( + "{} * {p1}", + rotate64( + &wrap64(&format!( + "{} + {}", + wide(accumulated), + wrap64(&format!("{} * {p2}", wide(input_word))) + )), + 31 + ) + )) + }; + let input_word = |offset: &str| { + (0..8) + .map(|byte| { + format!( + "({} << {})", + wide(&format!("{element}[{offset} + {}]", byte + 1)), + 8 * byte + ) + }) + .collect::>() + .join(" | ") + }; + let word = |offset: &str| { + (0..4) + .map(|byte| { + format!( + "({} << {})", + wide(&format!("{element}[{offset} + {}]", byte + 1)), + 8 * byte + ) + }) + .collect::>() + .join(" | ") + }; + let seed = wide(total); + let start_accumulators = format!( + "[{}, {}, {seed}, {}]", + wrap64(&format!("{seed} + {p1} + {p2}")), + wrap64(&format!("{seed} + {p2}")), + wrap64(&format!("{seed} + {}", (1u128 << 64) - u128::from(p1))), + ); + let stripes = format!( + "list_reduce(range(len({element}) // 32), lambda {accumulators}, {slot}: list_transform(range(4), lambda {hashed}: {}), {start_accumulators})", + round( + &format!("{accumulators}[{hashed} + 1]"), + &input_word(&format!("32 * {slot} + 8 * {hashed}")) + ) + ); + let converged = wrap64( + &[1, 7, 12, 18] + .iter() + .enumerate() + .map(|(index, bits)| rotate64(&format!("{accumulators}[{}]", index + 1), *bits)) + .collect::>() + .join(" + "), + ); + let merged = format!( + "list_reduce({accumulators}, lambda {hashed}, {slot}: {}, {converged})", + wrap64(&format!( + "{} + {p4}", + wrap64(&format!("{} * {p1}", xor64(hashed, &round("0", slot)))) + )) + ); + let start = format!( + "CASE WHEN len({element}) >= 32 THEN list_transform([{stripes}], lambda {accumulators}: {merged})[1] ELSE {} END", + wrap64(&format!("{seed} + {p5}")) + ); + let start = wrap64(&format!( + "{} + {}", + wide(&start), + wide(&format!("len({element})")) + )); + let words = format!( + "list_reduce(range(len({element}) // 32 * 4, len({element}) // 8), lambda {hashed}, {slot}: {}, {start})", + wrap64(&format!( + "{} + {p4}", + wrap64(&format!( + "{} * {p1}", + rotate64( + &xor64(hashed, &round("0", &input_word(&format!("8 * {slot}")))), + 27 + ) + )) + )) + ); + let half = format!( + "list_reduce(range(len({element}) // 8 * 2, len({element}) // 4), lambda {hashed}, {slot}: {}, {words})", + wrap64(&format!( + "{} + {p3}", + wrap64(&format!( + "{} * {p2}", + rotate64( + &xor64( + hashed, + &wrap64(&format!("({}) * {p1}", word(&format!("4 * {slot}")))) + ), + 23 + ) + )) + )) + ); + let tail = format!( + "list_reduce(range(len({element}) // 4 * 4, len({element})), lambda {hashed}, {slot}: {}, {half})", + wrap64(&format!( + "{} * {p1}", + rotate64( + &xor64( + hashed, + &wrap64(&format!( + "{} * {p5}", + wide(&format!("{element}[{slot} + 1]")) + )) + ), + 11 + ) + )) + ); + let finished = format!( + "list_reduce([33, 29, 32], lambda {hashed}, {slot}: CASE {slot} WHEN 33 THEN {} WHEN 29 THEN {} ELSE {} END, {tail})", + wrap64(&format!( + "{} * {p2}", + xor64(hashed, &format!("{hashed} >> 33")) + )), + wrap64(&format!( + "{} * {p3}", + xor64(hashed, &format!("{hashed} >> 29")) + )), + xor64(hashed, &format!("{hashed} >> 32")), + ); + let folded = chained(values, &finished, &wide(&HASH_SEED.to_string()))?; + Some(typed( + format!( + "CAST(CAST(xor({folded}, {}) AS HUGEINT) - {BIGINT_SIGN} AS BIGINT)", + wide(&BIGINT_SIGN.to_string()) + ), + DatabricksType::BigInt, + )) +} + +/// `finished`, one argument's hash of `element` seeded with `total`, folded over every argument's bytes from `seed`. +fn chained(values: &[Emitted], finished: &str, seed: &str) -> Option { + if values.is_empty() { + return None; + } + let lists = values + .iter() + .map(bytes) + .collect::>>()? + .join(", "); + Some(format!( + "list_reduce([{lists}], lambda {LAMBDA_TOTAL}, {LAMBDA_ELEMENT}: CASE WHEN {LAMBDA_ELEMENT} IS NULL \ + THEN {LAMBDA_TOTAL} ELSE {finished} END, {seed})" + )) +} + +/// The bytes Spark hashes for `value` as a list of UBIGINT, NULL for NULL: an INT's four and a BIGINT's eight little-endian bytes, a string's UTF-8 bytes or a byte string's own. +fn bytes(value: &Emitted) -> Option { + if held(&value.sql) { + return None; + } + let (sql, slot) = (&value.sql, LAMBDA_INDEX); + let integer = |width: u8, wide_type: &str, mask: u128| { + format!( + "CASE WHEN {sql} IS NOT NULL THEN list_transform(range({width}), lambda {slot}: \ + CAST(((CAST({sql} AS {wide_type}) & {mask}) >> (8 * {slot})) & 255 AS UBIGINT)) END" + ) + }; + let hexed = |blob: String| { + format!( + "list_transform(regexp_extract_all(hex({blob}), '..'), lambda {slot}: CAST(CAST('0x' || {slot} AS INTEGER) AS UBIGINT))" + ) + }; + Some(match value.data_type { + DatabricksType::Int => integer(4, "BIGINT", u128::from(u32::MAX)), + DatabricksType::BigInt => integer(8, "HUGEINT", u128::from(u64::MAX)), + DatabricksType::String => hexed(format!("encode({sql})")), + DatabricksType::Binary => hexed(sql.clone()), + _ => return None, + }) +} + +/// Whether `sql` may name a parameter of the lambdas these hashes wrap it in. +fn held(sql: &str) -> bool { + let lowered = sql.to_lowercase(); + captured(sql) + || [LAMBDA_HASHED, LAMBDA_ACCUMULATORS] + .iter() + .any(|name| lowered.contains(name)) +} + +/// `sql` modulo 2^32. +fn wrap32(sql: &str) -> String { + format!("(({sql}) % 4294967296)") +} + +/// `sql`, below 2^32, rotated left by `bits` within 32 bits. +fn rotate32(sql: &str, bits: u8) -> String { + format!( + "((({sql}) << {bits}) % 4294967296 | (({sql}) >> {}))", + 32 - bits + ) +} + +/// `sql` as UHUGEINT, wide enough for the product of two 64-bit words. +fn wide(sql: &str) -> String { + format!("CAST({sql} AS UHUGEINT)") +} + +/// `sql` modulo 2^64. +fn wrap64(sql: &str) -> String { + format!("(({sql}) % 18446744073709551616)") +} + +/// `sql`, below 2^64, rotated left by `bits` within 64 bits. +fn rotate64(sql: &str, bits: u8) -> String { + let value = wide(sql); + format!( + "(({value} << {bits}) % 18446744073709551616 | ({value} >> {}))", + 64 - bits + ) +} + +/// The XOR of two values below 2^64, both as UHUGEINT. +fn xor64(left: &str, right: &str) -> String { + format!("xor({}, {})", wide(left), wide(right)) +} diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/formats.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/formats.rs index c98730520..aafda64d4 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/formats.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/formats.rs @@ -7,9 +7,10 @@ use crate::databricks::conversion::_helpers::expressions::literals::{ }; use crate::databricks::conversion::_helpers::functions::rewrites::Rewrite; use crate::databricks::conversion::constants::{ - DATE_PATTERN_LETTERS, DEFAULT_DECIMAL, JAVA_ASCII_WHITESPACE, LAMBDA_ELEMENT, - MAX_DECIMAL_PRECISION, NUMBER_FORMAT_MISMATCH_ERROR, NUMBER_FORMAT_OVERFLOW_ERROR, - UNFORMATTED_YEAR_ERROR, UNREAD_NUMBER_TEXT_ERROR, ZERO_FORMAT_ERROR, + DATE_PATTERN_LETTERS, DEFAULT_DECIMAL, FORMAT_NUMBER_PLACES_UNREAD, JAVA_ASCII_WHITESPACE, + JAVA_FRACTION_DIGITS, LAMBDA_ELEMENT, MAX_DECIMAL_PRECISION, NUMBER_FORMAT_MISMATCH_ERROR, + NUMBER_FORMAT_OVERFLOW_ERROR, TIME_EPOCH_DATE, TIME_PATTERN_LETTERS, UNFORMATTED_YEAR_ERROR, + UNREAD_NUMBER_TEXT_ERROR, ZERO_FORMAT_ERROR, }; use crate::databricks::conversion::models::{ DatabricksType, DigitRun, Emitted, Literal, NumberFormat, @@ -30,11 +31,56 @@ pub(crate) fn number_format_rewrite(name: &str) -> Option { let rewrite: Rewrite = match name { "TO_NUMBER" => |values| to_number(values, false), "TRY_TO_NUMBER" => |values| to_number(values, true), + "FORMAT_NUMBER" => format_number, _ => return None, }; Some(rewrite) } +/// `FORMAT_NUMBER(x, d)` of an integer or DECIMAL and an INT count of places: grouped by commas with `d` places rounded half to even, NULL for a negative `d`; an integer writes at most 340 places, as Java's DecimalFormat does for a `long`. A DOUBLE is left out: Databricks writes the digits of Java's `Double.toString`, which for some values, such as 1e23 as 9.999999999999999E22, are not the shortest digits DuckDB writes. +fn format_number(values: &[Emitted]) -> Option { + let [value, places] = values else { + return None; + }; + if places.data_type != DatabricksType::Int { + return None; + } + let (x, d) = (&value.sql, &places.sql); + let text = match value.data_type { + data_type if data_type.is_integral() => format!( + "format('{{:,}}', {x}) || CASE WHEN {d} > 0 THEN '.' || repeat('0', least({d}, {JAVA_FRACTION_DIGITS})) ELSE '' END" + ), + DatabricksType::Decimal { scale, .. } => { + let ten = |k: &str| format!("CAST('1' || repeat('0', {k}) AS HUGEINT)"); + let digits = format!("abs(CAST(replace(CAST({x} AS VARCHAR), '.', '') AS HUGEINT))"); + let cut = ten(&format!("greatest({scale} - {d}, 0)")); + let quotient = format!("({digits} // {cut})"); + let rest = format!("({digits} % {cut})"); + let rounded = format!( + "({quotient} + CASE WHEN 2 * {rest} > {cut} OR (2 * {rest} = {cut} AND {quotient} % 2 = 1) THEN 1 ELSE 0 END)" + ); + let kept = format!("least({d}, {scale})"); + let unit = ten(&kept); + let fraction = format!( + "CASE WHEN {kept} > 0 THEN '.' || lpad(CAST({rounded} % {unit} AS VARCHAR), {kept}, '0') ELSE '' END" + ); + let padding = match scale { + 0 => format!("CASE WHEN {d} > 0 THEN '.' || repeat('0', {d}) ELSE '' END"), + _ => format!("CASE WHEN {d} > {scale} THEN repeat('0', {d} - {scale}) ELSE '' END"), + }; + format!( + "CASE WHEN {d} > {JAVA_FRACTION_DIGITS} THEN CAST(error('{FORMAT_NUMBER_PLACES_UNREAD}') AS VARCHAR) \ + ELSE (CASE WHEN {x} < 0 THEN '-' ELSE '' END) || format('{{:,}}', {rounded} // {unit}) || {fraction} || {padding} END" + ) + } + _ => return None, + }; + Some(typed( + format!("(CASE WHEN {x} IS NULL OR {d} IS NULL OR {d} < 0 THEN NULL ELSE {text} END)"), + DatabricksType::String, + )) +} + /// `TO_CHAR(x, format)`: a date or timestamp by its pattern, an integer or decimal by its number format, NULL for a NULL format. fn to_char(values: &[Emitted]) -> Option { let [value, format] = values else { @@ -262,7 +308,7 @@ fn number_read(text: &Emitted, format: &NumberFormat, try_: bool) -> Option Option { let [value, pattern] = values else { return None; @@ -270,14 +316,19 @@ fn date_format(values: &[Emitted], text: bool) -> Option { let Some(Literal::Text(pattern)) = &pattern.literal else { return None; }; + let time = value.data_type == DatabricksType::Time; let value = match value.data_type { DatabricksType::Date | DatabricksType::Timestamp | DatabricksType::TimestampNtz => { value.clone() } DatabricksType::String if text => cast_value(value, DatabricksType::Timestamp)?, + DatabricksType::Time if text => typed( + format!("({TIME_EPOCH_DATE} + {})", value.sql), + DatabricksType::TimestampNtz, + ), _ => return None, }; - let format = strftime_format(pattern)?; + let format = strftime_format(pattern, time)?; Some(typed( format!( "(CASE WHEN {x} IS NULL THEN NULL WHEN year({x}) BETWEEN 1 AND 9999 THEN strftime({x}, {}) \ @@ -290,8 +341,8 @@ fn date_format(values: &[Emitted], text: bool) -> Option { )) } -/// The Java pattern `pattern` as a `strftime` format, `None` for a letter, count or symbol outside those it writes alike. -fn strftime_format(pattern: &str) -> Option { +/// The Java pattern `pattern` as a `strftime` format, `None` for a letter, count or symbol outside those it writes alike, or with `time` for a letter outside the time of day. +fn strftime_format(pattern: &str, time: bool) -> Option { let characters: Vec = pattern.chars().collect(); let mut format = String::new(); let mut at = 0; @@ -333,6 +384,9 @@ fn strftime_format(pattern: &str) -> Option { let (_, written) = DATE_PATTERN_LETTERS .iter() .find(|(java, _)| *java == letters)?; + if time && !TIME_PATTERN_LETTERS.contains(&letters.as_str()) { + return None; + } format.push_str(written); continue; } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/mod.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/mod.rs index d4e40fdad..1da21a057 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/mod.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/mod.rs @@ -1,6 +1,7 @@ pub(crate) mod arrays; pub(crate) mod calls; pub(crate) mod dates; +pub(crate) mod digests; pub(crate) mod encodings; pub(crate) mod formats; pub(crate) mod indexes; diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/rewrites.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/rewrites.rs index d9da3ff92..da95a305f 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/rewrites.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/rewrites.rs @@ -13,6 +13,7 @@ use crate::databricks::conversion::_helpers::functions::arrays::{ array_length_rewrite, array_rewrite, }; use crate::databricks::conversion::_helpers::functions::dates::{date_plus_days, date_rewrite}; +use crate::databricks::conversion::_helpers::functions::digests::digest_rewrite; use crate::databricks::conversion::_helpers::functions::encodings::encoding_rewrite; use crate::databricks::conversion::_helpers::functions::formats::{ format_rewrite, number_format_rewrite, @@ -52,7 +53,7 @@ type Family = fn(&str) -> Option; /// The rule and rewrite of the function `name`, `None` when no rewrite handles it. pub(crate) fn rewrite(name: &str) -> Option<(&'static str, Rewrite)> { - let families: [(&str, Family); 20] = [ + let families: [(&str, Family); 21] = [ (REWRITE_RULE, own_rewrite), (REWRITE_RULE, array_rewrite), (DATE_FUNCTION_RULE, date_rewrite), @@ -62,6 +63,7 @@ pub(crate) fn rewrite(name: &str) -> Option<(&'static str, Rewrite)> { (REGEX_RULE, regex_rewrite), (STRING_FUNCTION_RULE, string_rewrite), (STRING_FUNCTION_RULE, encoding_rewrite), + (STRING_FUNCTION_RULE, digest_rewrite), (STRING_FUNCTION_RULE, json_rewrite), (STRING_FUNCTION_RULE, url_rewrite), (NUMBER_FUNCTION_RULE, number_rewrite), diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/strings.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/strings.rs index 41ade50cb..4cd50df65 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/strings.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/strings.rs @@ -1,23 +1,119 @@ //! String functions, with Databricks's handling of empty, NULL and out-of-range arguments written out. +use serde_json::Value; +use sqlbabel_diagnostics::refusals::models::Refusal; + +use crate::databricks::conversion::_helpers::expressions::dispatch::expression; use crate::databricks::conversion::_helpers::expressions::literals::{ cast_value, quoted_text, typed, }; -use crate::databricks::conversion::_helpers::expressions::patterns::case_mapped; +use crate::databricks::conversion::_helpers::expressions::patterns::{case_mapped, lower_cased}; use crate::databricks::conversion::_helpers::functions::arrays::captured; use crate::databricks::conversion::_helpers::functions::rewrites::{ Rewrite, int_count, small_integer, }; +use crate::databricks::conversion::_helpers::support::scope::Site; +use crate::databricks::conversion::_helpers::support::tree::{ + constant_text, field, identifier, node_kind, refused_function, understood, +}; use crate::databricks::conversion::constants::{ - ALPHABET_ERROR, ASCII_ALPHABET, ASCII_LOWER, ASCII_UPPER, CASE_MAPPING_ERROR, - CHARACTER_KIND_ERROR, CHR_MODULUS, DEFAULT_COLLATION, DEFAULT_MASKS, DEFAULT_PAD, - FORMAT_SPECIFIER_ERROR, HIGH_SURROGATE, JARO_BOOST_ERROR, JARO_PARAMETERS, JARO_UNIT, - JARO_WINKLER_PREFIX, KINDED_CHARACTERS, LAMBDA_ELEMENT, LAMBDA_INDEX, LOW_SURROGATE, - LOWERED_CHARACTERS, MASKED_KINDS, SOUNDEX_CODES, SUBSTRING_INDEX_COUNT_ERROR, SUBSTRING_LENGTH, - UNTITLED_CHARACTERS, UPPERED_CHARACTERS, UTF16_SUPPLEMENTARY, + ALPHABET_ERROR, ASCII_ALPHABET, ASCII_LOWER, ASCII_UPPER, CAPITAL_DOTTED_I, CASE_MAPPING_ERROR, + CHARACTER_KIND_ERROR, CHR_MODULUS, COMBINING_DOT, DEFAULT_COLLATION, DEFAULT_MASKS, + DEFAULT_PAD, DOTTED_SPLIT_ERROR, FORMAT_SPECIFIER_ERROR, HIGH_SURROGATE, JARO_BOOST_ERROR, + JARO_PARAMETERS, JARO_UNIT, JARO_WINKLER_PREFIX, KINDED_CHARACTERS, LAMBDA_ELEMENT, + LAMBDA_INDEX, LATIN_LOWER_I, LOW_SURROGATE, LOWERED_CHARACTERS, MASKED_KINDS, + NAMED_ARGUMENT_KIND, REWRITE_RULE, SEARCH_MODE_NAME, SOUNDEX_CODES, + SUBSTRING_INDEX_COUNT_ERROR, SUBSTRING_LENGTH, SUBSTRING_MODE, UNTITLED_CHARACTERS, + UPPERED_CHARACTERS, UTF16_SUPPLEMENTARY, }; use crate::databricks::conversion::models::{DatabricksType, Emitted, Literal}; +/// `SEARCH(x, ..., pattern)` or, with `folds`, `ISEARCH` in substring mode: whether a STRING argument holds the constant pattern, lowered on both sides as UTF8_LCASE lowers them with `folds`, as an `OR` that is NULL when none does and one is NULL; other scalar arguments are skipped. +pub(crate) fn search( + name: &str, + args: &[Value], + folds: bool, + site: Site<'_>, +) -> Result { + let refusal = + |reason: &str| refused_function(name, format!("no rule converts {name} {reason}")); + let args = match args.split_last() { + Some((last, rest)) => match node_kind(last) { + Some((NAMED_ARGUMENT_KIND, named)) => { + let named = + understood(named, NAMED_ARGUMENT_KIND, &["name", "value", "separator"])?; + let substring = constant_text(field(named, "value")) + .is_some_and(|mode| mode.eq_ignore_ascii_case(SUBSTRING_MODE)); + if !identifier(field(named, "name"))?.eq_ignore_ascii_case(SEARCH_MODE_NAME) + || !substring + { + return Err(refusal("in a mode other than substring")); + } + rest + } + _ => args, + }, + None => args, + }; + let Some((pattern, targets)) = args.split_last().filter(|(_, targets)| !targets.is_empty()) + else { + return Err(refusal("without a pattern and an expression to search")); + }; + let pattern = expression(pattern, site)?; + let _rule = site.log.rule(REWRITE_RULE); + let pattern = match (&pattern.literal, pattern.data_type) { + (_, DatabricksType::Null) => { + return Ok(typed( + "CAST(NULL AS BOOLEAN)".to_owned(), + DatabricksType::Boolean, + )); + } + (Some(Literal::Text(text)), DatabricksType::String) if !text.is_empty() => pattern, + _ => { + return Err(refusal( + "of a pattern other than a non-empty constant string", + )); + } + }; + let fold = |text: Emitted| match folds { + true => lower_cased(text), + false => text, + }; + let lowered = match &pattern.literal { + Some(Literal::Text(text)) => text.to_lowercase(), + _ => String::new(), + }; + let splits_dotted = + folds && (lowered.starts_with(COMBINING_DOT) || lowered.ends_with(LATIN_LOWER_I)); + let pattern = fold(pattern); + let mut tests: Vec = Vec::new(); + for target in targets { + let target = expression(target, site)?; + match target.data_type { + DatabricksType::String | DatabricksType::Null => { + let raw = target.sql.clone(); + let test = format!("contains({}, {})", fold(target).sql, pattern.sql); + tests.push(match splits_dotted { + true => format!( + "(CASE WHEN contains({raw}, '{CAPITAL_DOTTED_I}') \ + THEN CAST(error('{DOTTED_SPLIT_ERROR}') AS BOOLEAN) ELSE {test} END)" + ), + false => test, + }); + } + DatabricksType::Array(_) | DatabricksType::Map(..) => { + return Err(refusal("of an array or map, whose strings it searches")); + } + _ => {} + } + } + let sql = match tests.is_empty() { + true => "FALSE".to_owned(), + false => format!("({})", tests.join(" OR ")), + }; + Ok(typed(sql, DatabricksType::Boolean)) +} + /// The rewrite of the string function `name`, `None` when none handles it; lengths count code points in both engines. pub(crate) fn string_rewrite(name: &str) -> Option { let rewrite: Rewrite = match name { diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/units.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/units.rs index f3d99f9db..cfc3937e7 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/units.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/units.rs @@ -9,14 +9,14 @@ use crate::databricks::conversion::_helpers::expressions::operators::as_type; use crate::databricks::conversion::_helpers::functions::rewrites::small_integer; use crate::databricks::conversion::_helpers::support::scope::Site; use crate::databricks::conversion::_helpers::support::tree::{ - node_kind, outside_function, refused_function, + field, identifier, node_kind, outside_function, refused_function, }; use crate::databricks::conversion::_helpers::support::typing::recorded_rejection; use crate::databricks::conversion::constants::{ - DATE_FUNCTION_RULE, MONTH_UNITS, TIME_UNITS, UNIT_ADD_NAMES, UNIT_DAY_ALIAS, UNIT_RANGE_ERROR, - UNIT_SPAN_MICROS, UNIT_SPAN_MONTHS, UNIT_YEARS, + DATE_FUNCTION_RULE, MONTH_UNITS, TIME_DIFF_UNIT_MICROS, TIME_UNITS, UNIT_ADD_NAMES, + UNIT_DAY_ALIAS, UNIT_RANGE_ERROR, UNIT_SPAN_MICROS, UNIT_SPAN_MONTHS, UNIT_YEARS, }; -use crate::databricks::conversion::models::{DatabricksType, Emitted}; +use crate::databricks::conversion::models::{DatabricksType, Emitted, Literal}; /// `name(unit, a, b)` for a datetime unit keyword, or the refusal of another unit or argument types. pub(crate) fn unit_call(name: &str, args: &[Value], site: Site<'_>) -> Result { @@ -46,6 +46,29 @@ pub(crate) fn unit_call(name: &str, args: &[Value], site: Site<'_>) -> Result Result, Refusal> { + let word = match args + .first() + .and_then(|first| node_kind(first).map(|kind| (first, kind))) + { + Some((first, ("var", _))) => unit_word(first), + Some((_, ("column", Value::Object(column)))) if field(column, "table").is_null() => { + Some(identifier(field(column, "name"))?.to_ascii_uppercase()) + } + _ => None, + }; + let Some(word) = word else { + return Ok(None); + }; + Ok((unit_micros(&word).is_some() || unit_months(&word).is_some()).then(|| { + outside_function( + name, + format!("Databricks reads the unit {word} written as a name in {name} as a column, and rejects it unresolved"), + ) + })) +} + /// The unit keyword a unit argument names, as the parser reads it. fn unit_word(node: &Value) -> Option { let (kind, payload) = node_kind(node)?; @@ -139,6 +162,27 @@ fn added(unit: &str, values: &[Emitted]) -> Option { }) } +/// `TIME_DIFF(unit, a, b)` of TIMEs for a literal unit of at most an hour, matched ignoring case: whole units of `b - a` toward zero. +pub(crate) fn time_difference(values: &[Emitted]) -> Option { + let [unit, start, end] = values else { + return None; + }; + let Some(Literal::Text(unit)) = &unit.literal else { + return None; + }; + let micros = unit_micros(&unit.to_ascii_uppercase()) + .filter(|micros| *micros <= TIME_DIFF_UNIT_MICROS)?; + let time = |value: &Emitted| value.data_type == DatabricksType::Time; + if !time(start) || !time(end) { + return None; + } + let whole = format!("(epoch_us({}) - epoch_us({}))", end.sql, start.sql); + Some(typed( + format!("CAST({} AS BIGINT)", toward_zero(&whole, micros)), + DatabricksType::BigInt, + )) +} + /// `whole` over `size` toward zero, as Java's long division truncates. fn toward_zero(whole: &str, size: i64) -> String { format!("(sign({whole}) * (abs({whole}) // {size}))") diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/vectors.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/vectors.rs index eca3f0f7d..5a5388013 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/vectors.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/functions/vectors.rs @@ -16,6 +16,7 @@ pub(crate) fn vector_rewrite(name: &str) -> Option { "VECTOR_INNER_PRODUCT" => inner_product, "VECTOR_COSINE_SIMILARITY" => cosine_similarity, "VECTOR_NORM" => norm, + "VECTOR_L2_DISTANCE" => l2_distance, _ => return None, }; Some(rewrite) @@ -55,6 +56,13 @@ fn norm(values: &[Emitted]) -> Option { )) } +/// `VECTOR_L2_DISTANCE(a, b)`: the square root of the DOUBLE sum of squared DOUBLE differences as Java narrows it to FLOAT, NULL for a NULL vector or element, raising for unequal dimensions. +fn l2_distance(values: &[Emitted]) -> Option { + let [a, b] = vectors(values)?; + let distance = narrowed(format!("sqrt({})", squared_distance(a, b)?))?; + Some(typed(checked(a, b, &distance.sql), DatabricksType::Float)) +} + /// The DOUBLE `sql`, evaluated once, narrowed to FLOAT as Java's cast narrows it, infinite past FLOAT's range. fn narrowed(sql: String) -> Option { let value = cast_value( @@ -99,22 +107,44 @@ fn checked(a: &Emitted, b: &Emitted, result: &str) -> String { ) } -/// The inner product of two FLOAT vectors in DOUBLE, summed as Databricks sums it: each block of [`VECTOR_BLOCK`] products left to right, then the blocks and the remaining products in turn from 0.0; `None` when a vector's SQL may name a lambda parameter. +/// The inner product of two FLOAT vectors in DOUBLE, summed as [`blocked_sum`] sums it; `None` when a vector's SQL may name a lambda parameter. fn dot(a: &Emitted, b: &Emitted) -> Option { if captured(&a.sql) || captured(&b.sql) { return None; } - let terms: Vec = (1..=VECTOR_BLOCK) + Some(blocked_sum(&format!( + "list_transform(CAST({a} AS DOUBLE[]), lambda {LAMBDA_ELEMENT}, {LAMBDA_INDEX}: \ + {LAMBDA_ELEMENT} * (CAST({b} AS DOUBLE[]))[{LAMBDA_INDEX}])", + a = a.sql, + b = b.sql + ))) +} + +/// The sum of squared DOUBLE differences of two FLOAT vectors, summed as [`blocked_sum`] sums it; `None` when a vector's SQL may name a lambda parameter. +fn squared_distance(a: &Emitted, b: &Emitted) -> Option { + if captured(&a.sql) || captured(&b.sql) { + return None; + } + let difference = format!( + "({LAMBDA_ELEMENT} - (CAST({b} AS DOUBLE[]))[{LAMBDA_INDEX}])", + b = b.sql + ); + Some(blocked_sum(&format!( + "list_transform(CAST({a} AS DOUBLE[]), lambda {LAMBDA_ELEMENT}, {LAMBDA_INDEX}: {difference} * {difference})", + a = a.sql + ))) +} + +/// The DOUBLE list `terms` summed as Databricks sums it: each block of [`VECTOR_BLOCK`] terms left to right, then the blocks and the remaining terms in turn from 0.0. +fn blocked_sum(terms: &str) -> String { + let block: Vec = (1..=VECTOR_BLOCK) .map(|k| format!("{LAMBDA_ELEMENT}[{VECTOR_BLOCK} * {LAMBDA_INDEX} + {k}]")) .collect(); - Some(format!( - "list_transform([list_transform(CAST({a} AS DOUBLE[]), lambda {LAMBDA_ELEMENT}, {LAMBDA_INDEX}: \ - {LAMBDA_ELEMENT} * (CAST({b} AS DOUBLE[]))[{LAMBDA_INDEX}])], lambda {LAMBDA_ELEMENT}: \ + format!( + "list_transform([{terms}], lambda {LAMBDA_ELEMENT}: \ list_reduce(list_concat(list_transform(range(0, len({LAMBDA_ELEMENT}) // {VECTOR_BLOCK}), \ lambda {LAMBDA_INDEX}: {}), {LAMBDA_ELEMENT}[len({LAMBDA_ELEMENT}) // {VECTOR_BLOCK} * {VECTOR_BLOCK} + 1:]), \ lambda {LAMBDA_TOTAL}, {LAMBDA_INDEX}: {LAMBDA_TOTAL} + {LAMBDA_INDEX}, 0.0))[1]", - terms.join(" + "), - a = a.sql, - b = b.sql - )) + block.join(" + "), + ) } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/grouping.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/grouping.rs index f0120048c..6958c8e68 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/grouping.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/grouping.rs @@ -6,16 +6,16 @@ use sqlbabel_diagnostics::refusals::models::Refusal; use crate::databricks::conversion::_helpers::expressions::dispatch::expression; use crate::databricks::conversion::_helpers::support::scope::Site; use crate::databricks::conversion::_helpers::support::tree::{ - flag, list, node_kind, outside, refused, understood, + digits_value, flag, list, node_kind, outside, refused, understood, }; use crate::databricks::conversion::constants::{ AGGREGATE_CALL_KIND, AGGREGATES, CALENDAR_EQUALITY, COLUMN_KIND, FLOAT_ELEMENTS, FUNCTION_KIND, GROUPING_SET_FUNCTIONS, GROUPING_SETS, HIVE_GROUPING_SETS_KIND, MAX_CUBE_COLUMNS, ORDERED_PICKS, OWN_AGGREGATES, TUPLE_KIND, UNGROUPED_SKIPS, WITHIN_GROUP_KIND, }; -use crate::databricks::conversion::models::{DatabricksType, Emitted}; +use crate::databricks::conversion::models::{DatabricksType, Emitted, Literal}; -/// The `GROUP BY` clause, or none for `GROUP BY ALL` over aggregates only, a global aggregate; `outputs` are the block's results, each with whether its expression holds an aggregate. +/// The `GROUP BY` clause, or none for `GROUP BY ALL` over aggregates only, a global aggregate; `outputs` are the block's results, each with whether its expression holds an aggregate; an integer key names one by position. pub(crate) fn group_by( group_by: &Value, outputs: &[(&Emitted, bool)], @@ -36,13 +36,53 @@ pub(crate) fn group_by( Some(sets) => vec![listed_sets(&sets)], None => list(group, "expressions") .iter() - .map(|item| grouping(item, site)) + .map(|item| match grouping_sets(item, site)? { + None => positioned_key(expression(item, site)?, outputs), + Some(sets) => Ok(listed_sets(&sets)), + }) .collect::>()?, }, }; Ok((!keys.is_empty()).then(|| format!(" GROUP BY {}", keys.join(", ")))) } +/// The SQL of the grouping columns GROUPING and GROUPING_ID read, in Databricks's order: Hive's listed keys, else each key in the order the items first name it. `None` unless the clause has ROLLUP, CUBE or GROUPING SETS. +pub(crate) fn grouping_columns( + group_by: &Value, + site: Site<'_>, +) -> Result>, Refusal> { + let group = understood( + group_by, + "group_by", + &["expressions", "all", "with_modifier"], + )?; + let items = list(group, "expressions"); + let item_sets = items + .iter() + .map(|item| grouping_sets(item, site)) + .collect::, _>>()?; + if flag(group, "all") || item_sets.iter().all(Option::is_none) { + return Ok(None); + } + let hive = items + .iter() + .any(|item| node_kind(item).is_some_and(|(kind, _)| kind == HIVE_GROUPING_SETS_KIND)); + let mut columns: Vec = Vec::new(); + for (item, sets) in items.iter().zip(item_sets) { + let keys = match sets { + Some(_) if hive => continue, + Some(sets) => sets.concat(), + None => vec![key(expression(item, site)?)?], + }; + for key in keys { + if !columns.contains(&key) { + columns.push(key); + } + } + } + Ok(Some(columns)) +} + /// The sets of Hive's `GROUP BY keys GROUPING SETS (...)`, `None` without one; each key must be in a set, as Databricks returns an always-NULL column otherwise. fn hive(items: &[Value], site: Site<'_>) -> Result>>, Refusal> { let Some(sets) = items @@ -145,12 +185,32 @@ pub(crate) fn not_positional(emitted: Emitted, kind: &str) -> Result) -> Result { - match grouping_sets(item, site)? { - None => key(expression(item, site)?), - Some(sets) => Ok(listed_sets(&sets)), +/// A plain `GROUP BY` key: an integer literal names the output at that position, counted from 1, as Databricks reads it; any other key groups by itself. +fn positioned_key(item: Emitted, outputs: &[(&Emitted, bool)]) -> Result { + let (Some(Literal::Number(text)), DatabricksType::Int) = (&item.literal, item.data_type) else { + return key(item); + }; + let Some((output, aggregated)) = digits_value(text) + .filter(|position| (1..=outputs.len() as u64).contains(position)) + .map(|position| outputs[position as usize - 1]) + else { + return Err(outside( + "group_by", + format!( + "position {text} is outside the {} columns the query returns, which Databricks rejects", + outputs.len() + ), + )); + }; + if aggregated { + return Err(outside( + "group_by", + format!( + "position {text} names an aggregate, which Databricks rejects as a grouping key" + ), + )); } + key(output.clone()) } /// `GROUPING SETS ((...), ...)` of `sets`. diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/query.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/query.rs index 929f1485c..10e29301e 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/query.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/queries/query.rs @@ -4,15 +4,18 @@ use serde_json::Value; use sqlbabel_diagnostics::provenance::models::ProvenanceLog; use sqlbabel_diagnostics::refusals::models::Refusal; -use crate::databricks::conversion::_helpers::expressions::dispatch::expression; +use crate::databricks::conversion::_helpers::expressions::dispatch::{collation, expression}; use crate::databricks::conversion::_helpers::expressions::operators::{as_type, common_type}; -use crate::databricks::conversion::_helpers::expressions::windows::{inlined_windows, spelled}; +use crate::databricks::conversion::_helpers::expressions::patterns::lower_cased; +use crate::databricks::conversion::_helpers::expressions::windows::{ + inlined_windows, spelled, spelled_item, +}; use crate::databricks::conversion::_helpers::functions::intervals::interval_text; use crate::databricks::conversion::_helpers::queries::generators::{ SelectGenerator, generated, select_generator, selected, }; use crate::databricks::conversion::_helpers::queries::grouping::{ - aggregates, group_by, not_positional, ungrouped_column, + aggregates, group_by, grouping_columns, not_positional, ungrouped_column, }; use crate::databricks::conversion::_helpers::queries::joins::{Source, comma_lateral, joined}; use crate::databricks::conversion::_helpers::queries::partitioning::partitioning; @@ -23,9 +26,10 @@ use crate::databricks::conversion::_helpers::support::tree::{ node_kind, outside, quoted, refused, understood, unresolved_node, }; use crate::databricks::conversion::constants::{ - ALL_KEYWORD, AUTO_SUBQUERY_NAME, CALENDAR_EQUALITY, CONTROL_CHARACTERS, CONTROL_ERROR, - FIXTURE_RULE, FUNCTION_KIND, IDENTIFIER_NAME, LAMBDA_ELEMENT, ORDER_RULE, RENDERED_ELEMENTS, - SELECT_RULE, SET_OPERATION_RULE, VALUES_KIND, WINDOW_KIND, + ALL_KEYWORD, AUTO_SUBQUERY_NAME, BINARY_COLLATION, CALENDAR_EQUALITY, COLLATION_KIND, + CONTROL_CHARACTERS, CONTROL_ERROR, FIXTURE_RULE, FUNCTION_KIND, IDENTIFIER_NAME, + LAMBDA_ELEMENT, LOWER_CASE_COLLATION, ORDER_RULE, RENDERED_ELEMENTS, SELECT_RULE, + SET_OPERATION_RULE, VALUES_KIND, WINDOW_KIND, }; use crate::databricks::conversion::models::{DatabricksType, Element, Emitted, Literal}; @@ -62,6 +66,14 @@ pub(crate) fn defined_query( query(node, log, &outer, false) } +/// The DuckDB SQL and columns of a subquery in an expression, which reads no table or column of the query around it. +pub(crate) fn subquery( + node: &Value, + log: &ProvenanceLog, +) -> Result<(String, Vec<(String, DatabricksType)>), Refusal> { + query(node, log, &[], false) +} + /// A query: one block or a set operation of blocks, reading the common tables `outer` defines; a `top` query's results are written as Databricks returns them, a nested one's kept as DuckDB values. fn query( node: &Value, @@ -132,6 +144,7 @@ fn select( "hint", "lateral_views", "from_first", + "table_statement", "pipe_operators", ], )?; @@ -162,6 +175,17 @@ fn select( true => "SELECT DISTINCT ", false => "SELECT ", }); + if let Some(group) = select.get("group_by").filter(|group| !group.is_null()) { + let keys = Site { + log, + scope: &scope, + aggregates: false, + outputs: false, + windows: false, + order_free: false, + }; + scope.grouping = grouping_columns(group, keys)?; + } let windows = [field(select, "group_by"), field(select, "having")] .iter() .all(|clause| clause.is_null()); @@ -1027,12 +1051,15 @@ fn projected(item: &Value, site: Site<'_>) -> Result, Ref )); } }, - _ => { - return Err(refused( - "select", - "no rule names an unaliased result column that is no column".to_owned(), - )); - } + _ => match spelled_item(item, site.scope)? { + Some(name) => vec![(name, expression(item, site)?)], + None => { + return Err(refused( + "select", + "no rule names an unaliased result column that is no column".to_owned(), + )); + } + }, }; let untyped = named.iter().find(|(_, emitted)| match emitted.data_type { DatabricksType::Array(element) => !RENDERED_ELEMENTS.contains(&element), @@ -1091,6 +1118,9 @@ fn keys(this: &Value, alone: bool, site: Site<'_>) -> Result, Refus .map(|position| positioned(site.scope, position)) .collect(); } + if let Some((COLLATION_KIND, collation)) = node_kind(this) { + return Ok(vec![collated(collation, site)?]); + } let key = expression(this, site)?; match (&key.literal, key.data_type) { (Some(Literal::Number(text)), DatabricksType::Int) if site.outputs => { @@ -1111,6 +1141,19 @@ fn keys(this: &Value, alone: bool, site: Site<'_>) -> Result, Refus } } +/// A STRING key under a collation: as itself under UTF8_BINARY, by its lower case, one code point at a time, under UTF8_LCASE, raising for a character outside those whose lowering was seen to agree. +fn collated(payload: &Value, site: Site<'_>) -> Result { + let (name, key) = collation(payload, site)?; + match name.as_str() { + BINARY_COLLATION => Ok(key), + LOWER_CASE_COLLATION => Ok(lower_cased(key)), + _ => Err(refused( + COLLATION_KIND, + format!("no rule orders by the collation {name}"), + )), + } +} + /// Whether `this` is the unquoted, unqualified word `ALL`. fn bare_all(this: &Value) -> Result { let Some(("column", payload)) = node_kind(this) else { diff --git a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/support/scope.rs b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/support/scope.rs index 15bb1c7fa..c0b19978c 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/_helpers/support/scope.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/_helpers/support/scope.rs @@ -28,6 +28,8 @@ pub(crate) struct Scope { pub(crate) outputs: Vec<(String, Emitted)>, /// The parameters of the lambdas around the expression, innermost last, with what each reads as. pub(crate) parameters: Vec<(String, Emitted)>, + /// The SQL of the block's grouping columns in Databricks's order, which GROUPING and GROUPING_ID read; `None` unless its GROUP BY has ROLLUP, CUBE or GROUPING SETS. + pub(crate) grouping: Option>, } impl Scope { @@ -42,6 +44,7 @@ impl Scope { visible, outputs: Vec::new(), parameters: Vec::new(), + grouping: None, } } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/constants.rs b/crates/sqlbabel-convert/src/databricks/conversion/constants.rs index fe68b16b2..cf422b988 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/constants.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/constants.rs @@ -30,6 +30,14 @@ pub const BOOLEAN_RULE: &str = "rule.databricks.boolean"; pub const NULL_TEST_RULE: &str = "rule.databricks.null_test"; /// `[NOT] BETWEEN` on values of one type family. pub const BETWEEN_RULE: &str = "rule.databricks.between"; +/// Why NOT of NOT IN a subquery refuses: NOT IN reads a NULL answer as FALSE, and no recording shows what a negation of it gives. +pub const IN_SUBQUERY_NEGATED: &str = + "no rule converts NOT of NOT IN a subquery, which no recording shows"; +/// The most fraction digits Java's DecimalFormat writes for an integer, as FORMAT_NUMBER does past them. +pub const JAVA_FRACTION_DIGITS: u32 = 340; +/// What FORMAT_NUMBER of a DECIMAL raises for more places than [`JAVA_FRACTION_DIGITS`], which no recording shows. +pub const FORMAT_NUMBER_PLACES_UNREAD: &str = + "no recording shows FORMAT_NUMBER of a DECIMAL with more than 340 places"; /// `[NOT] IN` a list of values of one type family. pub const IN_LIST_RULE: &str = "rule.databricks.in_list"; /// A searched `CASE` whose branches share one type. @@ -229,6 +237,16 @@ pub const NTILE_NAME: &str = "NTILE"; pub const NTH_VALUE_NAME: &str = "NTH_VALUE"; /// The window functions reading a row a given offset away, which take no frame. pub const OFFSET_WINDOWS: &[&str] = &["LAG", "LEAD"]; +/// COUNTER_DIFF: the rise of a counter since its last non-NULL value, NULL where it fell. +pub const COUNTER_DIFF_NAME: &str = "COUNTER_DIFF"; +/// The counter types COUNTER_DIFF converts, whose difference keeps the counter's type in both engines. +pub const COUNTER_TYPES: &[DatabricksType] = &[ + DatabricksType::Int, + DatabricksType::BigInt, + DatabricksType::Double, +]; +/// The frame of the rows before the current one, which COUNTER_DIFF reads its last value from. +pub const PREVIOUS_ROWS: &str = "ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING"; /// The largest offset, bucket count or frame bound a rule converts: the largest INT. pub const MAX_WINDOW_COUNT: u64 = 2_147_483_647; /// The one ranking function whose frame Databricks names RANGE rather than ROWS. @@ -248,7 +266,7 @@ pub const COLLECT_ORDER: &str = "collect_list_order"; pub const COLLECT_ORDER_ERROR: &str = "collect_list_order: COLLECT_LIST or ARRAY_AGG of several distinct values in no defined order"; /// FIRST and LAST as aggregates, in each spelling, whose value depends on the order rows arrive. -pub const ORDERED_PICKS: &[&str] = &["FIRST", "FIRST_VALUE", "LAST", "LAST_VALUE"]; +pub const ORDERED_PICKS: &[&str] = &["FIRST", "FIRST_VALUE", "LAST", "LAST_VALUE", "ANY_VALUE"]; /// The divergence of MAX_BY and MIN_BY, which break a tie on their ordering in an order neither engine defines. pub const PICK_TIES: &str = "max_by_ties"; /// What MAX_BY or MIN_BY raises where rows tie on an ordering that decides the result. @@ -307,6 +325,36 @@ pub const SHA2_DEFAULT_BITS: &str = "0"; pub const SHA2_MISSING_BITS: &str = "224, 384, 512"; /// The error SHA2 raises for a digest length DuckDB has no function for. pub const DIGEST_ERROR: &str = "the SHA2 digest length has no DuckDB function"; +/// The SHA-256 block HMAC pads its key to, in bytes; a longer key is hashed first. +pub const HMAC_BLOCK: u8 = 64; +/// The bytes HMAC XORs into the padded key for its inner and its outer hash. +pub const HMAC_PADS: (u8, u8) = (0x36, 0x5C); +/// The error HMAC raises for an empty key, which Databricks rejects. +pub const HMAC_EMPTY_KEY_ERROR: &str = "HMAC needs a key of at least one byte"; +/// The seed Databricks starts HASH and XXHASH64 from. +pub const HASH_SEED: u64 = 42; +/// The reflected CRC-32 polynomial. +pub const CRC32_POLYNOMIAL: u64 = 0xEDB8_8320; +/// 2^32 - 1, CRC32's start and final XOR. +pub const CRC32_ALL_ONES: u64 = 0xFFFF_FFFF; +/// Murmur3_x86_32's two block multipliers and the constant its hash adds after each block. +pub const MURMUR3_BLOCK: (u64, u64, u64) = (0xCC9E_2D51, 0x1B87_3593, 0xE654_6B64); +/// Murmur3_x86_32's two finishing multipliers. +pub const MURMUR3_FINISH: (u64, u64) = (0x85EB_CA6B, 0xC2B2_AE35); +/// xxHash64's five primes. +pub const XXHASH64_PRIMES: [u64; 5] = [ + 0x9E37_79B1_85EB_CA87, + 0xC2B2_AE3D_27D4_EB4F, + 0x1656_67B1_9E37_79F9, + 0x85EB_CA77_C2B2_AE63, + 0x27D4_EB2F_1656_67C5, +]; +/// What sign-extends a byte of 128 or more to a 32-bit word, as Spark reads the bytes past a hash's last word. +pub const SIGN_EXTENSION: u64 = 0xFFFF_FF00; +/// The sign bit of a 32-bit word. +pub const INT_SIGN: u64 = 1 << 31; +/// The sign bit of a 64-bit word. +pub const BIGINT_SIGN: u64 = 1 << 63; /// An aggregate DuckDB computes the same way, its result cast to the type Databricks gives it. pub const AGGREGATE_RULE: &str = "rule.databricks.aggregate"; /// A date or timestamp function: a field such as DAY or HOUR, or date arithmetic in whole days. @@ -387,6 +435,8 @@ pub const MIN_IN_ARGUMENTS: usize = 2; pub const WITHIN_GROUP_KIND: &str = "within_group"; /// The node kind of `EXTRACT(field FROM x)`. pub const EXTRACT_KIND: &str = "extract"; +/// The aggregates whose unaliased call on a column Databricks names as `sum(x2)` is written, lower-cased. +pub const NAMED_AGGREGATES: &[&str] = &["SUM", "MIN", "MAX"]; /// The node kind of a call the parser keeps by name. pub const FUNCTION_KIND: &str = "function"; /// The node kind of an aggregate call with a FILTER clause. @@ -437,10 +487,40 @@ pub const RANGE_NAME: &str = "RANGE"; pub const PIVOT_RULE: &str = "rule.databricks.pivot"; /// The node kind of a column reference. pub const COLUMN_KIND: &str = "column"; +/// The node kind of a literal. +pub const LITERAL_KIND: &str = "literal"; /// The clause naming a column or table by a string, `IDENTIFIER('...')`. pub const IDENTIFIER_NAME: &str = "IDENTIFIER"; /// The word `LIMIT ALL` reads as a variable, keeping every row. pub const ALL_KEYWORD: &str = "ALL"; +/// Capital sigma, which Java's LOWER lowers by its place in a word and UTF8_LCASE, like DuckDB, to sigma. +pub const CAPITAL_SIGMA: &str = r"\x{3a3}"; +/// The node kind of a `name => value` argument. +pub const NAMED_ARGUMENT_KIND: &str = "named_argument"; +/// The named argument choosing how SEARCH and ISEARCH match. +pub const SEARCH_MODE_NAME: &str = "mode"; +/// Capital I with dot above, which UTF8_LCASE lowers to `i` and a combining dot. +pub const CAPITAL_DOTTED_I: char = '\u{130}'; +/// The combining dot above that follows `i` in the lower case of capital I with dot above. +pub const COMBINING_DOT: char = '\u{307}'; +/// The lower-case `i`, the first half of the lower case of capital I with dot above. +pub const LATIN_LOWER_I: char = 'i'; +/// What ISEARCH raises where its pattern could match half of a capital I with dot above, which no recording shows. +pub const DOTTED_SPLIT_ERROR: &str = + "no recording shows ISEARCH matching part of a capital I with dot above"; +/// The SEARCH mode that matches the pattern anywhere in a value, the default. +pub const SUBSTRING_MODE: &str = "substring"; +/// The most whole-number digits a DECIMAL may have for every value to fit BIGINT. +pub const BIGINT_WHOLE_DIGITS: u8 = 18; +/// The node kind of `x COLLATE name`. +pub const COLLATION_KIND: &str = "collation"; +/// The collation comparing strings byte by byte, the default. +pub const BINARY_COLLATION: &str = "UTF8_BINARY"; +/// The collation comparing strings by their lower case, one code point at a time. +pub const LOWER_CASE_COLLATION: &str = "UTF8_LCASE"; +/// The code points UTF8_LCASE lowers otherwise than the simple case mapping DuckDB's `lower` applies: capital I with dot above to `i` and a combining dot, and final sigma to sigma. +pub const LOWER_CASE_EXCEPTIONS: &[(&str, &str)] = + &[("\u{130}", "i\u{307}"), ("\u{3c2}", "\u{3c3}")]; /// The start of the name a LATERAL VIEW without a table alias is read by, which no qualifier can name. pub const LATERAL_VIEW_NAME: &str = "__lateral_view_"; /// The name Databricks gives a FROM subquery written without an alias. @@ -816,6 +896,8 @@ pub const FRAME_KIND: &str = "frame"; /// The spelling a TIME literal's refusal names, which links to the TIME literal form. pub const TIME_LITERAL_SPELLING: &str = "time_literal"; +/// The length of a TIME literal of two-digit hours and minutes without seconds, `HH:MM`, which Databricks reads at zero seconds. +pub const HOURS_MINUTES_LENGTH: usize = 5; /// The most significant bits a FLOAT holds. pub const FLOAT_MANTISSA_BITS: u32 = 24; /// The most significant bits a DOUBLE holds. @@ -965,7 +1047,8 @@ pub const FAILURE_MODES: &[(&str, &[FailureMode])] = &[ (ARITHMETIC_RULE, &[OVERFLOW]), (SAME_FUNCTION_RULE, &[OVERFLOW]), (DIVISION_RULE, &[DIVISION, OVERFLOW]), - (AGGREGATE_RULE, &[OVERFLOW]), + (AGGREGATE_RULE, &[OVERFLOW, ARGUMENT]), + (WINDOW_RULE, &[ARGUMENT]), ( DATE_FUNCTION_RULE, &[OVERFLOW, ARGUMENT, DATE_TEXT, TIMESTAMP_TEXT, TIME_TEXT], @@ -999,6 +1082,10 @@ pub const FAILURE_MODES: &[(&str, &[FailureMode])] = &[ /// The bits in one Databricks bitmap, which BITMAP_BIT_POSITION and BITMAP_BUCKET_NUMBER split a value by. pub const BITMAP_BITS: u16 = 32768; +/// What BITMAP_CONSTRUCT_AGG raises, after the argument-rejected fragment, for a bit position outside a bitmap. +pub const BITMAP_POSITION_ERROR: &str = "the bit position is outside the bitmap"; +/// What COUNTER_DIFF raises for a negative counter value, which Databricks rejects. +pub const NEGATIVE_COUNTER_ERROR: &str = "the counter value is negative"; /// The largest BIGINT, where Java's cast of a larger DOUBLE saturates. pub const BIGINT_MAX: &str = "9223372036854775807"; /// The smallest BIGINT, where Java's cast of a smaller DOUBLE saturates. @@ -1013,6 +1100,10 @@ pub const UNSIGNED_SPAN: &str = "18446744073709551616"; pub const SIGN_BIT: &str = "9223372036854775808"; /// The lambda parameter of a running total, such as CONV's value as it reads each digit. pub const LAMBDA_TOTAL: &str = "total"; +/// The lambda parameter of a hash as it reads each byte or word. +pub const LAMBDA_HASHED: &str = "hashed"; +/// The lambda parameter of xxHash64's four accumulators. +pub const LAMBDA_ACCUMULATORS: &str = "accumulators"; /// Java's `Math.E` as a DuckDB DOUBLE: its shortest decimal text, which reads back as the same DOUBLE. pub const EULER: &str = "CAST('2.718281828459045' AS DOUBLE)"; /// The largest argument FACTORIAL takes; it returns NULL above it, as 21! exceeds BIGINT. @@ -1152,6 +1243,12 @@ pub const DATE_PATTERN_LETTERS: &[(&str, &str)] = &[ ("SSS", "%g"), ("SSSSSS", "%f"), ]; +/// The Java pattern letters of [`DATE_PATTERN_LETTERS`] that write a time of day, the only ones DATE_FORMAT of a TIME is converted with. +pub const TIME_PATTERN_LETTERS: &[&str] = &[ + "a", "HH", "H", "hh", "h", "mm", "m", "ss", "s", "SSS", "SSSSSS", +]; +/// The date a TIME is written on as a timestamp, which a pattern of [`TIME_PATTERN_LETTERS`] never shows. +pub const TIME_EPOCH_DATE: &str = "DATE '1970-01-01'"; /// What TO_CHAR raises for a value with more digits than its format, which Spark writes as `#` and no recording shows. pub const NUMBER_FORMAT_OVERFLOW_ERROR: &str = "the value has more digits than the number format, which no recording shows Databricks writing"; @@ -1206,6 +1303,7 @@ pub const AGGREGATES: &[(&str, &str)] = &[ ("BIT_XOR", "bit_xor"), ("BITMAP_OR_AGG", "bit_or"), ("BITMAP_AND_AGG", "bit_and"), + ("BITMAP_CONSTRUCT_AGG", "bitstring_agg"), ]; /// The functions named after a type, which cast their one argument to it. @@ -1247,6 +1345,10 @@ pub const TIME_UNITS: [(&str, i64); 7] = [ ("DAY", 86_400_000_000), ("WEEK", 604_800_000_000), ]; +/// TIME_DIFF, whose unit Databricks reads as a string, so a unit keyword written as a name is a column it cannot resolve. +pub const TIME_DIFF_NAME: &str = "TIME_DIFF"; +/// The microseconds of TIME_DIFF's largest unit, an hour; a TIME spans less than a day. +pub const TIME_DIFF_UNIT_MICROS: i64 = 3_600_000_000; /// The datetime units counted in months, with the months each holds. pub const MONTH_UNITS: [(&str, i64); 3] = [("MONTH", 1), ("QUARTER", 3), ("YEAR", 12)]; /// The unit TIMESTAMPADD reads as DAY and TIMESTAMPDIFF rejects. diff --git a/crates/sqlbabel-convert/src/databricks/conversion/main/_convert_effect.rs b/crates/sqlbabel-convert/src/databricks/conversion/main/_convert_effect.rs index d9c6df63d..1e2933fa3 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/main/_convert_effect.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/main/_convert_effect.rs @@ -26,7 +26,8 @@ pub(crate) fn convert_effect( match catalog.in_transaction { true => Err(refused( "utility_statement", - "the probes would read inside an open transaction".to_owned(), + "the statements end inside an open transaction, so what they commit is unknown" + .to_owned(), )), false => Ok(written), } diff --git a/crates/sqlbabel-convert/src/databricks/conversion/recorded_rejections.txt b/crates/sqlbabel-convert/src/databricks/conversion/recorded_rejections.txt index 17e2b53e7..2f7f1534f 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/recorded_rejections.txt +++ b/crates/sqlbabel-convert/src/databricks/conversion/recorded_rejections.txt @@ -79,6 +79,8 @@ ELEMENT_AT(STRING, INT) ENCODE(ARRAY, STRING) ENDSWITH(ARRAY, STRING) FIND_IN_SET(ARRAY, STRING) +FORMAT_NUMBER(INT, BIGINT) +FORMAT_NUMBER(STRING, INT) FORMAT_STRING(ARRAY) GET(ARRAY, ARRAY) GET(STRING, INT) @@ -141,6 +143,7 @@ RIGHT(ARRAY, INT) RLIKE(ARRAY, STRING) RPAD(ARRAY, INT) SEQUENCE(DATE, INT) +SEQUENCE(STRING, STRING) SEQUENCE(TIMESTAMP, INT) SHA(ARRAY) SHA1(ARRAY) @@ -218,6 +221,7 @@ URL_ENCODE(ARRAY) VALIDATE_UTF8(ARRAY) VECTOR_COSINE_SIMILARITY(STRING, ARRAY) VECTOR_INNER_PRODUCT(STRING, ARRAY) +VECTOR_L2_DISTANCE(STRING, ARRAY) VECTOR_NORM(STRING) WIDTH_BUCKET(INTERVAL DAY, INT, INT, INT) WIDTH_BUCKET(INTERVAL YEAR TO MONTH, INT, INT, INT) diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests.rs index dbe0def7a..d30dd2e44 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests.rs @@ -10,6 +10,8 @@ mod test_convert_effect; mod test_queries; #[path = "tests/test_raises.rs"] mod test_raises; +#[path = "tests/test_search.rs"] +mod test_search; #[path = "tests/test_types.rs"] mod test_types; #[path = "tests/test_vectors.rs"] diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_categories.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_categories.rs index 6bdff4b57..1f78be997 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_categories.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_categories.rs @@ -3,7 +3,9 @@ use sqlbabel_diagnostics::refusals::models::RefusalCategory; use crate::databricks::analysis::main::analyze::analyze; -use crate::databricks::conversion::tests::test_types::CategoryTestCase; +use crate::databricks::conversion::tests::test_types::{ + CategoryTestCase, RefusedConstructTestCase, +}; const FIXTURE: &str = "WITH input AS (SELECT * FROM VALUES (1, CAST(-7 AS INT), CAST('a' AS STRING)), \ (2, CAST(NULL AS INT), CAST(NULL AS STRING)) AS input(ordinal, x1, s)) "; @@ -198,3 +200,38 @@ fn given_arguments_outside_a_rule_when_converted_then_the_refusal_is_a_type_cond ); } } + +#[test] +fn given_a_refused_query_when_its_construct_is_keyed_then_it_names_the_construct_statements_carry() +{ + let test_cases = [ + RefusedConstructTestCase { + description: "a cast to a MAP of DOUBLE keys is cast:MAP, the key a statement using it carries", + query: "SELECT CAST(NULL AS MAP) AS r FROM input", + expected_key: "cast:MAP", + }, + RefusedConstructTestCase { + description: "a STRUCT cast is cast:OBJECT, as the classifier names STRUCT", + query: "SELECT CAST(NULL AS STRUCT) AS r FROM input", + expected_key: "cast:OBJECT", + }, + RefusedConstructTestCase { + description: "ARRAY_SORT with a comparator is fn:ARRAY_SORT, not the lambda other functions convert", + query: "SELECT array_sort(array(x1), (l, r) -> r - l) AS r FROM input", + expected_key: "fn:ARRAY_SORT", + }, + ]; + for test_case in test_cases { + let refusal = + analyze(&format!("{FIXTURE}{}", test_case.query)).expect_err(test_case.description); + assert_eq!( + refusal + .construct + .map(|construct| construct.key()) + .as_deref(), + Some(test_case.expected_key), + "{}", + test_case.description + ); + } +} diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert.rs index 514d5097a..111818347 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert.rs @@ -6,7 +6,6 @@ use crate::databricks::conversion::models::{DatabricksType, Element, IntervalFie use crate::databricks::conversion::tests::test_types::{ ColumnDivergenceTestCase, ConvertTestCase, DivergenceTestCase, RefuseTestCase, - RefusedConstructTestCase, }; const FIXTURE: &str = "WITH input AS (SELECT * FROM VALUES (1, CAST(-7 AS INT), CAST('a' AS STRING)), \ @@ -651,6 +650,14 @@ fn given_a_query_over_the_fixture_when_converted_then_duckdb_sql_keeps_databrick ], expected_types: &[DatabricksType::String], }, + ConvertTestCase { + description: "DATE_FORMAT of a TIME writes it on a date its time-of-day pattern never shows", + query: "SELECT date_format(TIME'23:59:59.999999', 'hh:mm:ss.SSS a') AS r FROM input", + expected_sql: &[ + "strftime((DATE '1970-01-01' + TIME '23:59:59.999999'), '%I:%M:%S.%g %p')", + ], + expected_types: &[DatabricksType::String], + }, ConvertTestCase { description: "URL_DECODE raises for an escape Java reads with a sign or non-ASCII digits", query: "SELECT try_url_decode(s) AS r FROM input", @@ -1250,6 +1257,12 @@ fn given_a_query_over_the_fixture_when_converted_then_duckdb_sql_keeps_databrick }, ], }, + ConvertTestCase { + description: "a TIME literal of hours and minutes reads as zero seconds", + query: "SELECT TIME'23:59' AS r FROM input", + expected_sql: &["TIME '23:59:00' AS \"r\""], + expected_types: &[DatabricksType::Time], + }, ConvertTestCase { description: "OVER a name the WINDOW clause defines takes its definition in every window function", query: "SELECT sum(x1) OVER w AS r, count(x1) OVER w AS c FROM input WINDOW w AS (ORDER BY ordinal)", @@ -1323,16 +1336,36 @@ fn given_a_hazard_or_unknown_construct_when_converted_then_it_is_refused() { query: "SELECT regexp_substr(s, '\\\\bab') AS r FROM input", expected_reason: "REGEXP_SUBSTR", }, + RefuseTestCase { + description: "DATE_FORMAT of a TIME with a date letter, which no recording shows Databricks writing", + query: "SELECT date_format(TIME'12:00:00', 'yyyy HH') AS r FROM input", + expected_reason: "DATE_FORMAT", + }, RefuseTestCase { description: "a week-based year, which Spark rejects and strftime would write", query: "SELECT date_format(CAST(s AS DATE), 'YYYY') AS r FROM input", expected_reason: "DATE_FORMAT", }, RefuseTestCase { - description: "a DOUBLE number for CONV, whose text Java writes differently", - query: "SELECT conv(CAST(x1 AS DOUBLE), 10, 2) AS r FROM input", + description: "TIME_DIFF of a unit keyword written as a name, which Databricks reads as a column it cannot resolve", + query: "SELECT time_diff(SECOND, x1, x1) AS r FROM input", + expected_reason: "TIME_DIFF", + }, + RefuseTestCase { + description: "a FLOAT number for CONV, whose text Java writes differently", + query: "SELECT conv(CAST(x1 AS FLOAT), 10, 2) AS r FROM input", expected_reason: "CONV", }, + RefuseTestCase { + description: "a DOUBLE number for CONV, which Java writes as 9.999999999999999E22 for 1e23", + query: "SELECT conv(CAST(x1 AS DOUBLE), 10, 36) AS r FROM input", + expected_reason: "CONV", + }, + RefuseTestCase { + description: "FORMAT_NUMBER of a DOUBLE, whose digits Databricks takes from Java's text", + query: "SELECT format_number(CAST(x1 AS DOUBLE), 2) AS r FROM input", + expected_reason: "FORMAT_NUMBER", + }, RefuseTestCase { description: "TO_CHAR of text, which Databricks formats as a number", query: "SELECT to_char(s, 'yyyy') AS r FROM input", @@ -1498,11 +1531,6 @@ fn given_a_hazard_or_unknown_construct_when_converted_then_it_is_refused() { query: "SELECT avg(x1) OVER (ORDER BY ordinal) AS r FROM input", expected_reason: "AVG as a window function", }, - RefuseTestCase { - description: "a RANGE frame with a literal offset, even of 0", - query: "SELECT sum(x1) OVER (ORDER BY ordinal RANGE BETWEEN 0 PRECEDING AND CURRENT ROW) AS r FROM input", - expected_reason: "over a frame other than", - }, RefuseTestCase { description: "a window in QUALIFY ordered by a SELECT alias, which no recording shows Databricks resolving", query: "SELECT x1 AS y FROM input QUALIFY row_number() OVER (ORDER BY y) = 1", @@ -1618,6 +1646,11 @@ fn given_a_hazard_or_unknown_construct_when_converted_then_it_is_refused() { query: "SELECT TIME'24:00:00' AS r FROM input", expected_reason: "no rule reads the time literal `24:00:00`", }, + RefuseTestCase { + description: "a TIME literal of one-digit hours without seconds, which no recording shows Databricks reading", + query: "SELECT TIME'1:30' AS r FROM input", + expected_reason: "no rule reads the time literal `1:30`", + }, RefuseTestCase { description: "a cast to TIME(3), which DuckDB's TIME does not round to", query: "SELECT CAST(TIME'01:02:03' AS TIME(3)) AS r FROM input", @@ -1861,35 +1894,6 @@ fn given_a_last_place_function_in_one_result_column_when_converted_then_only_tha } } -#[test] -fn given_a_cast_to_a_type_no_rule_maps_when_refused_then_its_key_names_the_cast_as_statements_do() { - let test_cases = [ - RefusedConstructTestCase { - description: "a cast to a MAP of DOUBLE keys is cast:MAP, the key a statement using it carries", - query: "SELECT CAST(NULL AS MAP) AS r FROM input", - expected_key: "cast:MAP", - }, - RefusedConstructTestCase { - description: "a STRUCT cast is cast:OBJECT, as the classifier names STRUCT", - query: "SELECT CAST(NULL AS STRUCT) AS r FROM input", - expected_key: "cast:OBJECT", - }, - ]; - for test_case in test_cases { - let refusal = - analyze(&format!("{FIXTURE}{}", test_case.query)).expect_err(test_case.description); - assert_eq!( - refusal - .construct - .map(|construct| construct.key()) - .as_deref(), - Some(test_case.expected_key), - "{}", - test_case.description - ); - } -} - #[test] fn given_float_array_elements_when_a_function_compares_them_then_it_is_refused_by_name() { let test_cases = [ diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert_effect.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert_effect.rs index bee243bb4..5dcf3769f 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert_effect.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_convert_effect.rs @@ -355,12 +355,19 @@ fn given_effect_statements_when_converted_then_duckdb_runs_them_alike_or_they_ar expected_refusal: "no DDL", }, EffectTestCase { - description: "a transaction left open is refused, as the probes would read inside it", + description: "a transaction left open is refused, as what it commits is unknown", setup: &[], statements: &["BEGIN TRANSACTION"], expected_statements: &[], expected_refusal: "inside an open transaction", }, + EffectTestCase { + description: "an insert into a table no statement defines is refused, naming the table", + setup: &[], + statements: &["INSERT INTO t VALUES (1)"], + expected_statements: &[], + expected_refusal: "this script doesn't define the table or view `t`", + }, ]; for test_case in test_cases { let setup: Vec = test_case diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_queries.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_queries.rs index ac307d2bb..816bab6b4 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_queries.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_queries.rs @@ -229,6 +229,21 @@ fn given_a_query_clause_no_rule_reads_as_databricks_does_when_converted_then_it_ query: "SELECT 1 AS one, count(*) AS n FROM input GROUP BY ALL", expected_reason: "no rule converts a literal in group_by", }, + RefuseTestCase { + description: "a DECIMAL cast to BIGINT whose whole part BIGINT may not hold", + query: "SELECT CAST(CAST(x1 AS DECIMAL(20, 1)) AS BIGINT) AS r FROM input", + expected_reason: "no rule shows DuckDB casts", + }, + RefuseTestCase { + description: "GROUP BY a position past the outputs, which Databricks rejects", + query: "SELECT s, count(*) AS n FROM input GROUP BY 3", + expected_reason: "position 3 is outside the 2 columns the query returns", + }, + RefuseTestCase { + description: "GROUP BY the position of an aggregate, which Databricks rejects", + query: "SELECT s, count(*) AS n FROM input GROUP BY 1, 2", + expected_reason: "position 2 names an aggregate", + }, RefuseTestCase { description: "FILTER on FIRST, which counts the NULLs the filter would add", query: "SELECT first(x1) FILTER (WHERE x1 > 0) AS r FROM input", @@ -334,6 +349,56 @@ fn given_a_query_clause_no_rule_reads_as_databricks_does_when_converted_then_it_ query: "SELECT s, count(*) AS n FROM input GROUP BY s, x1 GROUPING SETS (s)", expected_reason: "a GROUP BY key outside its GROUPING SETS", }, + RefuseTestCase { + description: "DECODE of a key of another type than the value, or INT columns as results", + query: "SELECT decode(x1, 'a', 1) AS r, decode(x1, 1, x1) AS c FROM input", + expected_reason: "no rule converts DECODE of (INT, STRING, INT)", + }, + RefuseTestCase { + description: "DECODE of integer results with a default, which Databricks types INT, not the BIGINT it gives without one", + query: "SELECT decode(s, 'a', 1, 'b', 2, 0) AS r FROM input", + expected_reason: "no rule converts DECODE of (STRING, STRING, INT, STRING, INT, INT)", + }, + RefuseTestCase { + description: "a RANGE frame with an offset over a SMALLINT key, which Databricks adds in SMALLINT and DuckDB in INTEGER", + query: "SELECT sum(x1) OVER (ORDER BY CAST(x1 AS SMALLINT) RANGE BETWEEN 1 PRECEDING AND CURRENT ROW) AS r FROM input", + expected_reason: "over a frame other than", + }, + RefuseTestCase { + description: "NOT of NOT IN a subquery, which no recording shows", + query: "SELECT NOT (x1 NOT IN (SELECT y FROM VALUES (1) AS t(y))) AS r FROM input", + expected_reason: "NOT of NOT IN a subquery", + }, + RefuseTestCase { + description: "a RANGE frame with a literal offset over a STRING key, even of 0", + query: "SELECT sum(x1) OVER (ORDER BY s RANGE BETWEEN 0 PRECEDING AND CURRENT ROW) AS r FROM input", + expected_reason: "over a frame other than", + }, + RefuseTestCase { + description: "a RANGE frame with a literal offset over two keys", + query: "SELECT count(x1) OVER (ORDER BY x1, ordinal RANGE BETWEEN 1 PRECEDING AND CURRENT ROW) AS r FROM input", + expected_reason: "over a frame other than", + }, + RefuseTestCase { + description: "ORDER BY under a collation other than UTF8_BINARY or UTF8_LCASE", + query: "SELECT s FROM input ORDER BY s COLLATE UNICODE_CI", + expected_reason: "no rule orders by the collation UNICODE_CI", + }, + RefuseTestCase { + description: "a comparison under a collation other than UTF8_BINARY", + query: "SELECT x1 FROM input WHERE s COLLATE UTF8_LCASE = 'a'", + expected_reason: "no rule compares under the collation UTF8_LCASE", + }, + RefuseTestCase { + description: "a value under a collation, which Databricks types with the collation", + query: "SELECT s COLLATE UTF8_BINARY AS c FROM input", + expected_reason: "which Databricks types STRING COLLATE UTF8_BINARY", + }, + RefuseTestCase { + description: "ORDER BY an INT under a collation", + query: "SELECT x1 FROM input ORDER BY x1 COLLATE UTF8_LCASE", + expected_reason: "no rule gives a INT a collation", + }, ]; for test_case in test_cases { let reason = analyze(&format!("{FIXTURE}{}", test_case.query)) @@ -350,6 +415,49 @@ fn given_a_query_clause_no_rule_reads_as_databricks_does_when_converted_then_it_ #[test] fn given_grouping_filtering_or_paging_clauses_when_converted_then_duckdb_reads_the_same_rows() { let test_cases = [ + ConvertTestCase { + description: "DECODE matches a NULL key to a NULL value, and returns integer literal results as BIGINT", + query: "SELECT decode(x1, NULL, 'null', 1, 'one', 'other') AS r, decode(s, 'a', 1, 'b', 2) AS n FROM input", + expected_sql: &[ + "(CASE WHEN \"x1\" IS NOT DISTINCT FROM NULL THEN 'null' WHEN \"x1\" IS NOT DISTINCT FROM 1 THEN 'one' ELSE 'other' END) AS \"r\"", + "WHEN \"s\" IS NOT DISTINCT FROM 'a' THEN CAST(1 AS BIGINT)", + ], + expected_types: &[DatabricksType::String, DatabricksType::BigInt], + }, + ConvertTestCase { + description: "NOT IN a subquery and NOT of IN one read a NULL answer as FALSE, in the select list and in a filter", + query: "SELECT x1 NOT IN (SELECT y FROM VALUES (1), (NULL) AS t(y)) AS r FROM input WHERE NOT (x1 IN (SELECT y FROM VALUES (2) AS t(y)))", + expected_sql: &[ + "SELECT coalesce(\"x1\" NOT IN (SELECT", + "WHERE coalesce(\"x1\" NOT IN (SELECT", + ], + expected_types: &[DatabricksType::Boolean], + }, + ConvertTestCase { + description: "a comparison under UTF8_BINARY compares the strings byte by byte, either side", + query: "SELECT s COLLATE utf8_binary = 'a' AS e, 'B' > s COLLATE UTF8_BINARY AS g FROM input", + expected_sql: &["SELECT (\"s\" = 'a') AS \"e\", ('B' > \"s\") AS \"g\""], + expected_types: &[DatabricksType::Boolean, DatabricksType::Boolean], + }, + ConvertTestCase { + description: "ORDER BY under UTF8_LCASE orders by the lower case Spark gives each code point, and UTF8_BINARY by the string", + query: "SELECT s FROM input ORDER BY s COLLATE utf8_lcase DESC, lower(s) COLLATE UTF8_BINARY", + expected_sql: &[ + "ORDER BY (CASE WHEN regexp_matches(replace(replace(\"s\", '\u{130}', 'i\u{307}'), '\u{3c2}', '\u{3c3}'), ", + "ELSE lower(replace(replace(\"s\", '\u{130}', 'i\u{307}'), '\u{3c2}', '\u{3c3}')) END) DESC NULLS LAST, (CASE WHEN regexp_matches(\"s\", ", + ], + expected_types: &[DatabricksType::String], + }, + ConvertTestCase { + description: "a RANGE frame with offsets over one integer key keeps them, descending too", + query: "SELECT count(x1) OVER (ORDER BY x1 RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS r, \ + first_value(x1) OVER (ORDER BY x1 DESC RANGE BETWEEN 2 PRECEDING AND CURRENT ROW) AS f FROM input", + expected_sql: &[ + "count(\"x1\") OVER (ORDER BY \"x1\" ASC NULLS FIRST RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS \"r\"", + "first_value(\"x1\") OVER (ORDER BY \"x1\" DESC NULLS LAST RANGE BETWEEN 2 PRECEDING AND CURRENT ROW) AS \"f\"", + ], + expected_types: &[DatabricksType::BigInt, DatabricksType::Int], + }, ConvertTestCase { description: "OFFSET skips rows after the ORDER BY and LIMIT", query: "SELECT x1 AS r FROM input ORDER BY ordinal LIMIT 1 OFFSET 1", @@ -394,6 +502,16 @@ fn given_grouping_filtering_or_paging_clauses_when_converted_then_duckdb_reads_t DatabricksType::BigInt, ], }, + ConvertTestCase { + description: "an integer GROUP BY key names the output at that position", + query: "SELECT s, x1 + 1 AS y, count(*) AS n FROM input GROUP BY 2, 1", + expected_sql: &["GROUP BY (\"x1\" + 1), \"s\""], + expected_types: &[ + DatabricksType::String, + DatabricksType::Int, + DatabricksType::BigInt, + ], + }, ConvertTestCase { description: "GROUP BY ALL leaves out PERCENTILE and MAX_BY, which are aggregates a rule of their own converts", query: "SELECT s, percentile(x1, 0.5) AS p, max_by(s, x1) AS m FROM input GROUP BY ALL ORDER BY s", @@ -505,6 +623,18 @@ fn given_grouping_filtering_or_paging_clauses_when_converted_then_duckdb_reads_t ], expected_types: &[DatabricksType::Int], }, + ConvertTestCase { + description: "a DECIMAL cast to BIGINT truncates toward zero where DuckDB would round", + query: "SELECT CAST(CAST(x1 AS DECIMAL(10, 2)) AS BIGINT) AS r FROM input", + expected_sql: &["CAST(trunc(CAST(\"x1\" AS DECIMAL(10, 2))) AS BIGINT)"], + expected_types: &[DatabricksType::BigInt], + }, + ConvertTestCase { + description: "a pipeline starting TABLE a relation reads every column of it", + query: "SELECT x1 FROM (TABLE input |> WHERE x1 > 0) AS q", + expected_sql: &["FROM \"input\" WHERE (\"x1\" > 0)) AS \"q\""], + expected_types: &[DatabricksType::Int], + }, ConvertTestCase { description: "a pipe join after a LATERAL VIEW joins the exploded rows, so unmatched right rows keep NULLs", query: ", t AS (SELECT ordinal, array(x1) AS a FROM input), u AS (SELECT ordinal AS uid FROM input) FROM t LATERAL VIEW explode(a) v AS e |> RIGHT JOIN u ON ordinal = uid |> SELECT uid, e", diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_raises.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_raises.rs index 29d2194df..02e343be6 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_raises.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_raises.rs @@ -41,12 +41,38 @@ fn given_a_function_that_raises_when_converted_then_duckdb_raises_as_databricks_ ], expected_types: &[DatabricksType::Null], }, + ConvertTestCase { + description: "COUNTER_DIFF rejects a negative counter before taking any difference", + query: "SELECT counter_diff(x1) OVER (ORDER BY ordinal) AS r FROM input", + expected_sql: &[ + "CASE WHEN \"x1\" < 0 THEN CAST(error('argument rejected: the counter value is negative') AS INTEGER) WHEN \"x1\" >= last_value(", + ], + expected_types: &[DatabricksType::Int], + }, + ConvertTestCase { + description: "FORMAT_NUMBER writes at most 340 places of an integer, and raises past them for a DECIMAL no recording shows", + query: "SELECT format_number(x1, x1) AS i, format_number(CAST(x1 AS DECIMAL(5, 2)), x1) AS d FROM input", + expected_sql: &[ + "repeat('0', least(\"x1\", 340))", + "CASE WHEN \"x1\" > 340 THEN CAST(error('no recording shows FORMAT_NUMBER of a DECIMAL with more than 340 places') AS VARCHAR)", + ], + expected_types: &[DatabricksType::String, DatabricksType::String], + }, ConvertTestCase { description: "ARRAY_REPEAT rejects a count past the most elements an array holds", query: "SELECT array_repeat(s, x1) AS r FROM input", expected_sql: &["WHEN \"x1\" > 2147483632 THEN CAST(error('argument rejected: "], expected_types: &[DatabricksType::Array(Element::String)], }, + ConvertTestCase { + description: "SEQUENCE reads a STRING bound beside an INT one as BIGINT, raising for text that is no whole number", + query: "SELECT sequence(s, x1) AS r FROM input", + expected_sql: &[ + "THEN CAST(trim(\"s\", ' ') AS BIGINT) WHEN", + "THEN CAST(error('text rejected as a number: ", + ], + expected_types: &[DatabricksType::Array(Element::BigInt)], + }, ]; for test_case in test_cases { let converted = analyze(&format!("{FIXTURE}{}", test_case.query)) @@ -81,6 +107,11 @@ fn given_a_raising_function_of_arguments_databricks_rejects_when_converted_then_ query: "SELECT assert_true(x1) AS r FROM input", expected_reason: "ASSERT_TRUE of (INT)", }, + RefuseTestCase { + description: "SEQUENCE of two STRING bounds, which Databricks rejects", + query: "SELECT sequence(s, s) AS r FROM input", + expected_reason: "SEQUENCE of (STRING, STRING)", + }, ]; for test_case in test_cases { let reason = analyze(&format!("{FIXTURE}{}", test_case.query)) diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_search.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_search.rs new file mode 100644 index 000000000..ab0a92152 --- /dev/null +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_search.rs @@ -0,0 +1,107 @@ +//! Databricks SEARCH and ISEARCH in substring mode, converted to DuckDB, and the ones refused. + +use crate::databricks::analysis::main::analyze::analyze; +use crate::databricks::conversion::models::DatabricksType; +use crate::databricks::conversion::tests::test_types::{ConvertTestCase, RefuseTestCase}; + +const FIXTURE: &str = "WITH input AS (SELECT * FROM VALUES (1, CAST(-7 AS INT), CAST('a' AS STRING)), \ + (2, CAST(NULL AS INT), CAST(NULL AS STRING)) AS input(ordinal, x1, s)) "; + +#[test] +fn given_search_in_substring_mode_when_converted_then_duckdb_tests_each_string_argument() { + let test_cases = [ + ConvertTestCase { + description: "SEARCH tests each STRING argument with an OR, skipping an INT and keeping a NULL", + query: "SELECT search(x1, s, NULL, 'a.b', mode => 'SUBSTRING') AS r FROM input", + expected_sql: &["(contains(\"s\", 'a.b') OR contains(NULL, 'a.b')) AS \"r\""], + expected_types: &[DatabricksType::Boolean], + }, + ConvertTestCase { + description: "SEARCH of only arguments it skips is FALSE, and of a NULL pattern NULL", + query: "SELECT search(x1, 'a') AS r, search(s, NULL) AS n FROM input", + expected_sql: &["FALSE AS \"r\"", "CAST(NULL AS BOOLEAN) AS \"n\""], + expected_types: &[DatabricksType::Boolean, DatabricksType::Boolean], + }, + ConvertTestCase { + description: "ISEARCH lowers both sides as UTF8_LCASE does, capital I with dot above and final sigma first", + query: "SELECT isearch(s, 'Ab') AS r FROM input", + expected_sql: &[ + "contains((CASE WHEN regexp_matches(replace(replace(\"s\", '\u{130}', 'i\u{307}'), '\u{3c2}', '\u{3c3}'), ", + "ELSE lower(replace(replace(\"s\", '\u{130}', 'i\u{307}'), '\u{3c2}', '\u{3c3}')) END), lower(replace(replace('Ab', ", + ], + expected_types: &[DatabricksType::Boolean], + }, + ConvertTestCase { + description: "ISEARCH raises for a target holding capital I with dot above where the pattern could match half its lower case", + query: "SELECT isearch(s, 'xI') AS r, isearch(s, '\u{307}x') AS d, isearch(s, 'İ') AS w FROM input", + expected_sql: &[ + "(CASE WHEN contains(\"s\", '\u{130}') THEN CAST(error('no recording shows ISEARCH matching part of a capital I with dot above') AS BOOLEAN) ELSE contains(", + "END)) AS \"d\", (contains((CASE", + ], + expected_types: &[ + DatabricksType::Boolean, + DatabricksType::Boolean, + DatabricksType::Boolean, + ], + }, + ]; + for test_case in test_cases { + let converted = analyze(&format!("{FIXTURE}{}", test_case.query)) + .unwrap_or_else(|refusal| panic!("{}: {}", test_case.description, refusal.reason)); + for expected in test_case.expected_sql { + assert!( + converted.sql.contains(expected), + "{}: {}", + test_case.description, + converted.sql + ); + } + let types: Vec = converted + .columns + .iter() + .map(|(_, data_type)| *data_type) + .collect(); + assert_eq!(types, test_case.expected_types, "{}", test_case.description); + } +} + +#[test] +fn given_search_outside_substring_mode_or_a_constant_pattern_when_converted_then_it_is_refused() { + let test_cases = [ + RefuseTestCase { + description: "word mode, which splits at UAX #29 word boundaries", + query: "SELECT search(s, 'a', mode => 'word') AS r FROM input", + expected_reason: "in a mode other than substring", + }, + RefuseTestCase { + description: "a pattern read from a column", + query: "SELECT search(s, s) AS r FROM input", + expected_reason: "of a pattern other than a non-empty constant string", + }, + RefuseTestCase { + description: "an empty pattern, which no recording shows", + query: "SELECT isearch(s, '') AS r FROM input", + expected_reason: "of a pattern other than a non-empty constant string", + }, + RefuseTestCase { + description: "an array, whose strings Databricks searches", + query: "SELECT search(array(s), 'a') AS r FROM input", + expected_reason: "of an array or map", + }, + RefuseTestCase { + description: "a pattern alone", + query: "SELECT search('a') AS r FROM input", + expected_reason: "without a pattern and an expression to search", + }, + ]; + for test_case in test_cases { + let reason = analyze(&format!("{FIXTURE}{}", test_case.query)) + .expect_err(test_case.description) + .reason; + assert!( + reason.contains(test_case.expected_reason), + "{}: {reason}", + test_case.description + ); + } +} diff --git a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_vectors.rs b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_vectors.rs index 1ccf67f50..47af52624 100644 --- a/crates/sqlbabel-convert/src/databricks/conversion/tests/test_vectors.rs +++ b/crates/sqlbabel-convert/src/databricks/conversion/tests/test_vectors.rs @@ -9,25 +9,36 @@ const FIXTURE: &str = "WITH input AS (SELECT * FROM VALUES (1, CAST(-7 AS INT), #[test] fn given_vector_functions_when_converted_then_duckdb_computes_them_in_double_as_databricks_does() { - let test_cases = [ConvertTestCase { - description: "vector functions sum FLOAT products in DOUBLE in blocks of eight and narrow to FLOAT as Java does, raising for unequal dimensions before NULL for a NULL element, NULL for a zero norm", - query: "SELECT vector_inner_product(array(CAST(x1 AS FLOAT)), array(CAST(x1 AS FLOAT))) AS p, vector_norm(array(CAST(x1 AS FLOAT))) AS n, vector_cosine_similarity(array(CAST(x1 AS FLOAT)), array(CAST(x1 AS FLOAT))) AS c FROM input", - expected_sql: &[ - "CASE WHEN [CAST(\"x1\" AS FLOAT)] IS NULL OR [CAST(\"x1\" AS FLOAT)] IS NULL THEN NULL \ + let test_cases = [ + ConvertTestCase { + description: "VECTOR_L2_DISTANCE sums squared DOUBLE differences in blocks of eight and narrows the root to FLOAT", + query: "SELECT vector_l2_distance(array(CAST(x1 AS FLOAT)), array(CAST(1 AS FLOAT))) AS d FROM input", + expected_sql: &[ + "lambda element, slot: (element - (CAST([CAST(1 AS FLOAT)] AS DOUBLE[]))[slot]) * (element - (CAST([CAST(1 AS FLOAT)] AS DOUBLE[]))[slot])", + "WHEN len([CAST(\"x1\" AS FLOAT)]) <> len([CAST(1 AS FLOAT)]) THEN error('argument rejected: the vectors have different dimensions')", + ], + expected_types: &[DatabricksType::Float], + }, + ConvertTestCase { + description: "vector functions sum FLOAT products in DOUBLE in blocks of eight and narrow to FLOAT as Java does, raising for unequal dimensions before NULL for a NULL element, NULL for a zero norm", + query: "SELECT vector_inner_product(array(CAST(x1 AS FLOAT)), array(CAST(x1 AS FLOAT))) AS p, vector_norm(array(CAST(x1 AS FLOAT))) AS n, vector_cosine_similarity(array(CAST(x1 AS FLOAT)), array(CAST(x1 AS FLOAT))) AS c FROM input", + expected_sql: &[ + "CASE WHEN [CAST(\"x1\" AS FLOAT)] IS NULL OR [CAST(\"x1\" AS FLOAT)] IS NULL THEN NULL \ WHEN len([CAST(\"x1\" AS FLOAT)]) <> len([CAST(\"x1\" AS FLOAT)]) THEN error('argument rejected: the vectors have different dimensions') \ WHEN list_count([CAST(\"x1\" AS FLOAT)]) < len([CAST(\"x1\" AS FLOAT)]) OR", - "lambda element: list_reduce(list_concat(list_transform(range(0, len(element) // 8), \ + "lambda element: list_reduce(list_concat(list_transform(range(0, len(element) // 8), \ lambda slot: element[8 * slot + 1] + element[8 * slot + 2]", - "lambda total: (CASE WHEN isfinite(total) AND abs(total) >= 3.4028235677973366e38", - "lambda element: CASE WHEN sqrt(element[2] * element[3]) = 0 THEN NULL \ + "lambda total: (CASE WHEN isfinite(total) AND abs(total) >= 3.4028235677973366e38", + "lambda element: CASE WHEN sqrt(element[2] * element[3]) = 0 THEN NULL \ ELSE CAST(element[1] / sqrt(element[2] * element[3]) AS FLOAT) END)[1] END AS \"c\"", - ], - expected_types: &[ - DatabricksType::Float, - DatabricksType::Float, - DatabricksType::Float, - ], - }]; + ], + expected_types: &[ + DatabricksType::Float, + DatabricksType::Float, + DatabricksType::Float, + ], + }, + ]; for test_case in test_cases { let converted = analyze(&format!("{FIXTURE}{}", test_case.query)) .unwrap_or_else(|refusal| panic!("{}: {}", test_case.description, refusal.reason)); @@ -57,9 +68,9 @@ fn given_a_vector_function_no_recording_shows_when_converted_then_it_is_refused( expected_reason: "outside its rewrite", }, RefuseTestCase { - description: "VECTOR_L2_DISTANCE, whose FLOAT or DOUBLE subtraction no recording shows", - query: "SELECT vector_l2_distance(array(CAST(x1 AS FLOAT)), array(CAST(x1 AS FLOAT))) AS d FROM input", - expected_reason: "VECTOR_L2_DISTANCE", + description: "VECTOR_NORMALIZE, whose FLOAT array result no recording shows DuckDB writing alike", + query: "SELECT vector_normalize(array(CAST(x1 AS FLOAT))) AS v FROM input", + expected_reason: "VECTOR_NORMALIZE", }, ]; for test_case in test_cases { diff --git a/crates/sqlbabel-evidence/src/databricks/profile/constants.rs b/crates/sqlbabel-evidence/src/databricks/profile/constants.rs index e7c4f525a..5c74311f1 100644 --- a/crates/sqlbabel-evidence/src/databricks/profile/constants.rs +++ b/crates/sqlbabel-evidence/src/databricks/profile/constants.rs @@ -65,6 +65,11 @@ pub const ERROR_CLASS_KINDS: &[(&str, ErrorKind)] = &[ ), ("DATETIME_FIELD_OUT_OF_BOUNDS", ErrorKind::InvalidArgument), ("INVALID_ARRAY_INDEX", ErrorKind::InvalidArgument), + ("INVALID_BITMAP_POSITION", ErrorKind::InvalidArgument), + ( + "COUNTER_DIFF_NEGATIVE_COUNTER_VALUE", + ErrorKind::InvalidArgument, + ), ("VECTOR_DIMENSION_MISMATCH", ErrorKind::InvalidArgument), ("INVALID_PARAMETER_VALUE", ErrorKind::InvalidArgument), ("CANNOT_DECODE_URL", ErrorKind::InvalidArgument), diff --git a/crates/sqlbabel-policy/policy-databricks.toml b/crates/sqlbabel-policy/policy-databricks.toml index 5a4d162a5..28dc38d27 100644 --- a/crates/sqlbabel-policy/policy-databricks.toml +++ b/crates/sqlbabel-policy/policy-databricks.toml @@ -328,15 +328,15 @@ default = "allow" failure = "loud" reason = "COLLECT_LIST and ARRAY_AGG return their non-NULL values in the order rows arrive, which neither engine defines. Passed straight into SIZE, CARDINALITY, ARRAY_SIZE, ARRAY_MAX, ARRAY_MIN, SORT_ARRAY or ARRAY_SORT without a comparator, whose results no order changes, the converted SQL returns the array unchecked; anywhere else it returns the array where it holds at most one distinct value, and raises otherwise. The failure is loud, never a wrong value." -# FIRST, FIRST_VALUE, LAST and LAST_VALUE as aggregates return the value of the first or last row -# to arrive, which neither engine defines. +# FIRST, FIRST_VALUE, LAST, LAST_VALUE and ANY_VALUE as aggregates return the value of the first +# or last row to arrive, which neither engine defines. [divergences.first_last_order] -constructs = ["fn:FIRST", "fn:FIRST_VALUE", "fn:LAST", "fn:LAST_VALUE"] +constructs = ["fn:FIRST", "fn:FIRST_VALUE", "fn:LAST", "fn:LAST_VALUE", "fn:ANY_VALUE"] replay = "warn" default = "allow" failure = "loud" -reason = "FIRST, FIRST_VALUE, LAST and LAST_VALUE as aggregates return the value of the first or last row to arrive, which neither engine defines. The converted SQL returns the value where every row of the group gives the same one, NULLs counted unless the second argument is TRUE, and raises otherwise. The failure is loud, never a wrong value." +reason = "FIRST, FIRST_VALUE, LAST, LAST_VALUE and ANY_VALUE as aggregates return the value of the first or last row to arrive, which neither engine defines. The converted SQL returns the value where every row of the group gives the same one, NULLs counted unless the second argument is TRUE, and raises otherwise. The failure is loud, never a wrong value." # MAX_BY and MIN_BY return the value of one of the rows tying on the ordering that decides the # result, which neither engine defines. diff --git a/crates/sqlbabel-policy/src/databricks/constants.rs b/crates/sqlbabel-policy/src/databricks/constants.rs index 67c803b8e..ade0cc571 100644 --- a/crates/sqlbabel-policy/src/databricks/constants.rs +++ b/crates/sqlbabel-policy/src/databricks/constants.rs @@ -125,7 +125,7 @@ pub const KNOWN_DIFFERENCES: &[KnownDifference] = &[ details: Some( "The converted SQL returns the value where every row of the group gives the same \ one. NULLs count as a value unless the second argument is TRUE, which skips them. \ - FIRST, FIRST_VALUE, LAST and LAST_VALUE without OVER are affected.", + FIRST, FIRST_VALUE, LAST, LAST_VALUE and ANY_VALUE without OVER are affected.", ), fine_when: "Every row of each group gives the same value.", wrong_when: "A group gives several values: DuckDB raises an error where Databricks \ diff --git a/crates/sqlbabel/src/statements/_helpers/spellings.rs b/crates/sqlbabel/src/statements/_helpers/spellings.rs index 721948a0c..d7d08579b 100644 --- a/crates/sqlbabel/src/statements/_helpers/spellings.rs +++ b/crates/sqlbabel/src/statements/_helpers/spellings.rs @@ -146,12 +146,14 @@ fn keyword_spelling(node: &Expression) -> Option { Some(format!("{SPELLING}{spelling}")) } -/// Databricks: the key of a clause a node holds besides its own key: an aggregate's FILTER, or a join hint. +/// Databricks: the key of a clause a node holds besides its own key: an aggregate's FILTER, an IN subquery, a window's written frame, or a join hint. fn clause_spelling(node: &Expression) -> Option<&'static str> { match node { Expression::AggregateFunction(function) if function.filter.is_some() => { Some("aggregate_filter") } + Expression::In(test) if test.query.is_some() => Some("in_subquery"), + Expression::WindowFunction(window) if window.over.frame.is_some() => Some("window_frame"), Expression::Select(select) => { let mut hints = select.hint.iter().flat_map(|hint| &hint.expressions); let joined = hints.any(|hint| { diff --git a/crates/sqlbabel/tests/cli/test_dialect.rs b/crates/sqlbabel/tests/cli/test_dialect.rs index a7917fce8..70cccc764 100644 --- a/crates/sqlbabel/tests/cli/test_dialect.rs +++ b/crates/sqlbabel/tests/cli/test_dialect.rs @@ -166,6 +166,61 @@ fn given_a_databricks_string_column_where_a_number_is_wanted_when_running_then_d } } +#[test] +fn given_databricks_decode_collations_positions_and_pipelines_when_running_then_duckdb_returns_the_recorded_values() + { + let test_cases = [ + ChainValueTestCase { + description: "DECODE with key and result pairs returns the default for a value no key matches", + sql: "WITH input AS (SELECT * FROM VALUES (CAST('c' AS STRING)) AS input(s)) SELECT decode(s, 'a', 'one', 'b', 'two', 'other') AS r FROM input", + expected_value: "Text(\"other\")", + }, + ChainValueTestCase { + description: "NOT IN a subquery holding NULL reads as false, as Databricks returns it", + sql: "WITH input AS (SELECT * FROM VALUES (CAST(1 AS INT)) AS input(x)) SELECT x NOT IN (SELECT y FROM VALUES (CAST(2 AS INT)), (CAST(NULL AS INT)) AS u(y)) AS r FROM input", + expected_value: "Boolean(false)", + }, + ChainValueTestCase { + description: "a comparison under COLLATE UTF8_BINARY tells the cases apart", + sql: "WITH input AS (SELECT * FROM VALUES (CAST('A' AS STRING)) AS input(s)) SELECT s COLLATE UTF8_BINARY = 'a' AS r FROM input", + expected_value: "Boolean(false)", + }, + ChainValueTestCase { + description: "GROUP BY 2 groups by the second output", + sql: "WITH input AS (SELECT * FROM VALUES (CAST('a' AS STRING)), (CAST('a' AS STRING)) AS input(s)) SELECT count(*) AS n, s FROM input GROUP BY 2", + expected_value: "BigInt(2)", + }, + ChainValueTestCase { + description: "a pipeline starting TABLE a relation filters its rows", + sql: "WITH input AS (SELECT * FROM VALUES (CAST(3 AS INT)), (CAST(-1 AS INT)) AS input(x1)) SELECT x1 FROM (TABLE input |> WHERE x1 > 0) AS q", + expected_value: "Int(3)", + }, + ChainValueTestCase { + description: "SEQUENCE reads a STRING start beside an INT stop as BIGINT, spaces trimmed", + sql: "WITH input AS (SELECT * FROM VALUES (CAST(' 2' AS STRING)) AS input(s)) SELECT size(sequence(s, 4)) AS r FROM input", + expected_value: "Int(3)", + }, + ChainValueTestCase { + description: "a DECIMAL cast to BIGINT truncates toward zero", + sql: "WITH input AS (SELECT * FROM VALUES (CAST(-3.75 AS DECIMAL(10,2))) AS input(d)) SELECT CAST(d AS BIGINT) AS r FROM input", + expected_value: "BigInt(-3)", + }, + ChainValueTestCase { + description: "VECTOR_L2_DISTANCE of two FLOAT vectors is the FLOAT root of the summed squared differences", + sql: "WITH input AS (SELECT * FROM VALUES (array(CAST(1 AS FLOAT), CAST(-2 AS FLOAT)), array(CAST(4 AS FLOAT), CAST(2 AS FLOAT))) AS input(a, b)) SELECT vector_l2_distance(a, b) AS r FROM input", + expected_value: "Float(5.0)", + }, + ]; + for test_case in test_cases { + assert_eq!( + databricks_column(test_case.sql).as_deref(), + Ok(test_case.expected_value), + "{}", + test_case.description + ); + } +} + #[test] fn given_ip_functions_over_columns_named_like_their_lambda_parameters_when_running_then_duckdb_reads_the_columns() { @@ -285,6 +340,11 @@ fn given_a_databricks_string_column_no_number_reads_when_running_then_duckdb_rai sql: "WITH input AS (SELECT * FROM VALUES (CAST('x' AS STRING)) AS input(s)) SELECT s + 1 AS r FROM input", expected_mention: "text rejected as a number", }, + RunErrorTestCase { + description: "SEQUENCE raises for a STRING bound holding a fraction, as Databricks's cast to BIGINT does", + sql: "WITH input AS (SELECT * FROM VALUES (CAST('3.5' AS STRING)) AS input(s)) SELECT size(sequence(s, 5)) AS r FROM input", + expected_mention: "text rejected as a number", + }, ]; for test_case in test_cases { let error = databricks_column(test_case.sql).err(); diff --git a/evidence.toml b/evidence.toml index f0b86c9c7..552b62ab2 100644 --- a/evidence.toml +++ b/evidence.toml @@ -1,4 +1,4 @@ # The evidence SQLBabel's checks read: one commit of the evidence repository, and the SHA-256 of its files. repository = "https://github.com/sqlstack-io/sqlbabel-evidence.git" -commit = "2de70829c03479c5e0fc4239006df229fc7af8fb" -content_sha256 = "135732dc3f1b5d1a30da0ad77f5033a6b03d5b45240f01633495a9f5d5747ac4" +commit = "7e6fdffaa6b83bb4b2025dc5ee1ba3262630b3db" +content_sha256 = "605793d7983fe62d995d777796c51a3587f12a808b24e2365e6443fe881ad826" diff --git a/website/src/content/docs/docs/cli/convert.mdx b/website/src/content/docs/docs/cli/convert.mdx index a34b5b317..758c86de4 100644 --- a/website/src/content/docs/docs/cli/convert.mdx +++ b/website/src/content/docs/docs/cli/convert.mdx @@ -101,7 +101,7 @@ $ echo "INSERT INTO orders VALUES (1, 2.50)" | sqlbabel convert --dialect databr error[SBL0002]: SQLBabel can't convert TABLE yet --> | - = note: `orders` is no table or view the case's statements define + = note: this script doesn't define the table or view `orders` sqlbabel convert: refused, 1 refusal ```