sqlglot.generators.singlestore
1from __future__ import annotations 2 3import re 4import typing as t 5 6from sqlglot import exp 7from sqlglot.dialects.dialect import ( 8 json_extract_segments, 9 json_path_key_only_name, 10 rename_func, 11 bool_xor_sql, 12 count_if_to_sum, 13 timestamptrunc_sql, 14 date_add_interval_sql, 15 timestampdiff_sql, 16) 17from sqlglot.expressions import DataType 18from sqlglot import generator 19from sqlglot.generator import unsupported_args 20from sqlglot.generators.mysql import MySQLGenerator, _remove_ts_or_ds_to_date, date_add_sql 21 22 23def _unicode_substitute(m: re.Match[str]) -> str: 24 return chr(int(m.group(1), 16)) 25 26 27class SingleStoreGenerator(MySQLGenerator): 28 SUPPORTS_UESCAPE = False 29 NULL_ORDERING_SUPPORTED: bool | None = True 30 MATCH_AGAINST_TABLE_PREFIX: str | None = "TABLE " 31 STRUCT_DELIMITER = ("(", ")") 32 33 UNICODE_SUBSTITUTE: t.ClassVar[t.Any] = staticmethod(_unicode_substitute) 34 35 SUPPORTED_JSON_PATH_PARTS = { 36 exp.JSONPathKey, 37 exp.JSONPathRoot, 38 exp.JSONPathSubscript, 39 } 40 41 TRANSFORMS = { 42 **{ 43 k: v 44 for k, v in MySQLGenerator.TRANSFORMS.items() 45 if k not in (exp.JSONExtractScalar, exp.CurrentDate) 46 }, 47 exp.TsOrDsToDate: lambda self, e: ( 48 self.func("TO_DATE", e.this, self.format_time(e)) 49 if e.args.get("format") 50 else self.func("DATE", e.this) 51 ), 52 exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)), 53 exp.ToChar: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)), 54 exp.StrToDate: lambda self, e: self.func( 55 "STR_TO_DATE", 56 e.this, 57 self.format_time( 58 e, 59 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 60 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 61 ), 62 ), 63 exp.TimeToStr: lambda self, e: self.func( 64 "DATE_FORMAT", 65 e.this, 66 self.format_time( 67 e, 68 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 69 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 70 ), 71 ), 72 exp.Date: unsupported_args("zone", "expressions")(rename_func("DATE")), 73 exp.Cast: unsupported_args("format", "action", "default")( 74 lambda self, e: f"{self.sql(e, 'this')} :> {self.sql(e, 'to')}" 75 ), 76 exp.TryCast: unsupported_args("format", "action", "default")( 77 lambda self, e: f"{self.sql(e, 'this')} !:> {self.sql(e, 'to')}" 78 ), 79 exp.CastToStrType: lambda self, e: self.sql( 80 exp.cast(e.this, DataType.build(e.args["to"].name)) 81 ), 82 exp.StrToUnix: unsupported_args("format")(rename_func("UNIX_TIMESTAMP")), 83 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), 84 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), 85 exp.UnixSeconds: rename_func("UNIX_TIMESTAMP"), 86 exp.UnixToStr: lambda self, e: self.func( 87 "FROM_UNIXTIME", 88 e.this, 89 self.format_time( 90 e, 91 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 92 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 93 ), 94 ), 95 exp.UnixToTime: unsupported_args("scale", "zone", "hours", "minutes")( 96 lambda self, e: self.func( 97 "FROM_UNIXTIME", 98 e.this, 99 self.format_time( 100 e, 101 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 102 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 103 ), 104 ), 105 ), 106 exp.UnixToTimeStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}) :> TEXT", 107 exp.DateBin: unsupported_args("unit", "zone")( 108 lambda self, e: self.func("TIME_BUCKET", e.this, e.expression, e.args.get("origin")) 109 ), 110 exp.TimeStrToDate: lambda self, e: self.sql(exp.cast(e.this, exp.DType.DATE)), 111 exp.FromTimeZone: lambda self, e: self.func( 112 "CONVERT_TZ", e.this, e.args.get("zone"), "'UTC'" 113 ), 114 exp.DiToDate: lambda self, e: ( 115 f"STR_TO_DATE({self.sql(e, 'this')}, {self.dialect.DATEINT_FORMAT})" 116 ), 117 exp.DateToDi: lambda self, e: ( 118 f"(DATE_FORMAT({self.sql(e, 'this')}, {self.dialect.DATEINT_FORMAT}) :> INT)" 119 ), 120 exp.TsOrDiToDi: lambda self, e: ( 121 f"(DATE_FORMAT({self.sql(e, 'this')}, {self.dialect.DATEINT_FORMAT}) :> INT)" 122 ), 123 exp.Time: unsupported_args("zone")(lambda self, e: f"{self.sql(e, 'this')} :> TIME"), 124 exp.DatetimeAdd: _remove_ts_or_ds_to_date(date_add_sql("ADD")), 125 exp.DatetimeTrunc: unsupported_args("zone")(timestamptrunc_sql()), 126 exp.DatetimeSub: date_add_interval_sql("DATE", "SUB"), 127 exp.DatetimeDiff: timestampdiff_sql, 128 exp.DateTrunc: unsupported_args("zone")(timestamptrunc_sql()), 129 exp.DateDiff: unsupported_args("zone")( 130 lambda self, e: ( 131 timestampdiff_sql(self, e) 132 if e.unit is not None 133 else self.func("DATEDIFF", e.this, e.expression) 134 ) 135 ), 136 exp.TsOrDsDiff: lambda self, e: ( 137 timestampdiff_sql(self, e) 138 if e.unit is not None 139 else self.func("DATEDIFF", e.this, e.expression) 140 ), 141 exp.TimestampTrunc: unsupported_args("zone")(timestamptrunc_sql()), 142 exp.CurrentDatetime: lambda self, e: self.sql( 143 self.dialect.CAST_TO_TIME6( 144 exp.CurrentTimestamp(this=exp.Literal.number(6)), exp.DType.DATETIME 145 ) 146 ), 147 exp.JSONExtract: unsupported_args( 148 "only_json_types", 149 "expressions", 150 "variant_extract", 151 "json_query", 152 "option", 153 "quote", 154 "on_condition", 155 "requires_json", 156 )(json_extract_segments("JSON_EXTRACT_JSON")), 157 exp.JSONBExtract: json_extract_segments("BSON_EXTRACT_BSON"), 158 exp.JSONPathKey: json_path_key_only_name, 159 exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this), 160 exp.JSONPathRoot: lambda *_: "", 161 exp.JSONFormat: unsupported_args("options", "is_json")(rename_func("JSON_PRETTY")), 162 exp.JSONArrayAgg: unsupported_args("null_handling", "return_type", "strict")( 163 lambda self, e: self.func("JSON_AGG", e.this, suffix=f"{self.sql(e, 'order')})") 164 ), 165 exp.JSONArray: unsupported_args("null_handling", "return_type", "strict")( 166 rename_func("JSON_BUILD_ARRAY") 167 ), 168 exp.JSONBExists: lambda self, e: self.func( 169 "BSON_MATCH_ANY_EXISTS", e.this, e.args.get("path") 170 ), 171 exp.JSONExists: lambda self, e: ( 172 f"{self.sql(e.this)}::?{self.sql(e.args.get('path'))}" 173 if e.args.get("from_dcolonqmark") 174 else self.func("JSON_MATCH_ANY_EXISTS", e.this, e.args.get("path")) 175 ), 176 exp.JSONObject: unsupported_args("null_handling", "unique_keys", "return_type", "encoding")( 177 rename_func("JSON_BUILD_OBJECT") 178 ), 179 exp.DayOfWeekIso: lambda self, e: f"(({self.func('DAYOFWEEK', e.this)} % 7) + 1)", 180 exp.DayOfMonth: rename_func("DAY"), 181 exp.Hll: rename_func("APPROX_COUNT_DISTINCT"), 182 exp.ApproxDistinct: rename_func("APPROX_COUNT_DISTINCT"), 183 exp.CountIf: count_if_to_sum, 184 exp.LogicalOr: lambda self, e: f"MAX(ABS({self.sql(e, 'this')}))", 185 exp.LogicalAnd: lambda self, e: f"MIN(ABS({self.sql(e, 'this')}))", 186 exp.ApproxQuantile: unsupported_args("accuracy", "weight")( 187 lambda self, e: self.func( 188 "APPROX_PERCENTILE", 189 e.this, 190 e.args.get("quantile"), 191 e.args.get("error_tolerance"), 192 ) 193 ), 194 exp.Variance: rename_func("VAR_SAMP"), 195 exp.VariancePop: rename_func("VAR_POP"), 196 exp.Xor: bool_xor_sql, 197 exp.Cbrt: lambda self, e: self.sql( 198 exp.Pow(this=e.this, expression=exp.Literal.number(1) / exp.Literal.number(3)) 199 ), 200 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), 201 exp.Repeat: lambda self, e: self.func( 202 "LPAD", 203 exp.Literal.string(""), 204 exp.Mul(this=self.func("LENGTH", e.this), expression=e.args.get("times")), 205 e.this, 206 ), 207 exp.IsAscii: lambda self, e: f"({self.sql(e, 'this')} RLIKE '^[\x00-\x7f]*$')", 208 exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)), 209 exp.Contains: rename_func("INSTR"), 210 exp.RegexpExtractAll: unsupported_args("position", "occurrence", "group")( 211 lambda self, e: self.func( 212 "REGEXP_MATCH", 213 e.this, 214 e.expression, 215 e.args.get("parameters"), 216 ) 217 ), 218 exp.RegexpExtract: unsupported_args("group")( 219 lambda self, e: self.func( 220 "REGEXP_SUBSTR", 221 e.this, 222 e.expression, 223 e.args.get("position"), 224 e.args.get("occurrence"), 225 e.args.get("parameters"), 226 ) 227 ), 228 exp.StartsWith: lambda self, e: self.func( 229 "REGEXP_INSTR", e.this, self.func("CONCAT", exp.Literal.string("^"), e.expression) 230 ), 231 exp.FromBase: lambda self, e: self.func( 232 "CONV", e.this, e.expression, exp.Literal.number(10) 233 ), 234 exp.RegexpILike: lambda self, e: self.binary( 235 exp.RegexpLike( 236 this=exp.Lower(this=e.this), 237 expression=exp.Lower(this=e.expression), 238 ), 239 "RLIKE", 240 ), 241 exp.Stuff: lambda self, e: self.func( 242 "CONCAT", 243 self.func("SUBSTRING", e.this, exp.Literal.number(1), e.args.get("start") - 1), 244 e.expression, 245 self.func("SUBSTRING", e.this, e.args.get("start") + e.args.get("length")), 246 ), 247 exp.National: lambda self, e: self.national_sql(e, prefix=""), 248 exp.Reduce: unsupported_args("finish")( 249 lambda self, e: self.func("REDUCE", e.args.get("initial"), e.this, e.args.get("merge")) 250 ), 251 exp.MatchAgainst: unsupported_args("modifier")( 252 lambda self, e: generator.Generator.matchagainst_sql(self, e) 253 ), 254 exp.Show: unsupported_args( 255 "history", 256 "terse", 257 "offset", 258 "starts_with", 259 "limit", 260 "from_", 261 "scope", 262 "scope_kind", 263 "mutex", 264 "query", 265 "channel", 266 "log", 267 "types", 268 "privileges", 269 )(lambda self, e: MySQLGenerator.show_sql(self, e)), 270 exp.Describe: unsupported_args( 271 "style", 272 "kind", 273 "expressions", 274 "partition", 275 "format", 276 )(lambda self, e: generator.Generator.describe_sql(self, e)), 277 } 278 279 UNSUPPORTED_TYPES = { 280 exp.DType.ARRAY, 281 exp.DType.AGGREGATEFUNCTION, 282 exp.DType.SIMPLEAGGREGATEFUNCTION, 283 exp.DType.BIGSERIAL, 284 exp.DType.BPCHAR, 285 exp.DType.DATEMULTIRANGE, 286 exp.DType.DATERANGE, 287 exp.DType.DYNAMIC, 288 exp.DType.HLLSKETCH, 289 exp.DType.HSTORE, 290 exp.DType.IMAGE, 291 exp.DType.INET, 292 exp.DType.INT128, 293 exp.DType.INT256, 294 exp.DType.INT4MULTIRANGE, 295 exp.DType.INT4RANGE, 296 exp.DType.INT8MULTIRANGE, 297 exp.DType.INT8RANGE, 298 exp.DType.INTERVAL, 299 exp.DType.IPADDRESS, 300 exp.DType.IPPREFIX, 301 exp.DType.IPV4, 302 exp.DType.IPV6, 303 exp.DType.LIST, 304 exp.DType.MAP, 305 exp.DType.LOWCARDINALITY, 306 exp.DType.MONEY, 307 exp.DType.MULTILINESTRING, 308 exp.DType.NAME, 309 exp.DType.NESTED, 310 exp.DType.NOTHING, 311 exp.DType.NULL, 312 exp.DType.NUMMULTIRANGE, 313 exp.DType.NUMRANGE, 314 exp.DType.OBJECT, 315 exp.DType.RANGE, 316 exp.DType.ROWVERSION, 317 exp.DType.SERIAL, 318 exp.DType.SMALLSERIAL, 319 exp.DType.SMALLMONEY, 320 exp.DType.SUPER, 321 exp.DType.TIMETZ, 322 exp.DType.TIMESTAMPNTZ, 323 exp.DType.TIMESTAMPLTZ, 324 exp.DType.TIMESTAMPTZ, 325 exp.DType.TIMESTAMP_NS, 326 exp.DType.TSMULTIRANGE, 327 exp.DType.TSRANGE, 328 exp.DType.TSTZMULTIRANGE, 329 exp.DType.TSTZRANGE, 330 exp.DType.UINT128, 331 exp.DType.UINT256, 332 exp.DType.UNION, 333 exp.DType.UNKNOWN, 334 exp.DType.USERDEFINED, 335 exp.DType.UUID, 336 exp.DType.VARIANT, 337 exp.DType.XML, 338 exp.DType.TDIGEST, 339 } 340 341 TYPE_MAPPING = { 342 **MySQLGenerator.TYPE_MAPPING, 343 exp.DType.BIGDECIMAL: "DECIMAL", 344 exp.DType.BIT: "BOOLEAN", 345 exp.DType.DATE32: "DATE", 346 exp.DType.DATETIME64: "DATETIME", 347 exp.DType.DECIMAL32: "DECIMAL", 348 exp.DType.DECIMAL64: "DECIMAL", 349 exp.DType.DECIMAL128: "DECIMAL", 350 exp.DType.DECIMAL256: "DECIMAL", 351 exp.DType.ENUM8: "ENUM", 352 exp.DType.ENUM16: "ENUM", 353 exp.DType.FIXEDSTRING: "TEXT", 354 exp.DType.GEOMETRY: "GEOGRAPHY", 355 exp.DType.POINT: "GEOGRAPHYPOINT", 356 exp.DType.RING: "GEOGRAPHY", 357 exp.DType.LINESTRING: "GEOGRAPHY", 358 exp.DType.POLYGON: "GEOGRAPHY", 359 exp.DType.MULTIPOLYGON: "GEOGRAPHY", 360 exp.DType.STRUCT: "RECORD", 361 exp.DType.JSONB: "BSON", 362 exp.DType.TIMESTAMP: "TIMESTAMP", 363 exp.DType.TIMESTAMP_S: "TIMESTAMP", 364 exp.DType.TIMESTAMP_MS: "TIMESTAMP(6)", 365 } 366 367 # https://docs.singlestore.com/cloud/reference/sql-reference/restricted-keywords/list-of-restricted-keywords/ 368 RESERVED_KEYWORDS = { 369 "abs", 370 "absolute", 371 "access", 372 "account", 373 "acos", 374 "action", 375 "add", 376 "adddate", 377 "addtime", 378 "admin", 379 "aes_decrypt", 380 "aes_encrypt", 381 "after", 382 "against", 383 "aggregate", 384 "aggregates", 385 "aggregator", 386 "aggregator_id", 387 "aggregator_plan_hash", 388 "aggregators", 389 "algorithm", 390 "all", 391 "also", 392 "alter", 393 "always", 394 "analyse", 395 "analyze", 396 "and", 397 "anti_join", 398 "any", 399 "any_value", 400 "approx_count_distinct", 401 "approx_count_distinct_accumulate", 402 "approx_count_distinct_combine", 403 "approx_count_distinct_estimate", 404 "approx_geography_intersects", 405 "approx_percentile", 406 "arghistory", 407 "arrange", 408 "arrangement", 409 "array", 410 "as", 411 "asc", 412 "ascii", 413 "asensitive", 414 "asin", 415 "asm", 416 "assertion", 417 "assignment", 418 "ast", 419 "asymmetric", 420 "async", 421 "at", 422 "atan", 423 "atan2", 424 "attach", 425 "attribute", 426 "authorization", 427 "auto", 428 "auto_increment", 429 "auto_reprovision", 430 "autostats", 431 "autostats_cardinality_mode", 432 "autostats_enabled", 433 "autostats_histogram_mode", 434 "autostats_sampling", 435 "availability", 436 "avg", 437 "avg_row_length", 438 "avro", 439 "azure", 440 "background", 441 "_background_threads_for_cleanup", 442 "backup", 443 "backup_history", 444 "backup_id", 445 "backward", 446 "batch", 447 "batches", 448 "batch_interval", 449 "_batch_size_limit", 450 "before", 451 "begin", 452 "between", 453 "bigint", 454 "bin", 455 "binary", 456 "_binary", 457 "bit", 458 "bit_and", 459 "bit_count", 460 "bit_or", 461 "bit_xor", 462 "blob", 463 "bool", 464 "boolean", 465 "bootstrap", 466 "both", 467 "_bt", 468 "btree", 469 "bucket_count", 470 "by", 471 "byte", 472 "byte_length", 473 "cache", 474 "call", 475 "call_for_pipeline", 476 "called", 477 "capture", 478 "cascade", 479 "cascaded", 480 "case", 481 "cast", 482 "catalog", 483 "ceil", 484 "ceiling", 485 "chain", 486 "change", 487 "char", 488 "character", 489 "characteristics", 490 "character_length", 491 "char_length", 492 "charset", 493 "check", 494 "checkpoint", 495 "_check_can_connect", 496 "_check_consistency", 497 "checksum", 498 "_checksum", 499 "class", 500 "clear", 501 "client", 502 "client_found_rows", 503 "close", 504 "cluster", 505 "clustered", 506 "cnf", 507 "coalesce", 508 "coercibility", 509 "collate", 510 "collation", 511 "collect", 512 "column", 513 "columnar", 514 "columns", 515 "columnstore", 516 "columnstore_segment_rows", 517 "comment", 518 "comments", 519 "commit", 520 "committed", 521 "_commit_log_tail", 522 "committed", 523 "compact", 524 "compile", 525 "compressed", 526 "compression", 527 "concat", 528 "concat_ws", 529 "concurrent", 530 "concurrently", 531 "condition", 532 "configuration", 533 "connection", 534 "connection_id", 535 "connections", 536 "config", 537 "constraint", 538 "constraints", 539 "content", 540 "continue", 541 "_continue_replay", 542 "conv", 543 "conversion", 544 "convert", 545 "convert_tz", 546 "copy", 547 "_core", 548 "cos", 549 "cost", 550 "cot", 551 "count", 552 "create", 553 "credentials", 554 "cross", 555 "cube", 556 "csv", 557 "cume_dist", 558 "curdate", 559 "current", 560 "current_catalog", 561 "current_date", 562 "current_role", 563 "current_schema", 564 "current_security_groups", 565 "current_security_roles", 566 "current_time", 567 "current_timestamp", 568 "current_user", 569 "cursor", 570 "curtime", 571 "cycle", 572 "data", 573 "database", 574 "databases", 575 "date", 576 "date_add", 577 "datediff", 578 "date_format", 579 "date_sub", 580 "date_trunc", 581 "datetime", 582 "day", 583 "day_hour", 584 "day_microsecond", 585 "day_minute", 586 "dayname", 587 "dayofmonth", 588 "dayofweek", 589 "dayofyear", 590 "day_second", 591 "deallocate", 592 "dec", 593 "decimal", 594 "declare", 595 "decode", 596 "default", 597 "defaults", 598 "deferrable", 599 "deferred", 600 "defined", 601 "definer", 602 "degrees", 603 "delayed", 604 "delay_key_write", 605 "delete", 606 "delimiter", 607 "delimiters", 608 "dense_rank", 609 "desc", 610 "describe", 611 "detach", 612 "deterministic", 613 "dictionary", 614 "differential", 615 "directory", 616 "disable", 617 "discard", 618 "_disconnect", 619 "disk", 620 "distinct", 621 "distinctrow", 622 "distributed_joins", 623 "div", 624 "do", 625 "document", 626 "domain", 627 "dot_product", 628 "double", 629 "drop", 630 "_drop_profile", 631 "dual", 632 "dump", 633 "duplicate", 634 "dynamic", 635 "earliest", 636 "each", 637 "echo", 638 "election", 639 "else", 640 "elseif", 641 "elt", 642 "enable", 643 "enclosed", 644 "encoding", 645 "encrypted", 646 "end", 647 "engine", 648 "engines", 649 "enum", 650 "errors", 651 "escape", 652 "escaped", 653 "estimate", 654 "euclidean_distance", 655 "event", 656 "events", 657 "except", 658 "exclude", 659 "excluding", 660 "exclusive", 661 "execute", 662 "exists", 663 "exit", 664 "exp", 665 "explain", 666 "extended", 667 "extension", 668 "external", 669 "external_host", 670 "external_port", 671 "extract", 672 "extractor", 673 "extractors", 674 "extra_join", 675 "_failover", 676 "failed_login_attempts", 677 "failure", 678 "false", 679 "family", 680 "fault", 681 "fetch", 682 "field", 683 "fields", 684 "file", 685 "files", 686 "fill", 687 "first", 688 "first_value", 689 "fix_alter", 690 "fixed", 691 "float", 692 "float4", 693 "float8", 694 "floor", 695 "flush", 696 "following", 697 "for", 698 "force", 699 "force_compiled_mode", 700 "force_interpreter_mode", 701 "foreground", 702 "foreign", 703 "format", 704 "forward", 705 "found_rows", 706 "freeze", 707 "from", 708 "from_base64", 709 "from_days", 710 "from_unixtime", 711 "fs", 712 "_fsync", 713 "full", 714 "fulltext", 715 "function", 716 "functions", 717 "gc", 718 "gcs", 719 "get_format", 720 "_gc", 721 "_gcx", 722 "generate", 723 "geography", 724 "geography_area", 725 "geography_contains", 726 "geography_distance", 727 "geography_intersects", 728 "geography_latitude", 729 "geography_length", 730 "geography_longitude", 731 "geographypoint", 732 "geography_point", 733 "geography_within_distance", 734 "geometry", 735 "geometry_area", 736 "geometry_contains", 737 "geometry_distance", 738 "geometry_filter", 739 "geometry_intersects", 740 "geometry_length", 741 "geometrypoint", 742 "geometry_point", 743 "geometry_within_distance", 744 "geometry_x", 745 "geometry_y", 746 "global", 747 "_global_version_timestamp", 748 "grant", 749 "granted", 750 "grants", 751 "greatest", 752 "group", 753 "grouping", 754 "groups", 755 "group_concat", 756 "gzip", 757 "handle", 758 "handler", 759 "hard_cpu_limit_percentage", 760 "hash", 761 "has_temp_tables", 762 "having", 763 "hdfs", 764 "header", 765 "heartbeat_no_logging", 766 "hex", 767 "highlight", 768 "high_priority", 769 "hold", 770 "holding", 771 "host", 772 "hosts", 773 "hour", 774 "hour_microsecond", 775 "hour_minute", 776 "hour_second", 777 "identified", 778 "identity", 779 "if", 780 "ifnull", 781 "ignore", 782 "ilike", 783 "immediate", 784 "immutable", 785 "implicit", 786 "import", 787 "in", 788 "including", 789 "increment", 790 "incremental", 791 "index", 792 "indexes", 793 "inet_aton", 794 "inet_ntoa", 795 "inet6_aton", 796 "inet6_ntoa", 797 "infile", 798 "inherit", 799 "inherits", 800 "_init_profile", 801 "init", 802 "initcap", 803 "initialize", 804 "initially", 805 "inject", 806 "inline", 807 "inner", 808 "inout", 809 "input", 810 "insensitive", 811 "insert", 812 "insert_method", 813 "instance", 814 "instead", 815 "instr", 816 "int", 817 "int1", 818 "int2", 819 "int3", 820 "int4", 821 "int8", 822 "integer", 823 "_internal_dynamic_typecast", 824 "interpreter_mode", 825 "intersect", 826 "interval", 827 "into", 828 "invoker", 829 "is", 830 "isnull", 831 "isolation", 832 "iterate", 833 "join", 834 "json", 835 "json_agg", 836 "json_array_contains_double", 837 "json_array_contains_json", 838 "json_array_contains_string", 839 "json_array_push_double", 840 "json_array_push_json", 841 "json_array_push_string", 842 "json_delete_key", 843 "json_extract_double", 844 "json_extract_json", 845 "json_extract_string", 846 "json_extract_bigint", 847 "json_get_type", 848 "json_length", 849 "json_set_double", 850 "json_set_json", 851 "json_set_string", 852 "json_splice_double", 853 "json_splice_json", 854 "json_splice_string", 855 "kafka", 856 "key", 857 "key_block_size", 858 "keys", 859 "kill", 860 "killall", 861 "label", 862 "lag", 863 "language", 864 "large", 865 "last", 866 "last_day", 867 "last_insert_id", 868 "last_value", 869 "lateral", 870 "latest", 871 "lc_collate", 872 "lc_ctype", 873 "lcase", 874 "lead", 875 "leading", 876 "leaf", 877 "leakproof", 878 "least", 879 "leave", 880 "leaves", 881 "left", 882 "length", 883 "level", 884 "license", 885 "like", 886 "limit", 887 "lines", 888 "listen", 889 "llvm", 890 "ln", 891 "load", 892 "loaddata_where", 893 "_load", 894 "local", 895 "localtime", 896 "localtimestamp", 897 "locate", 898 "location", 899 "lock", 900 "log", 901 "log10", 902 "log2", 903 "long", 904 "longblob", 905 "longtext", 906 "loop", 907 "lower", 908 "low_priority", 909 "lpad", 910 "_ls", 911 "ltrim", 912 "lz4", 913 "management", 914 "_management_thread", 915 "mapping", 916 "master", 917 "match", 918 "materialized", 919 "max", 920 "maxvalue", 921 "max_concurrency", 922 "max_errors", 923 "max_partitions_per_batch", 924 "max_queue_depth", 925 "max_retries_per_batch_partition", 926 "max_rows", 927 "mbc", 928 "md5", 929 "mpl", 930 "median", 931 "mediumblob", 932 "mediumint", 933 "mediumtext", 934 "member", 935 "memory", 936 "memory_percentage", 937 "_memsql_table_id_lookup", 938 "memsql", 939 "memsql_deserialize", 940 "memsql_imitating_kafka", 941 "memsql_serialize", 942 "merge", 943 "metadata", 944 "microsecond", 945 "middleint", 946 "min", 947 "min_rows", 948 "minus", 949 "minute", 950 "minute_microsecond", 951 "minute_second", 952 "minvalue", 953 "mod", 954 "mode", 955 "model", 956 "modifies", 957 "modify", 958 "month", 959 "monthname", 960 "months_between", 961 "move", 962 "mpl", 963 "names", 964 "named", 965 "namespace", 966 "national", 967 "natural", 968 "nchar", 969 "next", 970 "no", 971 "node", 972 "none", 973 "no_query_rewrite", 974 "noparam", 975 "not", 976 "nothing", 977 "notify", 978 "now", 979 "nowait", 980 "no_write_to_binlog", 981 "no_query_rewrite", 982 "norely", 983 "nth_value", 984 "ntile", 985 "null", 986 "nullcols", 987 "nullif", 988 "nulls", 989 "numeric", 990 "nvarchar", 991 "object", 992 "octet_length", 993 "of", 994 "off", 995 "offline", 996 "offset", 997 "offsets", 998 "oids", 999 "on", 1000 "online", 1001 "only", 1002 "open", 1003 "operator", 1004 "optimization", 1005 "optimize", 1006 "optimizer", 1007 "optimizer_state", 1008 "option", 1009 "options", 1010 "optionally", 1011 "or", 1012 "order", 1013 "ordered_serialize", 1014 "orphan", 1015 "out", 1016 "out_of_order", 1017 "outer", 1018 "outfile", 1019 "over", 1020 "overlaps", 1021 "overlay", 1022 "owned", 1023 "owner", 1024 "pack_keys", 1025 "paired", 1026 "parser", 1027 "parquet", 1028 "partial", 1029 "partition", 1030 "partition_id", 1031 "partitioning", 1032 "partitions", 1033 "passing", 1034 "password", 1035 "password_lock_time", 1036 "parser", 1037 "pause", 1038 "_pause_replay", 1039 "percent_rank", 1040 "percentile_cont", 1041 "percentile_disc", 1042 "periodic", 1043 "persisted", 1044 "pi", 1045 "pipeline", 1046 "pipelines", 1047 "pivot", 1048 "placing", 1049 "plan", 1050 "plans", 1051 "plancache", 1052 "plugins", 1053 "pool", 1054 "pools", 1055 "port", 1056 "position", 1057 "pow", 1058 "power", 1059 "preceding", 1060 "precision", 1061 "prepare", 1062 "prepared", 1063 "preserve", 1064 "primary", 1065 "prior", 1066 "privileges", 1067 "procedural", 1068 "procedure", 1069 "procedures", 1070 "process", 1071 "processlist", 1072 "profile", 1073 "profiles", 1074 "program", 1075 "promote", 1076 "proxy", 1077 "purge", 1078 "quarter", 1079 "queries", 1080 "query", 1081 "query_timeout", 1082 "queue", 1083 "quote", 1084 "radians", 1085 "rand", 1086 "range", 1087 "rank", 1088 "read", 1089 "_read", 1090 "reads", 1091 "real", 1092 "reassign", 1093 "rebalance", 1094 "recheck", 1095 "record", 1096 "recursive", 1097 "redundancy", 1098 "redundant", 1099 "ref", 1100 "reference", 1101 "references", 1102 "refresh", 1103 "regexp", 1104 "reindex", 1105 "relative", 1106 "release", 1107 "reload", 1108 "rely", 1109 "remote", 1110 "remove", 1111 "rename", 1112 "repair", 1113 "_repair_table", 1114 "repeat", 1115 "repeatable", 1116 "_repl", 1117 "_reprovisioning", 1118 "replace", 1119 "replica", 1120 "replicate", 1121 "replicating", 1122 "replication", 1123 "durability", 1124 "require", 1125 "resource", 1126 "resource_pool", 1127 "reset", 1128 "restart", 1129 "restore", 1130 "restrict", 1131 "result", 1132 "_resurrect", 1133 "retry", 1134 "return", 1135 "returning", 1136 "returns", 1137 "reverse", 1138 "revoke", 1139 "rg_pool", 1140 "right", 1141 "right_anti_join", 1142 "right_semi_join", 1143 "right_straight_join", 1144 "rlike", 1145 "role", 1146 "roles", 1147 "rollback", 1148 "rollup", 1149 "round", 1150 "routine", 1151 "row", 1152 "row_count", 1153 "row_format", 1154 "row_number", 1155 "rows", 1156 "rowstore", 1157 "rule", 1158 "rpad", 1159 "_rpc", 1160 "rtrim", 1161 "running", 1162 "s3", 1163 "safe", 1164 "save", 1165 "savepoint", 1166 "scalar", 1167 "schema", 1168 "schemas", 1169 "schema_binding", 1170 "scroll", 1171 "search", 1172 "second", 1173 "second_microsecond", 1174 "sec_to_time", 1175 "security", 1176 "select", 1177 "semi_join", 1178 "_send_threads", 1179 "sensitive", 1180 "separator", 1181 "sequence", 1182 "sequences", 1183 "serial", 1184 "serializable", 1185 "series", 1186 "service_user", 1187 "server", 1188 "session", 1189 "session_user", 1190 "set", 1191 "setof", 1192 "security_lists_intersect", 1193 "sha", 1194 "sha1", 1195 "sha2", 1196 "shard", 1197 "sharded", 1198 "sharded_id", 1199 "share", 1200 "show", 1201 "shutdown", 1202 "sigmoid", 1203 "sign", 1204 "signal", 1205 "similar", 1206 "simple", 1207 "site", 1208 "signed", 1209 "sin", 1210 "skip", 1211 "skipped_batches", 1212 "sleep", 1213 "_sleep", 1214 "smallint", 1215 "snapshot", 1216 "_snapshot", 1217 "_snapshots", 1218 "soft_cpu_limit_percentage", 1219 "some", 1220 "soname", 1221 "sparse", 1222 "spatial", 1223 "spatial_check_index", 1224 "specific", 1225 "split", 1226 "sql", 1227 "sql_big_result", 1228 "sql_buffer_result", 1229 "sql_cache", 1230 "sql_calc_found_rows", 1231 "sqlexception", 1232 "sql_mode", 1233 "sql_no_cache", 1234 "sql_no_logging", 1235 "sql_small_result", 1236 "sqlstate", 1237 "sqlwarning", 1238 "sqrt", 1239 "ssl", 1240 "stable", 1241 "standalone", 1242 "start", 1243 "starting", 1244 "state", 1245 "statement", 1246 "statistics", 1247 "stats", 1248 "status", 1249 "std", 1250 "stddev", 1251 "stddev_pop", 1252 "stddev_samp", 1253 "stdin", 1254 "stdout", 1255 "stop", 1256 "storage", 1257 "str_to_date", 1258 "straight_join", 1259 "strict", 1260 "string", 1261 "strip", 1262 "subdate", 1263 "substr", 1264 "substring", 1265 "substring_index", 1266 "success", 1267 "sum", 1268 "super", 1269 "symmetric", 1270 "sync_snapshot", 1271 "sync", 1272 "_sync", 1273 "_sync2", 1274 "_sync_partitions", 1275 "_sync_snapshot", 1276 "synchronize", 1277 "sysid", 1278 "system", 1279 "table", 1280 "table_checksum", 1281 "tables", 1282 "tablespace", 1283 "tags", 1284 "tan", 1285 "target_size", 1286 "task", 1287 "temp", 1288 "template", 1289 "temporary", 1290 "temptable", 1291 "_term_bump", 1292 "terminate", 1293 "terminated", 1294 "test", 1295 "text", 1296 "then", 1297 "time", 1298 "timediff", 1299 "time_bucket", 1300 "time_format", 1301 "timeout", 1302 "timestamp", 1303 "timestampadd", 1304 "timestampdiff", 1305 "timezone", 1306 "time_to_sec", 1307 "tinyblob", 1308 "tinyint", 1309 "tinytext", 1310 "to", 1311 "to_base64", 1312 "to_char", 1313 "to_date", 1314 "to_days", 1315 "to_json", 1316 "to_number", 1317 "to_seconds", 1318 "to_timestamp", 1319 "tracelogs", 1320 "traditional", 1321 "trailing", 1322 "transform", 1323 "transaction", 1324 "_transactions_experimental", 1325 "treat", 1326 "trigger", 1327 "triggers", 1328 "trim", 1329 "true", 1330 "trunc", 1331 "truncate", 1332 "trusted", 1333 "two_phase", 1334 "_twopcid", 1335 "type", 1336 "types", 1337 "ucase", 1338 "unbounded", 1339 "uncommitted", 1340 "undefined", 1341 "undo", 1342 "unencrypted", 1343 "unenforced", 1344 "unhex", 1345 "unhold", 1346 "unicode", 1347 "union", 1348 "unique", 1349 "_unittest", 1350 "unix_timestamp", 1351 "unknown", 1352 "unlisten", 1353 "_unload", 1354 "unlock", 1355 "unlogged", 1356 "unpivot", 1357 "unsigned", 1358 "until", 1359 "update", 1360 "upgrade", 1361 "upper", 1362 "usage", 1363 "use", 1364 "user", 1365 "users", 1366 "using", 1367 "utc_date", 1368 "utc_time", 1369 "utc_timestamp", 1370 "_utf8", 1371 "vacuum", 1372 "valid", 1373 "validate", 1374 "validator", 1375 "value", 1376 "values", 1377 "varbinary", 1378 "varchar", 1379 "varcharacter", 1380 "variables", 1381 "variadic", 1382 "variance", 1383 "var_pop", 1384 "var_samp", 1385 "varying", 1386 "vector_sub", 1387 "verbose", 1388 "version", 1389 "view", 1390 "void", 1391 "volatile", 1392 "voting", 1393 "wait", 1394 "_wake", 1395 "warnings", 1396 "week", 1397 "weekday", 1398 "weekofyear", 1399 "when", 1400 "where", 1401 "while", 1402 "whitespace", 1403 "window", 1404 "with", 1405 "without", 1406 "within", 1407 "_wm_heartbeat", 1408 "work", 1409 "workload", 1410 "wrapper", 1411 "write", 1412 "xact_id", 1413 "xor", 1414 "year", 1415 "year_month", 1416 "yes", 1417 "zerofill", 1418 "zone", 1419 } 1420 1421 def jsonextractscalar_sql(self, expression: exp.JSONExtractScalar) -> str: 1422 json_type = expression.args.get("json_type") 1423 func_name = "JSON_EXTRACT_JSON" if json_type is None else f"JSON_EXTRACT_{json_type}" 1424 return json_extract_segments(func_name)(self, expression) 1425 1426 def jsonbextractscalar_sql(self, expression: exp.JSONBExtractScalar) -> str: 1427 json_type = expression.args.get("json_type") 1428 func_name = "BSON_EXTRACT_BSON" if json_type is None else f"BSON_EXTRACT_{json_type}" 1429 return json_extract_segments(func_name)(self, expression) 1430 1431 def jsonextractarray_sql(self, expression: exp.JSONExtractArray) -> str: 1432 self.unsupported("Arrays are not supported in SingleStore") 1433 return self.function_fallback_sql(expression) 1434 1435 def jsonvalue_sql(self, expression: exp.JSONValue) -> str: 1436 if expression.args.get("on_condition"): 1437 self.unsupported("JSON_VALUE does not support on_condition") 1438 res: exp.Expr = exp.JSONExtractScalar( 1439 this=expression.this, 1440 expression=expression.args.get("path"), 1441 json_type="STRING", 1442 ) 1443 1444 returning = expression.args.get("returning") 1445 if returning is not None: 1446 res = exp.Cast(this=res, to=returning) 1447 1448 return self.sql(res) 1449 1450 def all_sql(self, expression: exp.All) -> str: 1451 self.unsupported("ALL subquery predicate is not supported in SingleStore") 1452 return super().all_sql(expression) 1453 1454 def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str: 1455 json_type = expression.text("json_type").upper() 1456 1457 if json_type: 1458 return self.func( 1459 f"JSON_ARRAY_CONTAINS_{json_type}", expression.expression, expression.this 1460 ) 1461 1462 return self.func( 1463 "JSON_ARRAY_CONTAINS_JSON", 1464 expression.expression, 1465 self.func("TO_JSON", expression.this), 1466 ) 1467 1468 def datatype_sql(self, expression: exp.DataType) -> str: 1469 for arg_name in ("kind", "values"): 1470 if expression.args.get(arg_name): 1471 self.unsupported(f"DATATYPE does not support {arg_name}") 1472 if expression.args.get("nested") and not expression.is_type(exp.DType.STRUCT): 1473 self.unsupported( 1474 f"Argument 'nested' is not supported for representation of '{expression.this.value}' in SingleStore" 1475 ) 1476 1477 if expression.is_type(exp.DType.VARBINARY) and not expression.expressions: 1478 # `VARBINARY` must always have a size - if it doesn't, we always generate `BLOB` 1479 return "BLOB" 1480 if expression.is_type( 1481 exp.DType.DECIMAL32, 1482 exp.DType.DECIMAL64, 1483 exp.DType.DECIMAL128, 1484 exp.DType.DECIMAL256, 1485 ): 1486 scale = self.expressions(expression, flat=True) 1487 1488 if expression.is_type(exp.DType.DECIMAL32): 1489 precision = "9" 1490 elif expression.is_type(exp.DType.DECIMAL64): 1491 precision = "18" 1492 elif expression.is_type(exp.DType.DECIMAL128): 1493 precision = "38" 1494 else: 1495 # 65 is a maximum precision supported in SingleStore 1496 precision = "65" 1497 if scale is not None: 1498 return f"DECIMAL({precision}, {scale[0]})" 1499 else: 1500 return f"DECIMAL({precision})" 1501 if expression.is_type(exp.DType.VECTOR): 1502 expressions = expression.expressions 1503 if len(expressions) == 2: 1504 type_name = self.sql(expressions[0]) 1505 if type_name in self.dialect.INVERSE_VECTOR_TYPE_ALIASES: 1506 type_name = self.dialect.INVERSE_VECTOR_TYPE_ALIASES[type_name] 1507 1508 return f"VECTOR({self.sql(expressions[1])}, {type_name})" 1509 1510 return super().datatype_sql(expression) 1511 1512 def collate_sql(self, expression: exp.Collate) -> str: 1513 # SingleStore does not support setting a collation for column in the SELECT query, 1514 # so we cast column to a LONGTEXT type with specific collation 1515 return self.binary(expression, ":> LONGTEXT COLLATE") 1516 1517 def currentdate_sql(self, expression: exp.CurrentDate) -> str: 1518 timezone = expression.this 1519 if timezone: 1520 if isinstance(timezone, exp.Literal) and timezone.name.lower() == "utc": 1521 return self.func("UTC_DATE") 1522 self.unsupported("CurrentDate with timezone is not supported in SingleStore") 1523 1524 return self.func("CURRENT_DATE") 1525 1526 def currenttime_sql(self, expression: exp.CurrentTime) -> str: 1527 arg = expression.this 1528 if arg: 1529 if isinstance(arg, exp.Literal) and arg.name.lower() == "utc": 1530 return self.func("UTC_TIME") 1531 if isinstance(arg, exp.Literal) and arg.is_number: 1532 return self.func("CURRENT_TIME", arg) 1533 self.unsupported("CurrentTime with timezone is not supported in SingleStore") 1534 1535 return self.func("CURRENT_TIME") 1536 1537 def currenttimestamp_sql(self, expression: exp.CurrentTimestamp) -> str: 1538 arg = expression.this 1539 if arg: 1540 if isinstance(arg, exp.Literal) and arg.name.lower() == "utc": 1541 return self.func("UTC_TIMESTAMP") 1542 if isinstance(arg, exp.Literal) and arg.is_number: 1543 return self.func("CURRENT_TIMESTAMP", arg) 1544 self.unsupported("CurrentTimestamp with timezone is not supported in SingleStore") 1545 1546 return self.func("CURRENT_TIMESTAMP") 1547 1548 def standardhash_sql(self, expression: exp.StandardHash) -> str: 1549 hash_function = expression.expression 1550 if hash_function is None: 1551 return self.func("SHA", expression.this) 1552 if isinstance(hash_function, exp.Literal): 1553 if hash_function.name.lower() == "sha": 1554 return self.func("SHA", expression.this) 1555 if hash_function.name.lower() == "md5": 1556 return self.func("MD5", expression.this) 1557 1558 self.unsupported(f"{hash_function.this} hash method is not supported in SingleStore") 1559 return self.func("SHA", expression.this) 1560 1561 self.unsupported("STANDARD_HASH function is not supported in SingleStore") 1562 return self.func("SHA", expression.this) 1563 1564 def truncatetable_sql(self, expression: exp.TruncateTable) -> str: 1565 for arg_name in ("is_database", "exists", "cluster", "identity", "option", "partition"): 1566 if expression.args.get(arg_name): 1567 self.unsupported(f"TRUNCATE TABLE does not support {arg_name}") 1568 statements = [] 1569 for table in expression.expressions: 1570 statements.append(f"TRUNCATE {self.sql(table)}") 1571 1572 return "; ".join(statements) 1573 1574 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 1575 if expression.args.get("exists"): 1576 self.unsupported("RENAME COLUMN does not support exists") 1577 old_column = self.sql(expression, "this") 1578 new_column = self.sql(expression, "to") 1579 return f"CHANGE {old_column} {new_column}" 1580 1581 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 1582 for arg_name in ("drop", "comment", "allow_null", "visible", "using"): 1583 if expression.args.get(arg_name): 1584 self.unsupported(f"ALTER COLUMN does not support {arg_name}") 1585 alter = super().altercolumn_sql(expression) 1586 1587 collate = self.sql(expression, "collate") 1588 collate = f" COLLATE {collate}" if collate else "" 1589 return f"{alter}{collate}" 1590 1591 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 1592 this = self.sql(expression, "this") 1593 not_null = " NOT NULL" if expression.args.get("not_null") else "" 1594 type = self.sql(expression, "data_type") or "AUTO" 1595 return f"AS {this} PERSISTED {type}{not_null}"
28class SingleStoreGenerator(MySQLGenerator): 29 SUPPORTS_UESCAPE = False 30 NULL_ORDERING_SUPPORTED: bool | None = True 31 MATCH_AGAINST_TABLE_PREFIX: str | None = "TABLE " 32 STRUCT_DELIMITER = ("(", ")") 33 34 UNICODE_SUBSTITUTE: t.ClassVar[t.Any] = staticmethod(_unicode_substitute) 35 36 SUPPORTED_JSON_PATH_PARTS = { 37 exp.JSONPathKey, 38 exp.JSONPathRoot, 39 exp.JSONPathSubscript, 40 } 41 42 TRANSFORMS = { 43 **{ 44 k: v 45 for k, v in MySQLGenerator.TRANSFORMS.items() 46 if k not in (exp.JSONExtractScalar, exp.CurrentDate) 47 }, 48 exp.TsOrDsToDate: lambda self, e: ( 49 self.func("TO_DATE", e.this, self.format_time(e)) 50 if e.args.get("format") 51 else self.func("DATE", e.this) 52 ), 53 exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)), 54 exp.ToChar: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)), 55 exp.StrToDate: lambda self, e: self.func( 56 "STR_TO_DATE", 57 e.this, 58 self.format_time( 59 e, 60 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 61 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 62 ), 63 ), 64 exp.TimeToStr: lambda self, e: self.func( 65 "DATE_FORMAT", 66 e.this, 67 self.format_time( 68 e, 69 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 70 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 71 ), 72 ), 73 exp.Date: unsupported_args("zone", "expressions")(rename_func("DATE")), 74 exp.Cast: unsupported_args("format", "action", "default")( 75 lambda self, e: f"{self.sql(e, 'this')} :> {self.sql(e, 'to')}" 76 ), 77 exp.TryCast: unsupported_args("format", "action", "default")( 78 lambda self, e: f"{self.sql(e, 'this')} !:> {self.sql(e, 'to')}" 79 ), 80 exp.CastToStrType: lambda self, e: self.sql( 81 exp.cast(e.this, DataType.build(e.args["to"].name)) 82 ), 83 exp.StrToUnix: unsupported_args("format")(rename_func("UNIX_TIMESTAMP")), 84 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), 85 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), 86 exp.UnixSeconds: rename_func("UNIX_TIMESTAMP"), 87 exp.UnixToStr: lambda self, e: self.func( 88 "FROM_UNIXTIME", 89 e.this, 90 self.format_time( 91 e, 92 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 93 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 94 ), 95 ), 96 exp.UnixToTime: unsupported_args("scale", "zone", "hours", "minutes")( 97 lambda self, e: self.func( 98 "FROM_UNIXTIME", 99 e.this, 100 self.format_time( 101 e, 102 inverse_time_mapping=self.dialect.MYSQL_INVERSE_TIME_MAPPING, 103 inverse_time_trie=self.dialect.MYSQL_INVERSE_TIME_TRIE, 104 ), 105 ), 106 ), 107 exp.UnixToTimeStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}) :> TEXT", 108 exp.DateBin: unsupported_args("unit", "zone")( 109 lambda self, e: self.func("TIME_BUCKET", e.this, e.expression, e.args.get("origin")) 110 ), 111 exp.TimeStrToDate: lambda self, e: self.sql(exp.cast(e.this, exp.DType.DATE)), 112 exp.FromTimeZone: lambda self, e: self.func( 113 "CONVERT_TZ", e.this, e.args.get("zone"), "'UTC'" 114 ), 115 exp.DiToDate: lambda self, e: ( 116 f"STR_TO_DATE({self.sql(e, 'this')}, {self.dialect.DATEINT_FORMAT})" 117 ), 118 exp.DateToDi: lambda self, e: ( 119 f"(DATE_FORMAT({self.sql(e, 'this')}, {self.dialect.DATEINT_FORMAT}) :> INT)" 120 ), 121 exp.TsOrDiToDi: lambda self, e: ( 122 f"(DATE_FORMAT({self.sql(e, 'this')}, {self.dialect.DATEINT_FORMAT}) :> INT)" 123 ), 124 exp.Time: unsupported_args("zone")(lambda self, e: f"{self.sql(e, 'this')} :> TIME"), 125 exp.DatetimeAdd: _remove_ts_or_ds_to_date(date_add_sql("ADD")), 126 exp.DatetimeTrunc: unsupported_args("zone")(timestamptrunc_sql()), 127 exp.DatetimeSub: date_add_interval_sql("DATE", "SUB"), 128 exp.DatetimeDiff: timestampdiff_sql, 129 exp.DateTrunc: unsupported_args("zone")(timestamptrunc_sql()), 130 exp.DateDiff: unsupported_args("zone")( 131 lambda self, e: ( 132 timestampdiff_sql(self, e) 133 if e.unit is not None 134 else self.func("DATEDIFF", e.this, e.expression) 135 ) 136 ), 137 exp.TsOrDsDiff: lambda self, e: ( 138 timestampdiff_sql(self, e) 139 if e.unit is not None 140 else self.func("DATEDIFF", e.this, e.expression) 141 ), 142 exp.TimestampTrunc: unsupported_args("zone")(timestamptrunc_sql()), 143 exp.CurrentDatetime: lambda self, e: self.sql( 144 self.dialect.CAST_TO_TIME6( 145 exp.CurrentTimestamp(this=exp.Literal.number(6)), exp.DType.DATETIME 146 ) 147 ), 148 exp.JSONExtract: unsupported_args( 149 "only_json_types", 150 "expressions", 151 "variant_extract", 152 "json_query", 153 "option", 154 "quote", 155 "on_condition", 156 "requires_json", 157 )(json_extract_segments("JSON_EXTRACT_JSON")), 158 exp.JSONBExtract: json_extract_segments("BSON_EXTRACT_BSON"), 159 exp.JSONPathKey: json_path_key_only_name, 160 exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this), 161 exp.JSONPathRoot: lambda *_: "", 162 exp.JSONFormat: unsupported_args("options", "is_json")(rename_func("JSON_PRETTY")), 163 exp.JSONArrayAgg: unsupported_args("null_handling", "return_type", "strict")( 164 lambda self, e: self.func("JSON_AGG", e.this, suffix=f"{self.sql(e, 'order')})") 165 ), 166 exp.JSONArray: unsupported_args("null_handling", "return_type", "strict")( 167 rename_func("JSON_BUILD_ARRAY") 168 ), 169 exp.JSONBExists: lambda self, e: self.func( 170 "BSON_MATCH_ANY_EXISTS", e.this, e.args.get("path") 171 ), 172 exp.JSONExists: lambda self, e: ( 173 f"{self.sql(e.this)}::?{self.sql(e.args.get('path'))}" 174 if e.args.get("from_dcolonqmark") 175 else self.func("JSON_MATCH_ANY_EXISTS", e.this, e.args.get("path")) 176 ), 177 exp.JSONObject: unsupported_args("null_handling", "unique_keys", "return_type", "encoding")( 178 rename_func("JSON_BUILD_OBJECT") 179 ), 180 exp.DayOfWeekIso: lambda self, e: f"(({self.func('DAYOFWEEK', e.this)} % 7) + 1)", 181 exp.DayOfMonth: rename_func("DAY"), 182 exp.Hll: rename_func("APPROX_COUNT_DISTINCT"), 183 exp.ApproxDistinct: rename_func("APPROX_COUNT_DISTINCT"), 184 exp.CountIf: count_if_to_sum, 185 exp.LogicalOr: lambda self, e: f"MAX(ABS({self.sql(e, 'this')}))", 186 exp.LogicalAnd: lambda self, e: f"MIN(ABS({self.sql(e, 'this')}))", 187 exp.ApproxQuantile: unsupported_args("accuracy", "weight")( 188 lambda self, e: self.func( 189 "APPROX_PERCENTILE", 190 e.this, 191 e.args.get("quantile"), 192 e.args.get("error_tolerance"), 193 ) 194 ), 195 exp.Variance: rename_func("VAR_SAMP"), 196 exp.VariancePop: rename_func("VAR_POP"), 197 exp.Xor: bool_xor_sql, 198 exp.Cbrt: lambda self, e: self.sql( 199 exp.Pow(this=e.this, expression=exp.Literal.number(1) / exp.Literal.number(3)) 200 ), 201 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), 202 exp.Repeat: lambda self, e: self.func( 203 "LPAD", 204 exp.Literal.string(""), 205 exp.Mul(this=self.func("LENGTH", e.this), expression=e.args.get("times")), 206 e.this, 207 ), 208 exp.IsAscii: lambda self, e: f"({self.sql(e, 'this')} RLIKE '^[\x00-\x7f]*$')", 209 exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)), 210 exp.Contains: rename_func("INSTR"), 211 exp.RegexpExtractAll: unsupported_args("position", "occurrence", "group")( 212 lambda self, e: self.func( 213 "REGEXP_MATCH", 214 e.this, 215 e.expression, 216 e.args.get("parameters"), 217 ) 218 ), 219 exp.RegexpExtract: unsupported_args("group")( 220 lambda self, e: self.func( 221 "REGEXP_SUBSTR", 222 e.this, 223 e.expression, 224 e.args.get("position"), 225 e.args.get("occurrence"), 226 e.args.get("parameters"), 227 ) 228 ), 229 exp.StartsWith: lambda self, e: self.func( 230 "REGEXP_INSTR", e.this, self.func("CONCAT", exp.Literal.string("^"), e.expression) 231 ), 232 exp.FromBase: lambda self, e: self.func( 233 "CONV", e.this, e.expression, exp.Literal.number(10) 234 ), 235 exp.RegexpILike: lambda self, e: self.binary( 236 exp.RegexpLike( 237 this=exp.Lower(this=e.this), 238 expression=exp.Lower(this=e.expression), 239 ), 240 "RLIKE", 241 ), 242 exp.Stuff: lambda self, e: self.func( 243 "CONCAT", 244 self.func("SUBSTRING", e.this, exp.Literal.number(1), e.args.get("start") - 1), 245 e.expression, 246 self.func("SUBSTRING", e.this, e.args.get("start") + e.args.get("length")), 247 ), 248 exp.National: lambda self, e: self.national_sql(e, prefix=""), 249 exp.Reduce: unsupported_args("finish")( 250 lambda self, e: self.func("REDUCE", e.args.get("initial"), e.this, e.args.get("merge")) 251 ), 252 exp.MatchAgainst: unsupported_args("modifier")( 253 lambda self, e: generator.Generator.matchagainst_sql(self, e) 254 ), 255 exp.Show: unsupported_args( 256 "history", 257 "terse", 258 "offset", 259 "starts_with", 260 "limit", 261 "from_", 262 "scope", 263 "scope_kind", 264 "mutex", 265 "query", 266 "channel", 267 "log", 268 "types", 269 "privileges", 270 )(lambda self, e: MySQLGenerator.show_sql(self, e)), 271 exp.Describe: unsupported_args( 272 "style", 273 "kind", 274 "expressions", 275 "partition", 276 "format", 277 )(lambda self, e: generator.Generator.describe_sql(self, e)), 278 } 279 280 UNSUPPORTED_TYPES = { 281 exp.DType.ARRAY, 282 exp.DType.AGGREGATEFUNCTION, 283 exp.DType.SIMPLEAGGREGATEFUNCTION, 284 exp.DType.BIGSERIAL, 285 exp.DType.BPCHAR, 286 exp.DType.DATEMULTIRANGE, 287 exp.DType.DATERANGE, 288 exp.DType.DYNAMIC, 289 exp.DType.HLLSKETCH, 290 exp.DType.HSTORE, 291 exp.DType.IMAGE, 292 exp.DType.INET, 293 exp.DType.INT128, 294 exp.DType.INT256, 295 exp.DType.INT4MULTIRANGE, 296 exp.DType.INT4RANGE, 297 exp.DType.INT8MULTIRANGE, 298 exp.DType.INT8RANGE, 299 exp.DType.INTERVAL, 300 exp.DType.IPADDRESS, 301 exp.DType.IPPREFIX, 302 exp.DType.IPV4, 303 exp.DType.IPV6, 304 exp.DType.LIST, 305 exp.DType.MAP, 306 exp.DType.LOWCARDINALITY, 307 exp.DType.MONEY, 308 exp.DType.MULTILINESTRING, 309 exp.DType.NAME, 310 exp.DType.NESTED, 311 exp.DType.NOTHING, 312 exp.DType.NULL, 313 exp.DType.NUMMULTIRANGE, 314 exp.DType.NUMRANGE, 315 exp.DType.OBJECT, 316 exp.DType.RANGE, 317 exp.DType.ROWVERSION, 318 exp.DType.SERIAL, 319 exp.DType.SMALLSERIAL, 320 exp.DType.SMALLMONEY, 321 exp.DType.SUPER, 322 exp.DType.TIMETZ, 323 exp.DType.TIMESTAMPNTZ, 324 exp.DType.TIMESTAMPLTZ, 325 exp.DType.TIMESTAMPTZ, 326 exp.DType.TIMESTAMP_NS, 327 exp.DType.TSMULTIRANGE, 328 exp.DType.TSRANGE, 329 exp.DType.TSTZMULTIRANGE, 330 exp.DType.TSTZRANGE, 331 exp.DType.UINT128, 332 exp.DType.UINT256, 333 exp.DType.UNION, 334 exp.DType.UNKNOWN, 335 exp.DType.USERDEFINED, 336 exp.DType.UUID, 337 exp.DType.VARIANT, 338 exp.DType.XML, 339 exp.DType.TDIGEST, 340 } 341 342 TYPE_MAPPING = { 343 **MySQLGenerator.TYPE_MAPPING, 344 exp.DType.BIGDECIMAL: "DECIMAL", 345 exp.DType.BIT: "BOOLEAN", 346 exp.DType.DATE32: "DATE", 347 exp.DType.DATETIME64: "DATETIME", 348 exp.DType.DECIMAL32: "DECIMAL", 349 exp.DType.DECIMAL64: "DECIMAL", 350 exp.DType.DECIMAL128: "DECIMAL", 351 exp.DType.DECIMAL256: "DECIMAL", 352 exp.DType.ENUM8: "ENUM", 353 exp.DType.ENUM16: "ENUM", 354 exp.DType.FIXEDSTRING: "TEXT", 355 exp.DType.GEOMETRY: "GEOGRAPHY", 356 exp.DType.POINT: "GEOGRAPHYPOINT", 357 exp.DType.RING: "GEOGRAPHY", 358 exp.DType.LINESTRING: "GEOGRAPHY", 359 exp.DType.POLYGON: "GEOGRAPHY", 360 exp.DType.MULTIPOLYGON: "GEOGRAPHY", 361 exp.DType.STRUCT: "RECORD", 362 exp.DType.JSONB: "BSON", 363 exp.DType.TIMESTAMP: "TIMESTAMP", 364 exp.DType.TIMESTAMP_S: "TIMESTAMP", 365 exp.DType.TIMESTAMP_MS: "TIMESTAMP(6)", 366 } 367 368 # https://docs.singlestore.com/cloud/reference/sql-reference/restricted-keywords/list-of-restricted-keywords/ 369 RESERVED_KEYWORDS = { 370 "abs", 371 "absolute", 372 "access", 373 "account", 374 "acos", 375 "action", 376 "add", 377 "adddate", 378 "addtime", 379 "admin", 380 "aes_decrypt", 381 "aes_encrypt", 382 "after", 383 "against", 384 "aggregate", 385 "aggregates", 386 "aggregator", 387 "aggregator_id", 388 "aggregator_plan_hash", 389 "aggregators", 390 "algorithm", 391 "all", 392 "also", 393 "alter", 394 "always", 395 "analyse", 396 "analyze", 397 "and", 398 "anti_join", 399 "any", 400 "any_value", 401 "approx_count_distinct", 402 "approx_count_distinct_accumulate", 403 "approx_count_distinct_combine", 404 "approx_count_distinct_estimate", 405 "approx_geography_intersects", 406 "approx_percentile", 407 "arghistory", 408 "arrange", 409 "arrangement", 410 "array", 411 "as", 412 "asc", 413 "ascii", 414 "asensitive", 415 "asin", 416 "asm", 417 "assertion", 418 "assignment", 419 "ast", 420 "asymmetric", 421 "async", 422 "at", 423 "atan", 424 "atan2", 425 "attach", 426 "attribute", 427 "authorization", 428 "auto", 429 "auto_increment", 430 "auto_reprovision", 431 "autostats", 432 "autostats_cardinality_mode", 433 "autostats_enabled", 434 "autostats_histogram_mode", 435 "autostats_sampling", 436 "availability", 437 "avg", 438 "avg_row_length", 439 "avro", 440 "azure", 441 "background", 442 "_background_threads_for_cleanup", 443 "backup", 444 "backup_history", 445 "backup_id", 446 "backward", 447 "batch", 448 "batches", 449 "batch_interval", 450 "_batch_size_limit", 451 "before", 452 "begin", 453 "between", 454 "bigint", 455 "bin", 456 "binary", 457 "_binary", 458 "bit", 459 "bit_and", 460 "bit_count", 461 "bit_or", 462 "bit_xor", 463 "blob", 464 "bool", 465 "boolean", 466 "bootstrap", 467 "both", 468 "_bt", 469 "btree", 470 "bucket_count", 471 "by", 472 "byte", 473 "byte_length", 474 "cache", 475 "call", 476 "call_for_pipeline", 477 "called", 478 "capture", 479 "cascade", 480 "cascaded", 481 "case", 482 "cast", 483 "catalog", 484 "ceil", 485 "ceiling", 486 "chain", 487 "change", 488 "char", 489 "character", 490 "characteristics", 491 "character_length", 492 "char_length", 493 "charset", 494 "check", 495 "checkpoint", 496 "_check_can_connect", 497 "_check_consistency", 498 "checksum", 499 "_checksum", 500 "class", 501 "clear", 502 "client", 503 "client_found_rows", 504 "close", 505 "cluster", 506 "clustered", 507 "cnf", 508 "coalesce", 509 "coercibility", 510 "collate", 511 "collation", 512 "collect", 513 "column", 514 "columnar", 515 "columns", 516 "columnstore", 517 "columnstore_segment_rows", 518 "comment", 519 "comments", 520 "commit", 521 "committed", 522 "_commit_log_tail", 523 "committed", 524 "compact", 525 "compile", 526 "compressed", 527 "compression", 528 "concat", 529 "concat_ws", 530 "concurrent", 531 "concurrently", 532 "condition", 533 "configuration", 534 "connection", 535 "connection_id", 536 "connections", 537 "config", 538 "constraint", 539 "constraints", 540 "content", 541 "continue", 542 "_continue_replay", 543 "conv", 544 "conversion", 545 "convert", 546 "convert_tz", 547 "copy", 548 "_core", 549 "cos", 550 "cost", 551 "cot", 552 "count", 553 "create", 554 "credentials", 555 "cross", 556 "cube", 557 "csv", 558 "cume_dist", 559 "curdate", 560 "current", 561 "current_catalog", 562 "current_date", 563 "current_role", 564 "current_schema", 565 "current_security_groups", 566 "current_security_roles", 567 "current_time", 568 "current_timestamp", 569 "current_user", 570 "cursor", 571 "curtime", 572 "cycle", 573 "data", 574 "database", 575 "databases", 576 "date", 577 "date_add", 578 "datediff", 579 "date_format", 580 "date_sub", 581 "date_trunc", 582 "datetime", 583 "day", 584 "day_hour", 585 "day_microsecond", 586 "day_minute", 587 "dayname", 588 "dayofmonth", 589 "dayofweek", 590 "dayofyear", 591 "day_second", 592 "deallocate", 593 "dec", 594 "decimal", 595 "declare", 596 "decode", 597 "default", 598 "defaults", 599 "deferrable", 600 "deferred", 601 "defined", 602 "definer", 603 "degrees", 604 "delayed", 605 "delay_key_write", 606 "delete", 607 "delimiter", 608 "delimiters", 609 "dense_rank", 610 "desc", 611 "describe", 612 "detach", 613 "deterministic", 614 "dictionary", 615 "differential", 616 "directory", 617 "disable", 618 "discard", 619 "_disconnect", 620 "disk", 621 "distinct", 622 "distinctrow", 623 "distributed_joins", 624 "div", 625 "do", 626 "document", 627 "domain", 628 "dot_product", 629 "double", 630 "drop", 631 "_drop_profile", 632 "dual", 633 "dump", 634 "duplicate", 635 "dynamic", 636 "earliest", 637 "each", 638 "echo", 639 "election", 640 "else", 641 "elseif", 642 "elt", 643 "enable", 644 "enclosed", 645 "encoding", 646 "encrypted", 647 "end", 648 "engine", 649 "engines", 650 "enum", 651 "errors", 652 "escape", 653 "escaped", 654 "estimate", 655 "euclidean_distance", 656 "event", 657 "events", 658 "except", 659 "exclude", 660 "excluding", 661 "exclusive", 662 "execute", 663 "exists", 664 "exit", 665 "exp", 666 "explain", 667 "extended", 668 "extension", 669 "external", 670 "external_host", 671 "external_port", 672 "extract", 673 "extractor", 674 "extractors", 675 "extra_join", 676 "_failover", 677 "failed_login_attempts", 678 "failure", 679 "false", 680 "family", 681 "fault", 682 "fetch", 683 "field", 684 "fields", 685 "file", 686 "files", 687 "fill", 688 "first", 689 "first_value", 690 "fix_alter", 691 "fixed", 692 "float", 693 "float4", 694 "float8", 695 "floor", 696 "flush", 697 "following", 698 "for", 699 "force", 700 "force_compiled_mode", 701 "force_interpreter_mode", 702 "foreground", 703 "foreign", 704 "format", 705 "forward", 706 "found_rows", 707 "freeze", 708 "from", 709 "from_base64", 710 "from_days", 711 "from_unixtime", 712 "fs", 713 "_fsync", 714 "full", 715 "fulltext", 716 "function", 717 "functions", 718 "gc", 719 "gcs", 720 "get_format", 721 "_gc", 722 "_gcx", 723 "generate", 724 "geography", 725 "geography_area", 726 "geography_contains", 727 "geography_distance", 728 "geography_intersects", 729 "geography_latitude", 730 "geography_length", 731 "geography_longitude", 732 "geographypoint", 733 "geography_point", 734 "geography_within_distance", 735 "geometry", 736 "geometry_area", 737 "geometry_contains", 738 "geometry_distance", 739 "geometry_filter", 740 "geometry_intersects", 741 "geometry_length", 742 "geometrypoint", 743 "geometry_point", 744 "geometry_within_distance", 745 "geometry_x", 746 "geometry_y", 747 "global", 748 "_global_version_timestamp", 749 "grant", 750 "granted", 751 "grants", 752 "greatest", 753 "group", 754 "grouping", 755 "groups", 756 "group_concat", 757 "gzip", 758 "handle", 759 "handler", 760 "hard_cpu_limit_percentage", 761 "hash", 762 "has_temp_tables", 763 "having", 764 "hdfs", 765 "header", 766 "heartbeat_no_logging", 767 "hex", 768 "highlight", 769 "high_priority", 770 "hold", 771 "holding", 772 "host", 773 "hosts", 774 "hour", 775 "hour_microsecond", 776 "hour_minute", 777 "hour_second", 778 "identified", 779 "identity", 780 "if", 781 "ifnull", 782 "ignore", 783 "ilike", 784 "immediate", 785 "immutable", 786 "implicit", 787 "import", 788 "in", 789 "including", 790 "increment", 791 "incremental", 792 "index", 793 "indexes", 794 "inet_aton", 795 "inet_ntoa", 796 "inet6_aton", 797 "inet6_ntoa", 798 "infile", 799 "inherit", 800 "inherits", 801 "_init_profile", 802 "init", 803 "initcap", 804 "initialize", 805 "initially", 806 "inject", 807 "inline", 808 "inner", 809 "inout", 810 "input", 811 "insensitive", 812 "insert", 813 "insert_method", 814 "instance", 815 "instead", 816 "instr", 817 "int", 818 "int1", 819 "int2", 820 "int3", 821 "int4", 822 "int8", 823 "integer", 824 "_internal_dynamic_typecast", 825 "interpreter_mode", 826 "intersect", 827 "interval", 828 "into", 829 "invoker", 830 "is", 831 "isnull", 832 "isolation", 833 "iterate", 834 "join", 835 "json", 836 "json_agg", 837 "json_array_contains_double", 838 "json_array_contains_json", 839 "json_array_contains_string", 840 "json_array_push_double", 841 "json_array_push_json", 842 "json_array_push_string", 843 "json_delete_key", 844 "json_extract_double", 845 "json_extract_json", 846 "json_extract_string", 847 "json_extract_bigint", 848 "json_get_type", 849 "json_length", 850 "json_set_double", 851 "json_set_json", 852 "json_set_string", 853 "json_splice_double", 854 "json_splice_json", 855 "json_splice_string", 856 "kafka", 857 "key", 858 "key_block_size", 859 "keys", 860 "kill", 861 "killall", 862 "label", 863 "lag", 864 "language", 865 "large", 866 "last", 867 "last_day", 868 "last_insert_id", 869 "last_value", 870 "lateral", 871 "latest", 872 "lc_collate", 873 "lc_ctype", 874 "lcase", 875 "lead", 876 "leading", 877 "leaf", 878 "leakproof", 879 "least", 880 "leave", 881 "leaves", 882 "left", 883 "length", 884 "level", 885 "license", 886 "like", 887 "limit", 888 "lines", 889 "listen", 890 "llvm", 891 "ln", 892 "load", 893 "loaddata_where", 894 "_load", 895 "local", 896 "localtime", 897 "localtimestamp", 898 "locate", 899 "location", 900 "lock", 901 "log", 902 "log10", 903 "log2", 904 "long", 905 "longblob", 906 "longtext", 907 "loop", 908 "lower", 909 "low_priority", 910 "lpad", 911 "_ls", 912 "ltrim", 913 "lz4", 914 "management", 915 "_management_thread", 916 "mapping", 917 "master", 918 "match", 919 "materialized", 920 "max", 921 "maxvalue", 922 "max_concurrency", 923 "max_errors", 924 "max_partitions_per_batch", 925 "max_queue_depth", 926 "max_retries_per_batch_partition", 927 "max_rows", 928 "mbc", 929 "md5", 930 "mpl", 931 "median", 932 "mediumblob", 933 "mediumint", 934 "mediumtext", 935 "member", 936 "memory", 937 "memory_percentage", 938 "_memsql_table_id_lookup", 939 "memsql", 940 "memsql_deserialize", 941 "memsql_imitating_kafka", 942 "memsql_serialize", 943 "merge", 944 "metadata", 945 "microsecond", 946 "middleint", 947 "min", 948 "min_rows", 949 "minus", 950 "minute", 951 "minute_microsecond", 952 "minute_second", 953 "minvalue", 954 "mod", 955 "mode", 956 "model", 957 "modifies", 958 "modify", 959 "month", 960 "monthname", 961 "months_between", 962 "move", 963 "mpl", 964 "names", 965 "named", 966 "namespace", 967 "national", 968 "natural", 969 "nchar", 970 "next", 971 "no", 972 "node", 973 "none", 974 "no_query_rewrite", 975 "noparam", 976 "not", 977 "nothing", 978 "notify", 979 "now", 980 "nowait", 981 "no_write_to_binlog", 982 "no_query_rewrite", 983 "norely", 984 "nth_value", 985 "ntile", 986 "null", 987 "nullcols", 988 "nullif", 989 "nulls", 990 "numeric", 991 "nvarchar", 992 "object", 993 "octet_length", 994 "of", 995 "off", 996 "offline", 997 "offset", 998 "offsets", 999 "oids", 1000 "on", 1001 "online", 1002 "only", 1003 "open", 1004 "operator", 1005 "optimization", 1006 "optimize", 1007 "optimizer", 1008 "optimizer_state", 1009 "option", 1010 "options", 1011 "optionally", 1012 "or", 1013 "order", 1014 "ordered_serialize", 1015 "orphan", 1016 "out", 1017 "out_of_order", 1018 "outer", 1019 "outfile", 1020 "over", 1021 "overlaps", 1022 "overlay", 1023 "owned", 1024 "owner", 1025 "pack_keys", 1026 "paired", 1027 "parser", 1028 "parquet", 1029 "partial", 1030 "partition", 1031 "partition_id", 1032 "partitioning", 1033 "partitions", 1034 "passing", 1035 "password", 1036 "password_lock_time", 1037 "parser", 1038 "pause", 1039 "_pause_replay", 1040 "percent_rank", 1041 "percentile_cont", 1042 "percentile_disc", 1043 "periodic", 1044 "persisted", 1045 "pi", 1046 "pipeline", 1047 "pipelines", 1048 "pivot", 1049 "placing", 1050 "plan", 1051 "plans", 1052 "plancache", 1053 "plugins", 1054 "pool", 1055 "pools", 1056 "port", 1057 "position", 1058 "pow", 1059 "power", 1060 "preceding", 1061 "precision", 1062 "prepare", 1063 "prepared", 1064 "preserve", 1065 "primary", 1066 "prior", 1067 "privileges", 1068 "procedural", 1069 "procedure", 1070 "procedures", 1071 "process", 1072 "processlist", 1073 "profile", 1074 "profiles", 1075 "program", 1076 "promote", 1077 "proxy", 1078 "purge", 1079 "quarter", 1080 "queries", 1081 "query", 1082 "query_timeout", 1083 "queue", 1084 "quote", 1085 "radians", 1086 "rand", 1087 "range", 1088 "rank", 1089 "read", 1090 "_read", 1091 "reads", 1092 "real", 1093 "reassign", 1094 "rebalance", 1095 "recheck", 1096 "record", 1097 "recursive", 1098 "redundancy", 1099 "redundant", 1100 "ref", 1101 "reference", 1102 "references", 1103 "refresh", 1104 "regexp", 1105 "reindex", 1106 "relative", 1107 "release", 1108 "reload", 1109 "rely", 1110 "remote", 1111 "remove", 1112 "rename", 1113 "repair", 1114 "_repair_table", 1115 "repeat", 1116 "repeatable", 1117 "_repl", 1118 "_reprovisioning", 1119 "replace", 1120 "replica", 1121 "replicate", 1122 "replicating", 1123 "replication", 1124 "durability", 1125 "require", 1126 "resource", 1127 "resource_pool", 1128 "reset", 1129 "restart", 1130 "restore", 1131 "restrict", 1132 "result", 1133 "_resurrect", 1134 "retry", 1135 "return", 1136 "returning", 1137 "returns", 1138 "reverse", 1139 "revoke", 1140 "rg_pool", 1141 "right", 1142 "right_anti_join", 1143 "right_semi_join", 1144 "right_straight_join", 1145 "rlike", 1146 "role", 1147 "roles", 1148 "rollback", 1149 "rollup", 1150 "round", 1151 "routine", 1152 "row", 1153 "row_count", 1154 "row_format", 1155 "row_number", 1156 "rows", 1157 "rowstore", 1158 "rule", 1159 "rpad", 1160 "_rpc", 1161 "rtrim", 1162 "running", 1163 "s3", 1164 "safe", 1165 "save", 1166 "savepoint", 1167 "scalar", 1168 "schema", 1169 "schemas", 1170 "schema_binding", 1171 "scroll", 1172 "search", 1173 "second", 1174 "second_microsecond", 1175 "sec_to_time", 1176 "security", 1177 "select", 1178 "semi_join", 1179 "_send_threads", 1180 "sensitive", 1181 "separator", 1182 "sequence", 1183 "sequences", 1184 "serial", 1185 "serializable", 1186 "series", 1187 "service_user", 1188 "server", 1189 "session", 1190 "session_user", 1191 "set", 1192 "setof", 1193 "security_lists_intersect", 1194 "sha", 1195 "sha1", 1196 "sha2", 1197 "shard", 1198 "sharded", 1199 "sharded_id", 1200 "share", 1201 "show", 1202 "shutdown", 1203 "sigmoid", 1204 "sign", 1205 "signal", 1206 "similar", 1207 "simple", 1208 "site", 1209 "signed", 1210 "sin", 1211 "skip", 1212 "skipped_batches", 1213 "sleep", 1214 "_sleep", 1215 "smallint", 1216 "snapshot", 1217 "_snapshot", 1218 "_snapshots", 1219 "soft_cpu_limit_percentage", 1220 "some", 1221 "soname", 1222 "sparse", 1223 "spatial", 1224 "spatial_check_index", 1225 "specific", 1226 "split", 1227 "sql", 1228 "sql_big_result", 1229 "sql_buffer_result", 1230 "sql_cache", 1231 "sql_calc_found_rows", 1232 "sqlexception", 1233 "sql_mode", 1234 "sql_no_cache", 1235 "sql_no_logging", 1236 "sql_small_result", 1237 "sqlstate", 1238 "sqlwarning", 1239 "sqrt", 1240 "ssl", 1241 "stable", 1242 "standalone", 1243 "start", 1244 "starting", 1245 "state", 1246 "statement", 1247 "statistics", 1248 "stats", 1249 "status", 1250 "std", 1251 "stddev", 1252 "stddev_pop", 1253 "stddev_samp", 1254 "stdin", 1255 "stdout", 1256 "stop", 1257 "storage", 1258 "str_to_date", 1259 "straight_join", 1260 "strict", 1261 "string", 1262 "strip", 1263 "subdate", 1264 "substr", 1265 "substring", 1266 "substring_index", 1267 "success", 1268 "sum", 1269 "super", 1270 "symmetric", 1271 "sync_snapshot", 1272 "sync", 1273 "_sync", 1274 "_sync2", 1275 "_sync_partitions", 1276 "_sync_snapshot", 1277 "synchronize", 1278 "sysid", 1279 "system", 1280 "table", 1281 "table_checksum", 1282 "tables", 1283 "tablespace", 1284 "tags", 1285 "tan", 1286 "target_size", 1287 "task", 1288 "temp", 1289 "template", 1290 "temporary", 1291 "temptable", 1292 "_term_bump", 1293 "terminate", 1294 "terminated", 1295 "test", 1296 "text", 1297 "then", 1298 "time", 1299 "timediff", 1300 "time_bucket", 1301 "time_format", 1302 "timeout", 1303 "timestamp", 1304 "timestampadd", 1305 "timestampdiff", 1306 "timezone", 1307 "time_to_sec", 1308 "tinyblob", 1309 "tinyint", 1310 "tinytext", 1311 "to", 1312 "to_base64", 1313 "to_char", 1314 "to_date", 1315 "to_days", 1316 "to_json", 1317 "to_number", 1318 "to_seconds", 1319 "to_timestamp", 1320 "tracelogs", 1321 "traditional", 1322 "trailing", 1323 "transform", 1324 "transaction", 1325 "_transactions_experimental", 1326 "treat", 1327 "trigger", 1328 "triggers", 1329 "trim", 1330 "true", 1331 "trunc", 1332 "truncate", 1333 "trusted", 1334 "two_phase", 1335 "_twopcid", 1336 "type", 1337 "types", 1338 "ucase", 1339 "unbounded", 1340 "uncommitted", 1341 "undefined", 1342 "undo", 1343 "unencrypted", 1344 "unenforced", 1345 "unhex", 1346 "unhold", 1347 "unicode", 1348 "union", 1349 "unique", 1350 "_unittest", 1351 "unix_timestamp", 1352 "unknown", 1353 "unlisten", 1354 "_unload", 1355 "unlock", 1356 "unlogged", 1357 "unpivot", 1358 "unsigned", 1359 "until", 1360 "update", 1361 "upgrade", 1362 "upper", 1363 "usage", 1364 "use", 1365 "user", 1366 "users", 1367 "using", 1368 "utc_date", 1369 "utc_time", 1370 "utc_timestamp", 1371 "_utf8", 1372 "vacuum", 1373 "valid", 1374 "validate", 1375 "validator", 1376 "value", 1377 "values", 1378 "varbinary", 1379 "varchar", 1380 "varcharacter", 1381 "variables", 1382 "variadic", 1383 "variance", 1384 "var_pop", 1385 "var_samp", 1386 "varying", 1387 "vector_sub", 1388 "verbose", 1389 "version", 1390 "view", 1391 "void", 1392 "volatile", 1393 "voting", 1394 "wait", 1395 "_wake", 1396 "warnings", 1397 "week", 1398 "weekday", 1399 "weekofyear", 1400 "when", 1401 "where", 1402 "while", 1403 "whitespace", 1404 "window", 1405 "with", 1406 "without", 1407 "within", 1408 "_wm_heartbeat", 1409 "work", 1410 "workload", 1411 "wrapper", 1412 "write", 1413 "xact_id", 1414 "xor", 1415 "year", 1416 "year_month", 1417 "yes", 1418 "zerofill", 1419 "zone", 1420 } 1421 1422 def jsonextractscalar_sql(self, expression: exp.JSONExtractScalar) -> str: 1423 json_type = expression.args.get("json_type") 1424 func_name = "JSON_EXTRACT_JSON" if json_type is None else f"JSON_EXTRACT_{json_type}" 1425 return json_extract_segments(func_name)(self, expression) 1426 1427 def jsonbextractscalar_sql(self, expression: exp.JSONBExtractScalar) -> str: 1428 json_type = expression.args.get("json_type") 1429 func_name = "BSON_EXTRACT_BSON" if json_type is None else f"BSON_EXTRACT_{json_type}" 1430 return json_extract_segments(func_name)(self, expression) 1431 1432 def jsonextractarray_sql(self, expression: exp.JSONExtractArray) -> str: 1433 self.unsupported("Arrays are not supported in SingleStore") 1434 return self.function_fallback_sql(expression) 1435 1436 def jsonvalue_sql(self, expression: exp.JSONValue) -> str: 1437 if expression.args.get("on_condition"): 1438 self.unsupported("JSON_VALUE does not support on_condition") 1439 res: exp.Expr = exp.JSONExtractScalar( 1440 this=expression.this, 1441 expression=expression.args.get("path"), 1442 json_type="STRING", 1443 ) 1444 1445 returning = expression.args.get("returning") 1446 if returning is not None: 1447 res = exp.Cast(this=res, to=returning) 1448 1449 return self.sql(res) 1450 1451 def all_sql(self, expression: exp.All) -> str: 1452 self.unsupported("ALL subquery predicate is not supported in SingleStore") 1453 return super().all_sql(expression) 1454 1455 def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str: 1456 json_type = expression.text("json_type").upper() 1457 1458 if json_type: 1459 return self.func( 1460 f"JSON_ARRAY_CONTAINS_{json_type}", expression.expression, expression.this 1461 ) 1462 1463 return self.func( 1464 "JSON_ARRAY_CONTAINS_JSON", 1465 expression.expression, 1466 self.func("TO_JSON", expression.this), 1467 ) 1468 1469 def datatype_sql(self, expression: exp.DataType) -> str: 1470 for arg_name in ("kind", "values"): 1471 if expression.args.get(arg_name): 1472 self.unsupported(f"DATATYPE does not support {arg_name}") 1473 if expression.args.get("nested") and not expression.is_type(exp.DType.STRUCT): 1474 self.unsupported( 1475 f"Argument 'nested' is not supported for representation of '{expression.this.value}' in SingleStore" 1476 ) 1477 1478 if expression.is_type(exp.DType.VARBINARY) and not expression.expressions: 1479 # `VARBINARY` must always have a size - if it doesn't, we always generate `BLOB` 1480 return "BLOB" 1481 if expression.is_type( 1482 exp.DType.DECIMAL32, 1483 exp.DType.DECIMAL64, 1484 exp.DType.DECIMAL128, 1485 exp.DType.DECIMAL256, 1486 ): 1487 scale = self.expressions(expression, flat=True) 1488 1489 if expression.is_type(exp.DType.DECIMAL32): 1490 precision = "9" 1491 elif expression.is_type(exp.DType.DECIMAL64): 1492 precision = "18" 1493 elif expression.is_type(exp.DType.DECIMAL128): 1494 precision = "38" 1495 else: 1496 # 65 is a maximum precision supported in SingleStore 1497 precision = "65" 1498 if scale is not None: 1499 return f"DECIMAL({precision}, {scale[0]})" 1500 else: 1501 return f"DECIMAL({precision})" 1502 if expression.is_type(exp.DType.VECTOR): 1503 expressions = expression.expressions 1504 if len(expressions) == 2: 1505 type_name = self.sql(expressions[0]) 1506 if type_name in self.dialect.INVERSE_VECTOR_TYPE_ALIASES: 1507 type_name = self.dialect.INVERSE_VECTOR_TYPE_ALIASES[type_name] 1508 1509 return f"VECTOR({self.sql(expressions[1])}, {type_name})" 1510 1511 return super().datatype_sql(expression) 1512 1513 def collate_sql(self, expression: exp.Collate) -> str: 1514 # SingleStore does not support setting a collation for column in the SELECT query, 1515 # so we cast column to a LONGTEXT type with specific collation 1516 return self.binary(expression, ":> LONGTEXT COLLATE") 1517 1518 def currentdate_sql(self, expression: exp.CurrentDate) -> str: 1519 timezone = expression.this 1520 if timezone: 1521 if isinstance(timezone, exp.Literal) and timezone.name.lower() == "utc": 1522 return self.func("UTC_DATE") 1523 self.unsupported("CurrentDate with timezone is not supported in SingleStore") 1524 1525 return self.func("CURRENT_DATE") 1526 1527 def currenttime_sql(self, expression: exp.CurrentTime) -> str: 1528 arg = expression.this 1529 if arg: 1530 if isinstance(arg, exp.Literal) and arg.name.lower() == "utc": 1531 return self.func("UTC_TIME") 1532 if isinstance(arg, exp.Literal) and arg.is_number: 1533 return self.func("CURRENT_TIME", arg) 1534 self.unsupported("CurrentTime with timezone is not supported in SingleStore") 1535 1536 return self.func("CURRENT_TIME") 1537 1538 def currenttimestamp_sql(self, expression: exp.CurrentTimestamp) -> str: 1539 arg = expression.this 1540 if arg: 1541 if isinstance(arg, exp.Literal) and arg.name.lower() == "utc": 1542 return self.func("UTC_TIMESTAMP") 1543 if isinstance(arg, exp.Literal) and arg.is_number: 1544 return self.func("CURRENT_TIMESTAMP", arg) 1545 self.unsupported("CurrentTimestamp with timezone is not supported in SingleStore") 1546 1547 return self.func("CURRENT_TIMESTAMP") 1548 1549 def standardhash_sql(self, expression: exp.StandardHash) -> str: 1550 hash_function = expression.expression 1551 if hash_function is None: 1552 return self.func("SHA", expression.this) 1553 if isinstance(hash_function, exp.Literal): 1554 if hash_function.name.lower() == "sha": 1555 return self.func("SHA", expression.this) 1556 if hash_function.name.lower() == "md5": 1557 return self.func("MD5", expression.this) 1558 1559 self.unsupported(f"{hash_function.this} hash method is not supported in SingleStore") 1560 return self.func("SHA", expression.this) 1561 1562 self.unsupported("STANDARD_HASH function is not supported in SingleStore") 1563 return self.func("SHA", expression.this) 1564 1565 def truncatetable_sql(self, expression: exp.TruncateTable) -> str: 1566 for arg_name in ("is_database", "exists", "cluster", "identity", "option", "partition"): 1567 if expression.args.get(arg_name): 1568 self.unsupported(f"TRUNCATE TABLE does not support {arg_name}") 1569 statements = [] 1570 for table in expression.expressions: 1571 statements.append(f"TRUNCATE {self.sql(table)}") 1572 1573 return "; ".join(statements) 1574 1575 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 1576 if expression.args.get("exists"): 1577 self.unsupported("RENAME COLUMN does not support exists") 1578 old_column = self.sql(expression, "this") 1579 new_column = self.sql(expression, "to") 1580 return f"CHANGE {old_column} {new_column}" 1581 1582 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 1583 for arg_name in ("drop", "comment", "allow_null", "visible", "using"): 1584 if expression.args.get(arg_name): 1585 self.unsupported(f"ALTER COLUMN does not support {arg_name}") 1586 alter = super().altercolumn_sql(expression) 1587 1588 collate = self.sql(expression, "collate") 1589 collate = f" COLLATE {collate}" if collate else "" 1590 return f"{alter}{collate}" 1591 1592 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 1593 this = self.sql(expression, "this") 1594 not_null = " NOT NULL" if expression.args.get("not_null") else "" 1595 type = self.sql(expression, "data_type") or "AUTO" 1596 return f"AS {this} PERSISTED {type}{not_null}"
Generator converts a given syntax tree to the corresponding SQL string.
Arguments:
- pretty: Whether to format the produced SQL string. Default: False.
- identify: Determines when an identifier should be quoted. Possible values are: False (default): Never quote, except in cases where it's mandatory by the dialect. True: Always quote except for specials cases. 'safe': Only quote identifiers that are case insensitive.
- normalize: Whether to normalize identifiers to lowercase. Default: False.
- pad: The pad size in a formatted string. For example, this affects the indentation of a projection in a query, relative to its nesting level. Default: 2.
- indent: The indentation size in a formatted string. For example, this affects the
indentation of subqueries and filters under a
WHEREclause. Default: 2. - normalize_functions: How to normalize function names. Possible values are: "upper" or True (default): Convert names to uppercase. "lower": Convert names to lowercase. False: Disables function name normalization.
- unsupported_level: Determines the generator's behavior when it encounters unsupported expressions. Default ErrorLevel.WARN.
- max_unsupported: Maximum number of unsupported messages to include in a raised UnsupportedError. This is only relevant if unsupported_level is ErrorLevel.RAISE. Default: 3
- leading_comma: Whether the comma is leading or trailing in select expressions. This is only relevant when generating in pretty mode. Default: False
- max_text_width: The max number of characters in a segment before creating new lines in pretty mode. The default is on the smaller end because the length only represents a segment and not the true line length. Default: 80
- comments: Whether to preserve comments in the output SQL code. Default: True
SUPPORTED_JSON_PATH_PARTS =
{<class 'sqlglot.expressions.query.JSONPathRoot'>, <class 'sqlglot.expressions.query.JSONPathSubscript'>, <class 'sqlglot.expressions.query.JSONPathKey'>}
TRANSFORMS =
{<class 'sqlglot.expressions.query.JSONPathKey'>: <function json_path_key_only_name>, <class 'sqlglot.expressions.query.JSONPathRoot'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.query.JSONPathSubscript'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.core.Adjacent'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.AllowedValuesProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.AnalyzeColumns'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.AnalyzeWith'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayContainsAll'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayOverlaps'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.AssumeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.AutoRefreshProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.BackupProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.math.Ceil'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.ConnectByRoot'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.string.ConvertToCharset'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CredentialsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentCatalog'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.SessionUser'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.constraints.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ApiProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ApplicationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CatalogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ComputeProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.DatabaseProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.DynamicProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.EmptyProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.EndStatement'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.EnviromentProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HandlerProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ParameterStyleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.EphemeralColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ExcludeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Except'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.math.Floor'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Get'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.GlobalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HybridProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.IcebergProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.InheritsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.InputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Intersect'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.datatypes.IntervalSpan'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.Int64'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsAnyTopKeys'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsAllTopKeys'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBDeleteAtPath'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONObject'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.json.JSONObjectAgg'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.MaskingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.NetFunc'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.NetworkProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.NonClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.NotForReplicationColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OnProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.Operator'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OutputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.ExtendsLeft'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.ExtendsRight'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.PartitionedByBucket'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.PartitionByTruncate'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.PivotAny'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.PositionalColumn'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ProjectionPolicyColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.InvisibleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ZeroFillColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Put'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.RemoteWithConnectionModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.RowAccessProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.SafeFunc'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SampleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SecureProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SecurityIntegrationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SetConfigProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SharingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SqlReadWriteProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Stream'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StreamingTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StrictProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ddl.SwapTable'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.TableColumn'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.Tags'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ToMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TransformModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.VirtualProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ddl.TriggerExecute'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Union'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.UnloggedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.UsingTemplateProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.UsingData'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcDate'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcTime'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.UtcTimestamp'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.query.Variadic'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.VarMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ViewAttributeProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithProcedureOptions'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithSchemaBindingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.WithOperator'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ForceProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.aggregate.ArrayAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.math.BitwiseAndAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.math.BitwiseOrAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.math.BitwiseXorAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.math.BitwiseCount'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Chr'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentVersion'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.DateDiff'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DateAdd'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.DateStrToDate'>: <function datestrtodate_sql>, <class 'sqlglot.expressions.temporal.DateSub'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.DateTrunc'>: <function timestamptrunc_sql.<locals>._timestamptrunc_sql>, <class 'sqlglot.expressions.temporal.Day'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.DayOfMonth'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.DayOfWeek'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.DayOfYear'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.aggregate.GroupConcat'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.core.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.string.Length'>: <function length_or_char_length_sql>, <class 'sqlglot.expressions.aggregate.LogicalOr'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.LogicalAnd'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.aggregate.Min'>: <function min_or_least>, <class 'sqlglot.expressions.temporal.Month'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.core.NullSafeEQ'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.core.NullSafeNEQ'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.string.NumberToStr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.query.Pivot'>: <function no_pivot_sql>, <class 'sqlglot.expressions.query.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.string.StrPosition'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.StrToDate'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.StrToTime'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.Stuff'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.query.TableSample'>: <function no_tablesample_sql>, <class 'sqlglot.expressions.temporal.TimeFromParts'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimestampAdd'>: <function date_add_interval_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.TimestampDiff'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TimestampSub'>: <function date_add_interval_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.TimeStrToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimeStrToTime'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TimeToStr'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.Trim'>: <function trim_sql>, <class 'sqlglot.expressions.math.Trunc'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.functions.TryCast'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TsOrDsAdd'>: <function date_add_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.TsOrDsDiff'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TsOrDsToDate'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.Unicode'>: <function MySQLGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.UnixToTime'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.Week'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.WeekOfYear'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.Year'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.string.ToChar'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.Date'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.functions.Cast'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.functions.CastToStrType'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.StrToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimeToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.UnixSeconds'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.UnixToStr'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.UnixToTimeStr'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DateBin'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TimeStrToDate'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.core.FromTimeZone'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DiToDate'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DateToDi'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TsOrDiToDi'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.Time'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DatetimeAdd'>: <function _remove_ts_or_ds_to_date.<locals>.func>, <class 'sqlglot.expressions.temporal.DatetimeTrunc'>: <function timestamptrunc_sql.<locals>._timestamptrunc_sql>, <class 'sqlglot.expressions.temporal.DatetimeSub'>: <function date_add_interval_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.DatetimeDiff'>: <function timestampdiff_sql>, <class 'sqlglot.expressions.temporal.TimestampTrunc'>: <function timestamptrunc_sql.<locals>._timestamptrunc_sql>, <class 'sqlglot.expressions.temporal.CurrentDatetime'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONExtract'>: <function json_extract_segments.<locals>._json_extract_segments>, <class 'sqlglot.expressions.json.JSONBExtract'>: <function json_extract_segments.<locals>._json_extract_segments>, <class 'sqlglot.expressions.json.JSONFormat'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.json.JSONArrayAgg'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONArray'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.json.JSONBExists'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONExists'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DayOfWeekIso'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.core.Hll'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.ApproxDistinct'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.CountIf'>: <function count_if_to_sum>, <class 'sqlglot.expressions.aggregate.ApproxQuantile'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.Variance'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.VariancePop'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.Xor'>: <function bool_xor_sql>, <class 'sqlglot.expressions.math.Cbrt'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.core.RegexpLike'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.Repeat'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.IsAscii'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.MD5Digest'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.Contains'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.RegexpExtractAll'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.RegexpExtract'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.StartsWith'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.FromBase'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.RegexpILike'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.query.National'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.array.Reduce'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.string.MatchAgainst'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.ddl.Show'>: <function SingleStoreGenerator.<lambda>>, <class 'sqlglot.expressions.ddl.Describe'>: <function SingleStoreGenerator.<lambda>>}
UNSUPPORTED_TYPES =
{<DType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <DType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <DType.XML: 'XML'>, <DType.TSRANGE: 'TSRANGE'>, <DType.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <DType.AGGREGATEFUNCTION: 'AGGREGATEFUNCTION'>, <DType.IPADDRESS: 'IPADDRESS'>, <DType.RANGE: 'RANGE'>, <DType.TIMETZ: 'TIMETZ'>, <DType.NOTHING: 'NOTHING'>, <DType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <DType.INT128: 'INT128'>, <DType.IPV6: 'IPV6'>, <DType.NUMRANGE: 'NUMRANGE'>, <DType.TDIGEST: 'TDIGEST'>, <DType.BPCHAR: 'BPCHAR'>, <DType.MONEY: 'MONEY'>, <DType.ROWVERSION: 'ROWVERSION'>, <DType.ARRAY: 'ARRAY'>, <DType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <DType.DYNAMIC: 'DYNAMIC'>, <DType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <DType.INT8RANGE: 'INT8RANGE'>, <DType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <DType.LIST: 'LIST'>, <DType.INT4RANGE: 'INT4RANGE'>, <DType.SUPER: 'SUPER'>, <DType.MULTILINESTRING: 'MULTILINESTRING'>, <DType.SMALLSERIAL: 'SMALLSERIAL'>, <DType.INT256: 'INT256'>, <DType.MAP: 'MAP'>, <DType.NAME: 'NAME'>, <DType.NESTED: 'NESTED'>, <DType.HSTORE: 'HSTORE'>, <DType.SMALLMONEY: 'SMALLMONEY'>, <DType.HLLSKETCH: 'HLLSKETCH'>, <DType.OBJECT: 'OBJECT'>, <DType.TIMESTAMPNTZ: 'TIMESTAMPNTZ'>, <DType.IPPREFIX: 'IPPREFIX'>, <DType.INTERVAL: 'INTERVAL'>, <DType.TSTZRANGE: 'TSTZRANGE'>, <DType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <DType.DATERANGE: 'DATERANGE'>, <DType.UINT128: 'UINT128'>, <DType.NULL: 'NULL'>, <DType.USERDEFINED: 'USER-DEFINED'>, <DType.BIGSERIAL: 'BIGSERIAL'>, <DType.SERIAL: 'SERIAL'>, <DType.UNKNOWN: 'UNKNOWN'>, <DType.VARIANT: 'VARIANT'>, <DType.TSMULTIRANGE: 'TSMULTIRANGE'>, <DType.UUID: 'UUID'>, <DType.LOWCARDINALITY: 'LOWCARDINALITY'>, <DType.IMAGE: 'IMAGE'>, <DType.SIMPLEAGGREGATEFUNCTION: 'SIMPLEAGGREGATEFUNCTION'>, <DType.UINT256: 'UINT256'>, <DType.UNION: 'UNION'>, <DType.IPV4: 'IPV4'>, <DType.INET: 'INET'>}
TYPE_MAPPING =
{<DType.NCHAR: 'NCHAR'>: 'CHAR', <DType.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <DType.INET: 'INET'>: 'INET', <DType.ROWVERSION: 'ROWVERSION'>: 'VARBINARY', <DType.UBIGINT: 'UBIGINT'>: 'BIGINT', <DType.UINT: 'UINT'>: 'INT', <DType.UMEDIUMINT: 'UMEDIUMINT'>: 'MEDIUMINT', <DType.USMALLINT: 'USMALLINT'>: 'SMALLINT', <DType.UTINYINT: 'UTINYINT'>: 'TINYINT', <DType.UDECIMAL: 'UDECIMAL'>: 'DECIMAL', <DType.UDOUBLE: 'UDOUBLE'>: 'DOUBLE', <DType.DATETIME2: 'DATETIME2'>: 'DATETIME', <DType.SMALLDATETIME: 'SMALLDATETIME'>: 'DATETIME', <DType.TIMESTAMP: 'TIMESTAMP'>: 'TIMESTAMP', <DType.TIMESTAMPNTZ: 'TIMESTAMPNTZ'>: 'DATETIME', <DType.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'TIMESTAMP', <DType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>: 'TIMESTAMP', <DType.BIGDECIMAL: 'BIGDECIMAL'>: 'DECIMAL', <DType.BIT: 'BIT'>: 'BOOLEAN', <DType.DATE32: 'DATE32'>: 'DATE', <DType.DATETIME64: 'DATETIME64'>: 'DATETIME', <DType.DECIMAL32: 'DECIMAL32'>: 'DECIMAL', <DType.DECIMAL64: 'DECIMAL64'>: 'DECIMAL', <DType.DECIMAL128: 'DECIMAL128'>: 'DECIMAL', <DType.DECIMAL256: 'DECIMAL256'>: 'DECIMAL', <DType.ENUM8: 'ENUM8'>: 'ENUM', <DType.ENUM16: 'ENUM16'>: 'ENUM', <DType.FIXEDSTRING: 'FIXEDSTRING'>: 'TEXT', <DType.GEOMETRY: 'GEOMETRY'>: 'GEOGRAPHY', <DType.POINT: 'POINT'>: 'GEOGRAPHYPOINT', <DType.RING: 'RING'>: 'GEOGRAPHY', <DType.LINESTRING: 'LINESTRING'>: 'GEOGRAPHY', <DType.POLYGON: 'POLYGON'>: 'GEOGRAPHY', <DType.MULTIPOLYGON: 'MULTIPOLYGON'>: 'GEOGRAPHY', <DType.STRUCT: 'STRUCT'>: 'RECORD', <DType.JSONB: 'JSONB'>: 'BSON', <DType.TIMESTAMP_S: 'TIMESTAMP_S'>: 'TIMESTAMP', <DType.TIMESTAMP_MS: 'TIMESTAMP_MS'>: 'TIMESTAMP(6)'}
RESERVED_KEYWORDS =
{'geometry_filter', 'collate', 'host', 'sigmoid', 'begin', 'cache', 'committed', 'geometry_distance', 'void', 'to_timestamp', 'primary', '_read', 'real', 'latest', 'when', 'float4', 'loaddata_where', 'connection', 'system', 'max', 'groups', 'sql_small_result', 'sql_big_result', 'abs', 'to_days', 'high_priority', 'drop', '_utf8', 'varcharacter', 'mediumint', 'trigger', 'procedural', 'regexp', '_resurrect', 'stdin', '_check_consistency', 'plancache', 'security', 'always', 'sql_buffer_result', 'ssl', 'stdout', 'week', 'binary', 'limit', 'memsql', 'cascade', 'procedure', 'utc_time', 'sqrt', 'bucket_count', 'running', 'end', 'read', 'aggregators', 'repeat', 'curdate', 'optimize', 'foreground', '_term_bump', '_load', 'skipped_batches', 'interpreter_mode', 'cume_dist', 'sec_to_time', 'memsql_serialize', 'where', 'substring', 'prior', 'row_number', 'from_base64', 'configuration', 'terminate', 'global', 'backup_history', 'cost', 'outfile', 'sequence', 'stop', 'aes_encrypt', 'standalone', 'hash', 'cot', 'null', 'false', 'found_rows', 'atan', 'event', 'close', 'modify', 'procedures', 'treat', 'rebalance', 'connections', 'concat_ws', 'heartbeat_no_logging', 'right_semi_join', 'geography_contains', 'also', 'repeatable', 'open', '_transactions_experimental', 'avro', 'bit', 'div', 'sql_mode', 'range', 'rule', 'over', 'do', 'orphan', 'any_value', 'clustered', 'signal', 'echo', 'schema_binding', '_snapshots', 'replication', 'time', 'has_temp_tables', 'nulls', 'scalar', '_sync_snapshot', 'truncate', 'copy', 'dual', 'trailing', 'named', 'reindex', 'nullcols', 'sync', 'autostats', 'out_of_order', 'reads', '_wake', 'replicating', 'sha2', 'off', 'safe', 'atan2', 'pipelines', 'view', 'int2', 'inet6_aton', 'byte_length', 'json_extract_string', 'sync_snapshot', 'at', 'geometry_contains', 'result', 'client', 'input', 'convert_tz', 'failed_login_attempts', 'to', 'hosts', 'series', 'session_user', 'hour_minute', 'sign', 'create', 'chain', 'program', 'enum', 'is', 'arrangement', 'function', 'array', 'lock', 'for', 'dayofyear', 'holding', '_sync2', 'case', 'tables', 'columns', 'routine', 'plan', 'stddev_samp', 'defined', 'memsql_deserialize', 'std', 'return', 'timediff', 'select', 'lz4', 'sql', 'record', 'remove', 'modifies', 'months_between', 'nowait', 'hdfs', 'redundancy', 'anti_join', 'cube', 'restart', '_wm_heartbeat', 'rank', 'to_seconds', 'instead', 'prepared', 'events', 'hard_cpu_limit_percentage', 'enable', 'partitions', 'triggers', 'shard', 'arghistory', 'init', 'some', 'success', 'inet_aton', 'from_days', 'length', 'unlogged', 'credentials', 'exclude', 'int', 'periodic', 'window', 'cnf', 'date_trunc', 'locate', 'second_microsecond', 'mediumblob', 'escaped', 'algorithm', 'lateral', 'listen', 'vector_sub', 'year', 'octet_length', 'wait', 'add', 'transaction', 'none', 'partial', 'unknown', 'characteristics', 'passing', 'transform', 'call', 'mapping', 'string', 'increment', 'btree', 'max_rows', 'yes', 'from_unixtime', 'asymmetric', 'document', 'repair', 'dayofweek', 'refresh', 'next', 'fulltext', 'last_value', 'aggregator_id', 'class', 'varbinary', 'variables', 'gzip', 'sysid', 'batch', '_rpc', 'char_length', 'columnstore_segment_rows', 'write', 'radians', '_drop_profile', 'purge', 'compressed', 'vacuum', 'rpad', 'namespace', 'json_splice_double', 'users', 'ltrim', 'reference', 'simple', 'partitioning', '_sleep', 'serializable', 'stddev', 'constraint', 'geography_point', 'substring_index', 'constraints', 'forward', 'round', 'xor', 'insensitive', 'pools', 'time_format', 'soft_cpu_limit_percentage', 'bit_or', 'resource_pool', 'instance', 'log10', 'leaf', 'addtime', 'concurrent', 'lag', 'rlike', 'last_insert_id', 'smallint', 'deferrable', 'load', 'concurrently', 'now', 'blob', 'split', 'overlaps', 'password', 'integer', 'decode', 'xact_id', 'merge', 'flush', 'all', 'day_hour', 'quarter', 'day_microsecond', 'recheck', 'metadata', 'traditional', 'day_minute', 'move', '_fsync', 'within', 'materialized', 'hour_microsecond', 'task', 'percentile_disc', 'position', 'inline', 'json_get_type', 'value', 'initcap', 'date_sub', 'sql_cache', 'distinctrow', 'on', 'out', 'warnings', 'geographypoint', 'availability', 'called', 'avg', 'elt', 'capture', 'condition', 'mode', 'encrypted', 'unlock', 'mediumtext', 'default', 'domain', 'handler', 'shutdown', 'family', 'unhold', 'immediate', 'connection_id', 'current_user', 'directory', 'cluster', 'json_delete_key', 'returning', 'utc_timestamp', '_bt', 'second', 'unique', 'restore', 'concat', 'freeze', 'batch_interval', 'in', 'unpivot', 'password_lock_time', 'session', 'sql_no_logging', 'long', 'ceiling', 'json_extract_double', 'revoke', 'row_format', 'require', 'nvarchar', 'minute_second', '_twopcid', 'database', 'compile', 'clear', 'partition_id', 'save', 'assignment', '_check_can_connect', '_send_threads', 'overlay', 'to_number', 'role', '_background_threads_for_cleanup', 'exp', 'union', 'log', 'ast', 'dense_rank', 'localtimestamp', 'desc', 'show', 'workload', '_pause_replay', 'backup_id', 'interval', 'approx_count_distinct_estimate', 'timestampdiff', 'retry', '_snapshot', 'change', 'low_priority', 'tinyblob', 'varchar', 'only', 'current_timestamp', 'owned', 'processlist', 'placing', 'autostats_cardinality_mode', 'rollback', 'whitespace', 'exclusive', 'execute', 'ln', 'sha', 'asm', 'geography_area', 'option', 'sparse', 'str_to_date', 'disable', 'persisted', 'usage', 'validate', 'then', 'dot_product', 'access', 'char', 'action', 'external', 'escape', 'day_second', 'dynamic', 'current_time', 'dayofmonth', 'specific', '_commit_log_tail', 'deferred', 'lpad', 'options', 'sharded', 'against', 'status', 'var_samp', 'pipeline', 'update', 'query_timeout', 'work', 'character', 'immutable', 'varying', '_internal_dynamic_typecast', 'timestampadd', 'inner', 'label', 'spatial', 'rely', 'with', 'gc', 'upper', 'plans', 'terminated', 'killall', 'zerofill', 'intersect', 'max_partitions_per_batch', 'pack_keys', 'inout', 'autostats_enabled', 'group', 'datetime', 'first', 'security_lists_intersect', 'json_array_contains_string', 'ascii', 'minus', 'admin', 'max_retries_per_batch_partition', 'table_checksum', 'starting', 'deallocate', 'sharded_id', 'insert', 'json_set_json', 'indexes', 'grants', 'force_interpreter_mode', 'bigint', 'curtime', 'key_block_size', 'lc_collate', 'pause', 'inet_ntoa', 'decimal', 'ntile', 'as', 'content', 'float8', 'table', '_init_profile', '_binary', 'last', 'right_straight_join', 'snapshot', 'remote', 'without', 'undefined', 'geography_latitude', 'file', 'leakproof', 'format', 'search', 'types', 'fields', 'implicit', 'natural', 'following', 'csv', 'infile', 'queue', 'references', 'approx_percentile', 'each', 'memory_percentage', 'extended', 'distributed_joins', 'import', 'statistics', 'encoding', 'assertion', 'serial', 'checksum', 'plugins', 'describe', 'ilike', 'replace', '_unittest', 'force_compiled_mode', 'field', 'loop', 'national', 'or', 'outer', 'sql_calc_found_rows', 'time_to_sec', 'schema', 'backward', 'initialize', 'json_array_push_double', 'separator', 'fault', 'attribute', 'ignore', '_failover', 'monthname', 'int8', 'left', 'straight_join', 'pi', 'numeric', 'variadic', '_repair_table', '_sync_partitions', 'approx_count_distinct_combine', 'current_catalog', 'estimate', 'extension', 'minute', 'client_found_rows', 'bootstrap', 'arrange', 'port', 'timeout', 'inject', 'site', 'definer', 'geometry_length', 'full', 'owner', 'having', 'type', 'disk', 'double', 'approx_count_distinct_accumulate', 'sleep', 'inherits', 'ordered_serialize', 'using', 'keys', 'extractor', 'optimization', 'dayname', 'coalesce', 'cos', 'catalog', 'max_errors', 'declare', 'super', 'query', '_gcx', 's3', 'language', 'maxvalue', 'geography_intersects', 'json_splice_string', 'first_value', 'noparam', 'scroll', 'geography_within_distance', 'tinytext', 'relative', 'insert_method', '_checksum', 'current_schema', 'longblob', 'granted', 'nth_value', '_memsql_table_id_lookup', 'object', 'prepare', 'redundant', 'autostats_sampling', 'index', 'unenforced', 'savepoint', 'current_security_roles', 'delay_key_write', 'fetch', '_continue_replay', 'unbounded', 'bit_xor', 'min_rows', 'least', 'unicode', 'spatial_check_index', 'state', 'asc', 'json_set_double', 'character_length', 'unix_timestamp', 'mod', 'asensitive', 'identity', 'conversion', 'location', 'hex', 'current_role', 'geometry_area', 'collect', 'power', 'lines', 'sin', 'like', 'longtext', 'isnull', 'master', 'parquet', 'grant', 'json_array_push_string', 'storage', 'sensitive', 'data', 'weekofyear', 'norely', 'roles', 'geometry_intersects', '_disconnect', 'json_array_push_json', 'parser', 'tracelogs', 'mpl', 'excluding', 'bool', 'join', 'no_query_rewrite', 'json_splice_json', 'lcase', 'temp', 'no', '_sync', 'to_json', 'dec', 'set', 'alter', 'management', 'charset', 'geometry', 'check', 'approx_geography_intersects', 'profiles', 'extract', 'last_day', 'subdate', 'middleint', 'online', 'cascaded', 'geometry_point', 'ceil', 'datediff', 'lower', 'service_user', 'voting', 'statement', 'tan', 'date', 'generate', 'promote', 'autostats_histogram_mode', 'explain', '_gc', 'preceding', 'nothing', '_repl', 'azure', 'sql_no_cache', 'cycle', 'pivot', 'json', 'median', 'substr', 'synchronize', 'geography', 'llvm', 'undo', 'user', 'operator', 'config', 'int1', 'fill', 'rg_pool', 'level', 'by', 'compression', 'float', 'json_array_contains_json', 'restrict', 'boolean', 'ucase', 'if', 'get_format', 'degrees', 'fixed', 'replica', 'tags', 'variance', 'inet6_ntoa', 'geometry_within_distance', 'int3', 'release', 'collation', 'right_anti_join', 'var_pop', 'including', 'acos', 'upgrade', 'two_phase', 'current_security_groups', 'optimizer', 'columnstore', 'fix_alter', 'sqlwarning', 'similar', 'soname', 'exit', 'date_add', 'queries', 'identified', 'between', 'recursive', 'kafka', 'month', 'test', 'to_date', 'server', '_management_thread', 'int4', 'databases', 'strip', 'until', 'ifnull', 'values', 'notify', 'defaults', 'log2', 'aggregate', 'geometry_y', 'temporary', 'offset', 'json_extract_json', 'tinyint', 'avg_row_length', 'timestamp', 'order', 'lead', 'geography_length', 'nullif', 'floor', 'leading', 'leaves', 'signed', 'comment', 'enclosed', 'batches', 'external_port', 'time_bucket', 'reload', 'coercibility', 'functions', 'mbc', 'minute_microsecond', 'instr', 'before', 'no_write_to_binlog', 'replicate', 'adddate', 'iterate', 'rtrim', 'unencrypted', 'geography_longitude', 'dictionary', 'checkpoint', 'discard', 'conv', 'incremental', 'unlisten', 'local', 'geometrypoint', 'rename', 'hour_second', 'start', 'tablespace', 'gcs', 'aes_decrypt', 'else', 'use', 'memory', 'rand', 'background', 'delimiter', 'trusted', 'wrapper', 'convert', 'proxy', '_core', 'elseif', 'trunc', 'json_set_string', 'sequences', 'durability', 'version', 'aggregator', 'min', 'names', 'dump', 'reset', 'from', 'analyse', 'both', 'earliest', 'isolation', 'max_queue_depth', 'lc_ctype', 'deterministic', 'privileges', 'percentile_cont', 'bit_and', 'match', 'hold', 'sum', 'into', 'engine', 'sqlexception', 'delayed', 'key', 'valid', '_global_version_timestamp', 'minvalue', 'header', 'skip', 'engines', 'cursor', 'profile', 'timezone', 'to_base64', 'euclidean_distance', 'md5', 'memsql_imitating_kafka', 'inherit', 'sha1', 'backup', 'except', 'volatile', 'optimizer_state', 'microsecond', 'current_date', 'count', 'json_length', 'columnar', 'force', 'not', 'handle', 'grouping', 'commit', 'approx_count_distinct', 'json_extract_bigint', 'fs', 'invoker', 'stable', 'files', 'geometry_x', 'setof', 'aggregates', 'localtime', 'row_count', 'auto_increment', 'rows', 'json_array_contains_double', 'auto_reprovision', 'node', 'duplicate', 'async', 'true', 'extractors', 'auto', 'large', 'validator', 'sqlstate', 'trim', 'delete', 'temptable', 'call_for_pipeline', 'compact', 'percent_rank', 'asin', 'bit_count', 'precision', 'leave', 'oids', 'weekday', 'differential', 'errors', 'any', 'reassign', 'returns', 'uncommitted', 'year_month', 'byte', 'column', 'offline', 'day', '_batch_size_limit', 'paired', 'distinct', 'rowstore', 'license', 'share', 'verbose', 'delimiters', 'unhex', 'rollup', 'authorization', 'to_char', 'of', '_reprovisioning', 'bin', 'json_agg', 'cast', 'zone', 'utc_date', 'stddev_pop', 'unsigned', 'extra_join', 'resource', 'aggregator_plan_hash', 'date_format', 'group_concat', 'pool', 'ref', 'nchar', 'continue', 'reverse', 'external_host', 'greatest', 'partition', 'detach', 'analyze', 'foreign', 'symmetric', 'optionally', 'model', 'process', 'kill', 'offsets', 'pow', 'exists', 'strict', 'absolute', 'max_concurrency', 'highlight', 'preserve', 'quote', 'cross', 'comments', 'row', 'initially', 'geography_distance', 'attach', 'hour', 'right', '_ls', 'semi_join', 'account', '_unload', 'member', 'text', 'and', 'after', 'current', 'failure', 'template', 'stats', 'election', 'while', 'target_size', 'schemas'}
1436 def jsonvalue_sql(self, expression: exp.JSONValue) -> str: 1437 if expression.args.get("on_condition"): 1438 self.unsupported("JSON_VALUE does not support on_condition") 1439 res: exp.Expr = exp.JSONExtractScalar( 1440 this=expression.this, 1441 expression=expression.args.get("path"), 1442 json_type="STRING", 1443 ) 1444 1445 returning = expression.args.get("returning") 1446 if returning is not None: 1447 res = exp.Cast(this=res, to=returning) 1448 1449 return self.sql(res)
1455 def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str: 1456 json_type = expression.text("json_type").upper() 1457 1458 if json_type: 1459 return self.func( 1460 f"JSON_ARRAY_CONTAINS_{json_type}", expression.expression, expression.this 1461 ) 1462 1463 return self.func( 1464 "JSON_ARRAY_CONTAINS_JSON", 1465 expression.expression, 1466 self.func("TO_JSON", expression.this), 1467 )
1469 def datatype_sql(self, expression: exp.DataType) -> str: 1470 for arg_name in ("kind", "values"): 1471 if expression.args.get(arg_name): 1472 self.unsupported(f"DATATYPE does not support {arg_name}") 1473 if expression.args.get("nested") and not expression.is_type(exp.DType.STRUCT): 1474 self.unsupported( 1475 f"Argument 'nested' is not supported for representation of '{expression.this.value}' in SingleStore" 1476 ) 1477 1478 if expression.is_type(exp.DType.VARBINARY) and not expression.expressions: 1479 # `VARBINARY` must always have a size - if it doesn't, we always generate `BLOB` 1480 return "BLOB" 1481 if expression.is_type( 1482 exp.DType.DECIMAL32, 1483 exp.DType.DECIMAL64, 1484 exp.DType.DECIMAL128, 1485 exp.DType.DECIMAL256, 1486 ): 1487 scale = self.expressions(expression, flat=True) 1488 1489 if expression.is_type(exp.DType.DECIMAL32): 1490 precision = "9" 1491 elif expression.is_type(exp.DType.DECIMAL64): 1492 precision = "18" 1493 elif expression.is_type(exp.DType.DECIMAL128): 1494 precision = "38" 1495 else: 1496 # 65 is a maximum precision supported in SingleStore 1497 precision = "65" 1498 if scale is not None: 1499 return f"DECIMAL({precision}, {scale[0]})" 1500 else: 1501 return f"DECIMAL({precision})" 1502 if expression.is_type(exp.DType.VECTOR): 1503 expressions = expression.expressions 1504 if len(expressions) == 2: 1505 type_name = self.sql(expressions[0]) 1506 if type_name in self.dialect.INVERSE_VECTOR_TYPE_ALIASES: 1507 type_name = self.dialect.INVERSE_VECTOR_TYPE_ALIASES[type_name] 1508 1509 return f"VECTOR({self.sql(expressions[1])}, {type_name})" 1510 1511 return super().datatype_sql(expression)
1518 def currentdate_sql(self, expression: exp.CurrentDate) -> str: 1519 timezone = expression.this 1520 if timezone: 1521 if isinstance(timezone, exp.Literal) and timezone.name.lower() == "utc": 1522 return self.func("UTC_DATE") 1523 self.unsupported("CurrentDate with timezone is not supported in SingleStore") 1524 1525 return self.func("CURRENT_DATE")
1527 def currenttime_sql(self, expression: exp.CurrentTime) -> str: 1528 arg = expression.this 1529 if arg: 1530 if isinstance(arg, exp.Literal) and arg.name.lower() == "utc": 1531 return self.func("UTC_TIME") 1532 if isinstance(arg, exp.Literal) and arg.is_number: 1533 return self.func("CURRENT_TIME", arg) 1534 self.unsupported("CurrentTime with timezone is not supported in SingleStore") 1535 1536 return self.func("CURRENT_TIME")
1538 def currenttimestamp_sql(self, expression: exp.CurrentTimestamp) -> str: 1539 arg = expression.this 1540 if arg: 1541 if isinstance(arg, exp.Literal) and arg.name.lower() == "utc": 1542 return self.func("UTC_TIMESTAMP") 1543 if isinstance(arg, exp.Literal) and arg.is_number: 1544 return self.func("CURRENT_TIMESTAMP", arg) 1545 self.unsupported("CurrentTimestamp with timezone is not supported in SingleStore") 1546 1547 return self.func("CURRENT_TIMESTAMP")
1549 def standardhash_sql(self, expression: exp.StandardHash) -> str: 1550 hash_function = expression.expression 1551 if hash_function is None: 1552 return self.func("SHA", expression.this) 1553 if isinstance(hash_function, exp.Literal): 1554 if hash_function.name.lower() == "sha": 1555 return self.func("SHA", expression.this) 1556 if hash_function.name.lower() == "md5": 1557 return self.func("MD5", expression.this) 1558 1559 self.unsupported(f"{hash_function.this} hash method is not supported in SingleStore") 1560 return self.func("SHA", expression.this) 1561 1562 self.unsupported("STANDARD_HASH function is not supported in SingleStore") 1563 return self.func("SHA", expression.this)
1565 def truncatetable_sql(self, expression: exp.TruncateTable) -> str: 1566 for arg_name in ("is_database", "exists", "cluster", "identity", "option", "partition"): 1567 if expression.args.get(arg_name): 1568 self.unsupported(f"TRUNCATE TABLE does not support {arg_name}") 1569 statements = [] 1570 for table in expression.expressions: 1571 statements.append(f"TRUNCATE {self.sql(table)}") 1572 1573 return "; ".join(statements)
1575 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 1576 if expression.args.get("exists"): 1577 self.unsupported("RENAME COLUMN does not support exists") 1578 old_column = self.sql(expression, "this") 1579 new_column = self.sql(expression, "to") 1580 return f"CHANGE {old_column} {new_column}"
1582 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 1583 for arg_name in ("drop", "comment", "allow_null", "visible", "using"): 1584 if expression.args.get(arg_name): 1585 self.unsupported(f"ALTER COLUMN does not support {arg_name}") 1586 alter = super().altercolumn_sql(expression) 1587 1588 collate = self.sql(expression, "collate") 1589 collate = f" COLLATE {collate}" if collate else "" 1590 return f"{alter}{collate}"
def
computedcolumnconstraint_sql( self, expression: sqlglot.expressions.constraints.ComputedColumnConstraint) -> str:
1592 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 1593 this = self.sql(expression, "this") 1594 not_null = " NOT NULL" if expression.args.get("not_null") else "" 1595 type = self.sql(expression, "data_type") or "AUTO" 1596 return f"AS {this} PERSISTED {type}{not_null}"
Inherited Members
- sqlglot.generator.Generator
- Generator
- WINDOW_FUNCS_WITH_NULL_ORDERING
- IGNORE_NULLS_IN_FUNC
- IGNORE_NULLS_BEFORE_ORDER
- EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE
- CREATE_FUNCTION_RETURN_AS
- MATCHED_BY_SOURCE
- SUPPORTS_MERGE_WHERE
- SINGLE_STRING_INTERVAL
- RENAME_TABLE_WITH_DB
- GROUPINGS_SEP
- INDEX_ON
- INOUT_SEPARATOR
- DIRECTED_JOINS
- QUERY_HINTS
- IS_BOOL_ALLOWED
- LIMIT_IS_TOP
- RETURNING_END
- EXTRACT_ALLOWS_QUOTES
- TZ_TO_WITH_TIME_ZONE
- ALTER_TABLE_INCLUDE_COLUMN_KEYWORD
- UNNEST_WITH_ORDINALITY
- AGGREGATE_FILTER_SUPPORTED
- SEMI_ANTI_JOIN_WITH_SIDE
- COMPUTED_COLUMN_WITH_TYPE
- SUPPORTS_TABLE_COPY
- TABLESAMPLE_REQUIRES_PARENS
- TABLESAMPLE_SIZE_IS_ROWS
- TABLESAMPLE_KEYWORDS
- TABLESAMPLE_WITH_METHOD
- TABLESAMPLE_SEED_KEYWORD
- COLLATE_IS_FUNC
- DATA_TYPE_SPECIFIERS_ALLOWED
- ENSURE_BOOLS
- CTE_RECURSIVE_KEYWORD_REQUIRED
- SUPPORTS_SINGLE_ARG_CONCAT
- SUPPORTS_TABLE_ALIAS_COLUMNS
- UNPIVOT_ALIASES_ARE_IDENTIFIERS
- INSERT_OVERWRITE
- SUPPORTS_SELECT_INTO
- SUPPORTS_UNLOGGED_TABLES
- SUPPORTS_CREATE_TABLE_LIKE
- LIKE_PROPERTY_INSIDE_SCHEMA
- MULTI_ARG_DISTINCT
- JSON_PATH_SINGLE_QUOTE_ESCAPE
- CAN_IMPLEMENT_ARRAY_ANY
- SUPPORTS_WINDOW_EXCLUDE
- SET_OP_MODIFIERS
- COPY_PARAMS_ARE_WRAPPED
- COPY_PARAMS_EQ_REQUIRED
- COPY_HAS_INTO_KEYWORD
- STAR_EXCEPT
- HEX_FUNC
- WITH_PROPERTIES_PREFIX
- QUOTE_JSON_PATH
- SUPPORTS_EXPLODING_PROJECTIONS
- ARRAY_CONCAT_IS_VAR_LEN
- SUPPORTS_CONVERT_TIMEZONE
- SUPPORTS_UNIX_SECONDS
- ALTER_SET_WRAPPED
- NORMALIZE_EXTRACT_DATE_PARTS
- ARRAY_SIZE_NAME
- ALTER_SET_TYPE
- ARRAY_SIZE_DIM_REQUIRED
- SUPPORTS_BETWEEN_FLAGS
- SUPPORTS_LIKE_QUANTIFIERS
- SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD
- DECLARE_DEFAULT_ASSIGNMENT
- STAR_EXCLUDE_REQUIRES_DERIVED_TABLE
- SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY
- TIME_PART_SINGULARS
- TOKEN_MAPPING
- PARAMETER_TOKEN
- NAMED_PLACEHOLDER_TOKEN
- EXPRESSION_PRECEDES_PROPERTIES_CREATABLES
- WITH_SEPARATED_COMMENTS
- EXCLUDE_COMMENTS
- UNWRAPPED_INTERVAL_VALUES
- PARAMETERIZABLE_TEXT_TYPES
- EXPRESSIONS_WITHOUT_NESTED_CTES
- RESPECT_IGNORE_NULLS_UNSUPPORTED_EXPRESSIONS
- SAFE_JSON_PATH_KEY_RE
- SENTINEL_LINE_BREAK
- pretty
- identify
- normalize
- pad
- unsupported_level
- max_unsupported
- leading_comma
- max_text_width
- comments
- dialect
- normalize_functions
- unsupported_messages
- generate
- preprocess
- unsupported
- sep
- seg
- sanitize_comment
- maybe_comment
- wrap
- no_identify
- normalize_func
- indent
- sql
- uncache_sql
- cache_sql
- characterset_sql
- column_parts
- column_sql
- pseudocolumn_sql
- columnposition_sql
- columndef_sql
- columnconstraint_sql
- autoincrementcolumnconstraint_sql
- compresscolumnconstraint_sql
- generatedasidentitycolumnconstraint_sql
- generatedasrowcolumnconstraint_sql
- periodforsystemtimeconstraint_sql
- notnullcolumnconstraint_sql
- primarykeycolumnconstraint_sql
- uniquecolumnconstraint_sql
- inoutcolumnconstraint_sql
- createable_sql
- create_sql
- sequenceproperties_sql
- triggerproperties_sql
- triggerreferencing_sql
- triggerevent_sql
- clone_sql
- describe_sql
- heredoc_sql
- prepend_ctes
- with_sql
- cte_sql
- tablealias_sql
- bitstring_sql
- hexstring_sql
- bytestring_sql
- unicodestring_sql
- rawstring_sql
- datatypeparam_sql
- directory_sql
- delete_sql
- drop_sql
- set_operation
- set_operations
- fetch_sql
- limitoptions_sql
- filter_sql
- hint_sql
- indexparameters_sql
- index_sql
- identifier_sql
- hex_sql
- lowerhex_sql
- inputoutputformat_sql
- national_sql
- properties_sql
- root_properties
- properties
- with_properties
- property_name
- property_sql
- uuidproperty_sql
- likeproperty_sql
- fallbackproperty_sql
- journalproperty_sql
- freespaceproperty_sql
- checksumproperty_sql
- mergeblockratioproperty_sql
- moduleproperty_sql
- datablocksizeproperty_sql
- blockcompressionproperty_sql
- isolatedloadingproperty_sql
- partitionboundspec_sql
- partitionedofproperty_sql
- lockingproperty_sql
- withdataproperty_sql
- withsystemversioningproperty_sql
- insert_sql
- introducer_sql
- kill_sql
- pseudotype_sql
- objectidentifier_sql
- onconflict_sql
- returning_sql
- rowformatdelimitedproperty_sql
- withtablehint_sql
- indextablehint_sql
- historicaldata_sql
- table_parts
- table_sql
- tablefromrows_sql
- tablesample_sql
- pivot_sql
- version_sql
- tuple_sql
- update_sql
- values_sql
- var_sql
- into_sql
- from_sql
- groupingsets_sql
- rollup_sql
- rollupindex_sql
- rollupproperty_sql
- cube_sql
- group_sql
- having_sql
- connect_sql
- prior_sql
- join_sql
- lambda_sql
- lateral_op
- lateral_sql
- limit_sql
- offset_sql
- setitem_sql
- set_sql
- queryband_sql
- pragma_sql
- lock_sql
- literal_sql
- escape_str
- loaddata_sql
- null_sql
- boolean_sql
- booland_sql
- boolor_sql
- order_sql
- withfill_sql
- cluster_sql
- distribute_sql
- sort_sql
- ordered_sql
- matchrecognizemeasure_sql
- matchrecognize_sql
- query_modifiers
- options_modifier
- for_modifiers
- queryoption_sql
- offset_limit_modifiers
- after_limit_modifiers
- select_sql
- schema_sql
- schema_columns_sql
- star_sql
- parameter_sql
- sessionparameter_sql
- placeholder_sql
- subquery_sql
- qualify_sql
- unnest_sql
- prewhere_sql
- where_sql
- window_sql
- partition_by_sql
- windowspec_sql
- withingroup_sql
- between_sql
- bracket_offset_expressions
- bracket_sql
- any_sql
- exists_sql
- case_sql
- constraint_sql
- nextvaluefor_sql
- trim_sql
- convert_concat_args
- concat_sql
- concatws_sql
- check_sql
- foreignkey_sql
- primarykey_sql
- if_sql
- matchagainst_sql
- jsonkeyvalue_sql
- jsonpath_sql
- json_path_part
- formatjson_sql
- formatphrase_sql
- jsonarray_sql
- jsonarrayagg_sql
- jsoncolumndef_sql
- jsonschema_sql
- jsontable_sql
- openjsoncolumndef_sql
- openjson_sql
- in_sql
- in_unnest_op
- interval_sql
- return_sql
- reference_sql
- anonymous_sql
- paren_sql
- neg_sql
- not_sql
- alias_sql
- pivotalias_sql
- aliases_sql
- atindex_sql
- fromtimezone_sql
- add_sql
- and_sql
- or_sql
- xor_sql
- connector_sql
- bitwiseand_sql
- bitwiseleftshift_sql
- bitwisenot_sql
- bitwiseor_sql
- bitwiserightshift_sql
- bitwisexor_sql
- strtotime_sql
- command_sql
- comment_sql
- mergetreettlaction_sql
- mergetreettl_sql
- transaction_sql
- commit_sql
- rollback_sql
- alterindex_sql
- alterdiststyle_sql
- altersortkey_sql
- alterset_sql
- alter_sql
- altersession_sql
- add_column_sql
- droppartition_sql
- addconstraint_sql
- addpartition_sql
- distinct_sql
- respectnulls_sql
- havingmax_sql
- intdiv_sql
- div_sql
- safedivide_sql
- overlaps_sql
- distance_sql
- dot_sql
- eq_sql
- propertyeq_sql
- escape_sql
- glob_sql
- gt_sql
- gte_sql
- is_sql
- like_sql
- ilike_sql
- match_sql
- similarto_sql
- lt_sql
- lte_sql
- mod_sql
- mul_sql
- neq_sql
- nullsafeeq_sql
- nullsafeneq_sql
- sub_sql
- trycast_sql
- jsoncast_sql
- try_sql
- log_sql
- use_sql
- binary
- ceil_floor
- function_fallback_sql
- func
- format_args
- too_wide
- format_time
- expressions
- op_expressions
- naked_property
- tag_sql
- token_sql
- userdefinedfunction_sql
- joinhint_sql
- kwarg_sql
- when_sql
- whens_sql
- merge_sql
- tochar_sql
- tonumber_sql
- dictproperty_sql
- dictrange_sql
- dictsubproperty_sql
- duplicatekeyproperty_sql
- uniquekeyproperty_sql
- distributedbyproperty_sql
- oncluster_sql
- clusteredbyproperty_sql
- anyvalue_sql
- querytransform_sql
- indexconstraintoption_sql
- checkcolumnconstraint_sql
- indexcolumnconstraint_sql
- nvl2_sql
- comprehension_sql
- columnprefix_sql
- opclass_sql
- predict_sql
- generateembedding_sql
- generatetext_sql
- generatetable_sql
- generatebool_sql
- generateint_sql
- generatedouble_sql
- mltranslate_sql
- mlforecast_sql
- aiforecast_sql
- featuresattime_sql
- vectorsearch_sql
- forin_sql
- refresh_sql
- toarray_sql
- tsordstotime_sql
- tsordstotimestamp_sql
- tsordstodatetime_sql
- tsordstodate_sql
- unixdate_sql
- lastday_sql
- dateadd_sql
- arrayany_sql
- struct_sql
- convert_sql
- copyparameter_sql
- credentials_sql
- copy_sql
- semicolon_sql
- datadeletionproperty_sql
- maskingpolicycolumnconstraint_sql
- gapfill_sql
- scope_resolution
- scoperesolution_sql
- parsejson_sql
- rand_sql
- changes_sql
- pad_sql
- summarize_sql
- explodinggenerateseries_sql
- json_sql
- skipjsoncolumn_sql
- conditionalinsert_sql
- multitableinserts_sql
- oncondition_sql
- jsonextractquote_sql
- jsonexists_sql
- arrayagg_sql
- slice_sql
- apply_sql
- grant_sql
- revoke_sql
- grantprivilege_sql
- grantprincipal_sql
- columns_sql
- overlay_sql
- todouble_sql
- string_sql
- median_sql
- overflowtruncatebehavior_sql
- unixseconds_sql
- arraysize_sql
- attach_sql
- detach_sql
- attachoption_sql
- watermarkcolumnconstraint_sql
- encodeproperty_sql
- includeproperty_sql
- xmlelement_sql
- xmlkeyvalueoption_sql
- partitionbyrangepropertydynamic_sql
- unpivotcolumns_sql
- analyzesample_sql
- analyzestatistics_sql
- analyzehistogram_sql
- analyzedelete_sql
- analyzelistchainedrows_sql
- analyzevalidate_sql
- analyze_sql
- xmltable_sql
- xmlnamespace_sql
- export_sql
- declare_sql
- declareitem_sql
- recursivewithsearch_sql
- parameterizedagg_sql
- anonymousaggfunc_sql
- combinedaggfunc_sql
- combinedparameterizedagg_sql
- install_sql
- get_put_sql
- translatecharacters_sql
- decodecase_sql
- semanticview_sql
- getextract_sql
- datefromunixdate_sql
- space_sql
- buildproperty_sql
- refreshtriggerproperty_sql
- modelattribute_sql
- directorystage_sql
- uuid_sql
- initcap_sql
- localtime_sql
- localtimestamp_sql
- weekstart_sql
- chr_sql
- block_sql
- storedprocedure_sql
- ifblock_sql
- whileblock_sql
- execute_sql
- executesql_sql
- altermodifysqlsecurity_sql
- usingproperty_sql
- renameindex_sql
- sqlglot.generators.mysql.MySQLGenerator
- SELECT_KINDS
- TRY_SUPPORTED
- SUPPORTS_DECODE_CASE
- AFTER_HAVING_MODIFIER_TRANSFORMS
- INTERVAL_ALLOWS_PLURAL_FORM
- LOCKING_READS_SUPPORTED
- JOIN_HINTS
- TABLE_HINTS
- DUPLICATE_KEY_UPDATE_WITH_SET
- QUERY_HINT_SEP
- VALUES_AS_TABLE
- NVL2_SUPPORTED
- LAST_DAY_SUPPORTS_DATE_PART
- JSON_TYPE_REQUIRED_FOR_EXTRACTION
- JSON_PATH_BRACKETED_KEY_SUPPORTED
- JSON_KEY_VALUE_PAIR_SEP
- SUPPORTS_TO_NUMBER
- PARSE_JSON_NAME
- PAD_FILL_PATTERN_IS_REQUIRED
- WRAP_DERIVED_VALUES
- VARCHAR_REQUIRES_SIZE
- SUPPORTS_MEDIAN
- UPDATE_STATEMENT_SUPPORTS_FROM
- UNSIGNED_TYPE_MAPPING
- TIMESTAMP_TYPE_MAPPING
- PROPERTIES_LOCATION
- LIMIT_FETCH
- LIMIT_ONLY_LITERALS
- CHAR_CAST_MAPPING
- SIGNED_CAST_MAPPING
- CAST_MAPPING
- TIMESTAMP_FUNC_TYPES
- SQL_SECURITY_VIEW_LOCATION
- locate_properties
- array_sql
- arraycontainsall_sql
- dpipe_sql
- extract_sql
- cast_sql
- show_sql
- alterrename_sql
- timestamptrunc_sql
- converttimezone_sql
- attimezone_sql
- isascii_sql
- ignorenulls_sql
- currentschema_sql
- partition_sql
- partitionbyrangeproperty_sql
- partitionbylistproperty_sql
- partitionlist_sql
- partitionrange_sql