sqlglot.dialects.mysql API documentation

Edit on GitHub

# sqlglot.dialects.mysql

View Source

      1from __future__ import annotations
      2
      3from sqlglot import exp, generator, parser, tokens
      4from sqlglot.dialects.dialect import (
      5    Dialect,
      6    locate_to_strposition,
      7    min_or_least,
      8    no_ilike_sql,
      9    no_paren_current_date_sql,
     10    no_tablesample_sql,
     11    no_trycast_sql,
     12    rename_func,
     13    strposition_to_locate_sql,
     14)
     15from sqlglot.helper import seq_get
     16from sqlglot.tokens import TokenType
     17
     18
     19def _show_parser(*args, **kwargs):
     20    def _parse(self):
     21        return self._parse_show_mysql(*args, **kwargs)
     22
     23    return _parse
     24
     25
     26def _date_trunc_sql(self, expression):
     27    expr = self.sql(expression, "this")
     28    unit = expression.text("unit")
     29
     30    if unit == "day":
     31        return f"DATE({expr})"
     32
     33    if unit == "week":
     34        concat = f"CONCAT(YEAR({expr}), ' ', WEEK({expr}, 1), ' 1')"
     35        date_format = "%Y %u %w"
     36    elif unit == "month":
     37        concat = f"CONCAT(YEAR({expr}), ' ', MONTH({expr}), ' 1')"
     38        date_format = "%Y %c %e"
     39    elif unit == "quarter":
     40        concat = f"CONCAT(YEAR({expr}), ' ', QUARTER({expr}) * 3 - 2, ' 1')"
     41        date_format = "%Y %c %e"
     42    elif unit == "year":
     43        concat = f"CONCAT(YEAR({expr}), ' 1 1')"
     44        date_format = "%Y %c %e"
     45    else:
     46        self.unsupported(f"Unexpected interval unit: {unit}")
     47        return f"DATE({expr})"
     48
     49    return f"STR_TO_DATE({concat}, '{date_format}')"
     50
     51
     52def _str_to_date(args):
     53    date_format = MySQL.format_time(seq_get(args, 1))
     54    return exp.StrToDate(this=seq_get(args, 0), format=date_format)
     55
     56
     57def _str_to_date_sql(self, expression):
     58    date_format = self.format_time(expression)
     59    return f"STR_TO_DATE({self.sql(expression.this)}, {date_format})"
     60
     61
     62def _trim_sql(self, expression):
     63    target = self.sql(expression, "this")
     64    trim_type = self.sql(expression, "position")
     65    remove_chars = self.sql(expression, "expression")
     66
     67    # Use TRIM/LTRIM/RTRIM syntax if the expression isn't mysql-specific
     68    if not remove_chars:
     69        return self.trim_sql(expression)
     70
     71    trim_type = f"{trim_type} " if trim_type else ""
     72    remove_chars = f"{remove_chars} " if remove_chars else ""
     73    from_part = "FROM " if trim_type or remove_chars else ""
     74    return f"TRIM({trim_type}{remove_chars}{from_part}{target})"
     75
     76
     77def _date_add(expression_class):
     78    def func(args):
     79        interval = seq_get(args, 1)
     80        return expression_class(
     81            this=seq_get(args, 0),
     82            expression=interval.this,
     83            unit=exp.Literal.string(interval.text("unit").lower()),
     84        )
     85
     86    return func
     87
     88
     89def _date_add_sql(kind):
     90    def func(self, expression):
     91        this = self.sql(expression, "this")
     92        unit = expression.text("unit").upper() or "DAY"
     93        return (
     94            f"DATE_{kind}({this}, {self.sql(exp.Interval(this=expression.expression, unit=unit))})"
     95        )
     96
     97    return func
     98
     99
    100class MySQL(Dialect):
    101    time_format = "'%Y-%m-%d %T'"
    102
    103    # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions
    104    time_mapping = {
    105        "%M": "%B",
    106        "%c": "%-m",
    107        "%e": "%-d",
    108        "%h": "%I",
    109        "%i": "%M",
    110        "%s": "%S",
    111        "%S": "%S",
    112        "%u": "%W",
    113        "%k": "%-H",
    114        "%l": "%-I",
    115        "%T": "%H:%M:%S",
    116    }
    117
    118    class Tokenizer(tokens.Tokenizer):
    119        QUOTES = ["'", '"']
    120        COMMENTS = ["--", "#", ("/*", "*/")]
    121        IDENTIFIERS = ["`"]
    122        STRING_ESCAPES = ["'", "\\"]
    123        BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
    124        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
    125
    126        KEYWORDS = {
    127            **tokens.Tokenizer.KEYWORDS,
    128            "MEDIUMTEXT": TokenType.MEDIUMTEXT,
    129            "LONGTEXT": TokenType.LONGTEXT,
    130            "MEDIUMBLOB": TokenType.MEDIUMBLOB,
    131            "LONGBLOB": TokenType.LONGBLOB,
    132            "START": TokenType.BEGIN,
    133            "SEPARATOR": TokenType.SEPARATOR,
    134            "_ARMSCII8": TokenType.INTRODUCER,
    135            "_ASCII": TokenType.INTRODUCER,
    136            "_BIG5": TokenType.INTRODUCER,
    137            "_BINARY": TokenType.INTRODUCER,
    138            "_CP1250": TokenType.INTRODUCER,
    139            "_CP1251": TokenType.INTRODUCER,
    140            "_CP1256": TokenType.INTRODUCER,
    141            "_CP1257": TokenType.INTRODUCER,
    142            "_CP850": TokenType.INTRODUCER,
    143            "_CP852": TokenType.INTRODUCER,
    144            "_CP866": TokenType.INTRODUCER,
    145            "_CP932": TokenType.INTRODUCER,
    146            "_DEC8": TokenType.INTRODUCER,
    147            "_EUCJPMS": TokenType.INTRODUCER,
    148            "_EUCKR": TokenType.INTRODUCER,
    149            "_GB18030": TokenType.INTRODUCER,
    150            "_GB2312": TokenType.INTRODUCER,
    151            "_GBK": TokenType.INTRODUCER,
    152            "_GEOSTD8": TokenType.INTRODUCER,
    153            "_GREEK": TokenType.INTRODUCER,
    154            "_HEBREW": TokenType.INTRODUCER,
    155            "_HP8": TokenType.INTRODUCER,
    156            "_KEYBCS2": TokenType.INTRODUCER,
    157            "_KOI8R": TokenType.INTRODUCER,
    158            "_KOI8U": TokenType.INTRODUCER,
    159            "_LATIN1": TokenType.INTRODUCER,
    160            "_LATIN2": TokenType.INTRODUCER,
    161            "_LATIN5": TokenType.INTRODUCER,
    162            "_LATIN7": TokenType.INTRODUCER,
    163            "_MACCE": TokenType.INTRODUCER,
    164            "_MACROMAN": TokenType.INTRODUCER,
    165            "_SJIS": TokenType.INTRODUCER,
    166            "_SWE7": TokenType.INTRODUCER,
    167            "_TIS620": TokenType.INTRODUCER,
    168            "_UCS2": TokenType.INTRODUCER,
    169            "_UJIS": TokenType.INTRODUCER,
    170            # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
    171            "_UTF8": TokenType.INTRODUCER,
    172            "_UTF16": TokenType.INTRODUCER,
    173            "_UTF16LE": TokenType.INTRODUCER,
    174            "_UTF32": TokenType.INTRODUCER,
    175            "_UTF8MB3": TokenType.INTRODUCER,
    176            "_UTF8MB4": TokenType.INTRODUCER,
    177            "@@": TokenType.SESSION_PARAMETER,
    178        }
    179
    180        COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SET, TokenType.SHOW}
    181
    182    class Parser(parser.Parser):
    183        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS, TokenType.SCHEMA, TokenType.DATABASE}  # type: ignore
    184
    185        FUNCTIONS = {
    186            **parser.Parser.FUNCTIONS,  # type: ignore
    187            "DATE_ADD": _date_add(exp.DateAdd),
    188            "DATE_SUB": _date_add(exp.DateSub),
    189            "STR_TO_DATE": _str_to_date,
    190            "LOCATE": locate_to_strposition,
    191            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    192            "LEFT": lambda args: exp.Substring(
    193                this=seq_get(args, 0), start=exp.Literal.number(1), length=seq_get(args, 1)
    194            ),
    195        }
    196
    197        FUNCTION_PARSERS = {
    198            **parser.Parser.FUNCTION_PARSERS,  # type: ignore
    199            "GROUP_CONCAT": lambda self: self.expression(
    200                exp.GroupConcat,
    201                this=self._parse_lambda(),
    202                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    203            ),
    204        }
    205
    206        PROPERTY_PARSERS = {
    207            **parser.Parser.PROPERTY_PARSERS,  # type: ignore
    208            "ENGINE": lambda self: self._parse_property_assignment(exp.EngineProperty),
    209        }
    210
    211        STATEMENT_PARSERS = {
    212            **parser.Parser.STATEMENT_PARSERS,  # type: ignore
    213            TokenType.SHOW: lambda self: self._parse_show(),
    214            TokenType.SET: lambda self: self._parse_set(),
    215        }
    216
    217        SHOW_PARSERS = {
    218            "BINARY LOGS": _show_parser("BINARY LOGS"),
    219            "MASTER LOGS": _show_parser("BINARY LOGS"),
    220            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    221            "CHARACTER SET": _show_parser("CHARACTER SET"),
    222            "CHARSET": _show_parser("CHARACTER SET"),
    223            "COLLATION": _show_parser("COLLATION"),
    224            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    225            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    226            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    227            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    228            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    229            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    230            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    231            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    232            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    233            "DATABASES": _show_parser("DATABASES"),
    234            "ENGINE": _show_parser("ENGINE", target=True),
    235            "STORAGE ENGINES": _show_parser("ENGINES"),
    236            "ENGINES": _show_parser("ENGINES"),
    237            "ERRORS": _show_parser("ERRORS"),
    238            "EVENTS": _show_parser("EVENTS"),
    239            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    240            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    241            "GRANTS": _show_parser("GRANTS", target="FOR"),
    242            "INDEX": _show_parser("INDEX", target="FROM"),
    243            "MASTER STATUS": _show_parser("MASTER STATUS"),
    244            "OPEN TABLES": _show_parser("OPEN TABLES"),
    245            "PLUGINS": _show_parser("PLUGINS"),
    246            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    247            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    248            "PRIVILEGES": _show_parser("PRIVILEGES"),
    249            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    250            "PROCESSLIST": _show_parser("PROCESSLIST"),
    251            "PROFILE": _show_parser("PROFILE"),
    252            "PROFILES": _show_parser("PROFILES"),
    253            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    254            "REPLICAS": _show_parser("REPLICAS"),
    255            "SLAVE HOSTS": _show_parser("REPLICAS"),
    256            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    257            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    258            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    259            "SESSION STATUS": _show_parser("STATUS"),
    260            "STATUS": _show_parser("STATUS"),
    261            "TABLE STATUS": _show_parser("TABLE STATUS"),
    262            "FULL TABLES": _show_parser("TABLES", full=True),
    263            "TABLES": _show_parser("TABLES"),
    264            "TRIGGERS": _show_parser("TRIGGERS"),
    265            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    266            "SESSION VARIABLES": _show_parser("VARIABLES"),
    267            "VARIABLES": _show_parser("VARIABLES"),
    268            "WARNINGS": _show_parser("WARNINGS"),
    269        }
    270
    271        SET_PARSERS = {
    272            "GLOBAL": lambda self: self._parse_set_item_assignment("GLOBAL"),
    273            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    274            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    275            "SESSION": lambda self: self._parse_set_item_assignment("SESSION"),
    276            "LOCAL": lambda self: self._parse_set_item_assignment("LOCAL"),
    277            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    278            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    279            "NAMES": lambda self: self._parse_set_item_names(),
    280            "TRANSACTION": lambda self: self._parse_set_transaction(),
    281        }
    282
    283        PROFILE_TYPES = {
    284            "ALL",
    285            "BLOCK IO",
    286            "CONTEXT SWITCHES",
    287            "CPU",
    288            "IPC",
    289            "MEMORY",
    290            "PAGE FAULTS",
    291            "SOURCE",
    292            "SWAPS",
    293        }
    294
    295        TRANSACTION_CHARACTERISTICS = {
    296            "ISOLATION LEVEL REPEATABLE READ",
    297            "ISOLATION LEVEL READ COMMITTED",
    298            "ISOLATION LEVEL READ UNCOMMITTED",
    299            "ISOLATION LEVEL SERIALIZABLE",
    300            "READ WRITE",
    301            "READ ONLY",
    302        }
    303
    304        INTEGER_DIVISION = False
    305
    306        def _parse_show_mysql(self, this, target=False, full=None, global_=None):
    307            if target:
    308                if isinstance(target, str):
    309                    self._match_text_seq(target)
    310                target_id = self._parse_id_var()
    311            else:
    312                target_id = None
    313
    314            log = self._parse_string() if self._match_text_seq("IN") else None
    315
    316            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    317                position = self._parse_number() if self._match_text_seq("FROM") else None
    318                db = None
    319            else:
    320                position = None
    321                db = self._parse_id_var() if self._match_text_seq("FROM") else None
    322
    323            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    324
    325            like = self._parse_string() if self._match_text_seq("LIKE") else None
    326            where = self._parse_where()
    327
    328            if this == "PROFILE":
    329                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    330                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    331                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    332                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    333            else:
    334                types, query = None, None
    335                offset, limit = self._parse_oldstyle_limit()
    336
    337            mutex = True if self._match_text_seq("MUTEX") else None
    338            mutex = False if self._match_text_seq("STATUS") else mutex
    339
    340            return self.expression(
    341                exp.Show,
    342                this=this,
    343                target=target_id,
    344                full=full,
    345                log=log,
    346                position=position,
    347                db=db,
    348                channel=channel,
    349                like=like,
    350                where=where,
    351                types=types,
    352                query=query,
    353                offset=offset,
    354                limit=limit,
    355                mutex=mutex,
    356                **{"global": global_},
    357            )
    358
    359        def _parse_var_from_options(self, options):
    360            for option in options:
    361                if self._match_text_seq(*option.split(" ")):
    362                    return exp.Var(this=option)
    363            return None
    364
    365        def _parse_oldstyle_limit(self):
    366            limit = None
    367            offset = None
    368            if self._match_text_seq("LIMIT"):
    369                parts = self._parse_csv(self._parse_number)
    370                if len(parts) == 1:
    371                    limit = parts[0]
    372                elif len(parts) == 2:
    373                    limit = parts[1]
    374                    offset = parts[0]
    375            return offset, limit
    376
    377        def _default_parse_set_item(self):
    378            return self._parse_set_item_assignment(kind=None)
    379
    380        def _parse_set_item_assignment(self, kind):
    381            if kind in {"GLOBAL", "SESSION"} and self._match_text_seq("TRANSACTION"):
    382                return self._parse_set_transaction(global_=kind == "GLOBAL")
    383
    384            left = self._parse_primary() or self._parse_id_var()
    385            if not self._match(TokenType.EQ):
    386                self.raise_error("Expected =")
    387            right = self._parse_statement() or self._parse_id_var()
    388
    389            this = self.expression(
    390                exp.EQ,
    391                this=left,
    392                expression=right,
    393            )
    394
    395            return self.expression(
    396                exp.SetItem,
    397                this=this,
    398                kind=kind,
    399            )
    400
    401        def _parse_set_item_charset(self, kind):
    402            this = self._parse_string() or self._parse_id_var()
    403
    404            return self.expression(
    405                exp.SetItem,
    406                this=this,
    407                kind=kind,
    408            )
    409
    410        def _parse_set_item_names(self):
    411            charset = self._parse_string() or self._parse_id_var()
    412            if self._match_text_seq("COLLATE"):
    413                collate = self._parse_string() or self._parse_id_var()
    414            else:
    415                collate = None
    416            return self.expression(
    417                exp.SetItem,
    418                this=charset,
    419                collate=collate,
    420                kind="NAMES",
    421            )
    422
    423        def _parse_set_transaction(self, global_=False):
    424            self._match_text_seq("TRANSACTION")
    425            characteristics = self._parse_csv(
    426                lambda: self._parse_var_from_options(self.TRANSACTION_CHARACTERISTICS)
    427            )
    428            return self.expression(
    429                exp.SetItem,
    430                expressions=characteristics,
    431                kind="TRANSACTION",
    432                **{"global": global_},
    433            )
    434
    435    class Generator(generator.Generator):
    436        LOCKING_READS_SUPPORTED = True
    437        NULL_ORDERING_SUPPORTED = False
    438        INTEGER_DIVISION = False
    439
    440        TRANSFORMS = {
    441            **generator.Generator.TRANSFORMS,  # type: ignore
    442            exp.CurrentDate: no_paren_current_date_sql,
    443            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
    444            exp.ILike: no_ilike_sql,
    445            exp.Min: min_or_least,
    446            exp.TableSample: no_tablesample_sql,
    447            exp.TryCast: no_trycast_sql,
    448            exp.DateAdd: _date_add_sql("ADD"),
    449            exp.DateSub: _date_add_sql("SUB"),
    450            exp.DateTrunc: _date_trunc_sql,
    451            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    452            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    453            exp.DayOfYear: rename_func("DAYOFYEAR"),
    454            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    455            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    456            exp.StrToDate: _str_to_date_sql,
    457            exp.StrToTime: _str_to_date_sql,
    458            exp.Trim: _trim_sql,
    459            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    460            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    461            exp.StrPosition: strposition_to_locate_sql,
    462        }
    463
    464        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    465        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    466        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    467        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    468        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    469
    470        PROPERTIES_LOCATION = {
    471            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    472            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    473        }
    474
    475        def show_sql(self, expression):
    476            this = f" {expression.name}"
    477            full = " FULL" if expression.args.get("full") else ""
    478            global_ = " GLOBAL" if expression.args.get("global") else ""
    479
    480            target = self.sql(expression, "target")
    481            target = f" {target}" if target else ""
    482            if expression.name in {"COLUMNS", "INDEX"}:
    483                target = f" FROM{target}"
    484            elif expression.name == "GRANTS":
    485                target = f" FOR{target}"
    486
    487            db = self._prefixed_sql("FROM", expression, "db")
    488
    489            like = self._prefixed_sql("LIKE", expression, "like")
    490            where = self.sql(expression, "where")
    491
    492            types = self.expressions(expression, key="types")
    493            types = f" {types}" if types else types
    494            query = self._prefixed_sql("FOR QUERY", expression, "query")
    495
    496            if expression.name == "PROFILE":
    497                offset = self._prefixed_sql("OFFSET", expression, "offset")
    498                limit = self._prefixed_sql("LIMIT", expression, "limit")
    499            else:
    500                offset = ""
    501                limit = self._oldstyle_limit_sql(expression)
    502
    503            log = self._prefixed_sql("IN", expression, "log")
    504            position = self._prefixed_sql("FROM", expression, "position")
    505
    506            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    507
    508            if expression.name == "ENGINE":
    509                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    510            else:
    511                mutex_or_status = ""
    512
    513            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    514
    515        def _prefixed_sql(self, prefix, expression, arg):
    516            sql = self.sql(expression, arg)
    517            if not sql:
    518                return ""
    519            return f" {prefix} {sql}"
    520
    521        def _oldstyle_limit_sql(self, expression):
    522            limit = self.sql(expression, "limit")
    523            offset = self.sql(expression, "offset")
    524            if limit:
    525                limit_offset = f"{offset}, {limit}" if offset else limit
    526                return f" LIMIT {limit_offset}"
    527            return ""
    528
    529        def setitem_sql(self, expression):
    530            kind = self.sql(expression, "kind")
    531            kind = f"{kind} " if kind else ""
    532            this = self.sql(expression, "this")
    533            expressions = self.expressions(expression)
    534            collate = self.sql(expression, "collate")
    535            collate = f" COLLATE {collate}" if collate else ""
    536            global_ = "GLOBAL " if expression.args.get("global") else ""
    537            return f"{global_}{kind}{this}{expressions}{collate}"
    538
    539        def set_sql(self, expression):
    540            return f"SET {self.expressions(expression)}"

class MySQL(sqlglot.dialects.dialect.Dialect): View Source

    101class MySQL(Dialect):
    102    time_format = "'%Y-%m-%d %T'"
    103
    104    # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions
    105    time_mapping = {
    106        "%M": "%B",
    107        "%c": "%-m",
    108        "%e": "%-d",
    109        "%h": "%I",
    110        "%i": "%M",
    111        "%s": "%S",
    112        "%S": "%S",
    113        "%u": "%W",
    114        "%k": "%-H",
    115        "%l": "%-I",
    116        "%T": "%H:%M:%S",
    117    }
    118
    119    class Tokenizer(tokens.Tokenizer):
    120        QUOTES = ["'", '"']
    121        COMMENTS = ["--", "#", ("/*", "*/")]
    122        IDENTIFIERS = ["`"]
    123        STRING_ESCAPES = ["'", "\\"]
    124        BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
    125        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
    126
    127        KEYWORDS = {
    128            **tokens.Tokenizer.KEYWORDS,
    129            "MEDIUMTEXT": TokenType.MEDIUMTEXT,
    130            "LONGTEXT": TokenType.LONGTEXT,
    131            "MEDIUMBLOB": TokenType.MEDIUMBLOB,
    132            "LONGBLOB": TokenType.LONGBLOB,
    133            "START": TokenType.BEGIN,
    134            "SEPARATOR": TokenType.SEPARATOR,
    135            "_ARMSCII8": TokenType.INTRODUCER,
    136            "_ASCII": TokenType.INTRODUCER,
    137            "_BIG5": TokenType.INTRODUCER,
    138            "_BINARY": TokenType.INTRODUCER,
    139            "_CP1250": TokenType.INTRODUCER,
    140            "_CP1251": TokenType.INTRODUCER,
    141            "_CP1256": TokenType.INTRODUCER,
    142            "_CP1257": TokenType.INTRODUCER,
    143            "_CP850": TokenType.INTRODUCER,
    144            "_CP852": TokenType.INTRODUCER,
    145            "_CP866": TokenType.INTRODUCER,
    146            "_CP932": TokenType.INTRODUCER,
    147            "_DEC8": TokenType.INTRODUCER,
    148            "_EUCJPMS": TokenType.INTRODUCER,
    149            "_EUCKR": TokenType.INTRODUCER,
    150            "_GB18030": TokenType.INTRODUCER,
    151            "_GB2312": TokenType.INTRODUCER,
    152            "_GBK": TokenType.INTRODUCER,
    153            "_GEOSTD8": TokenType.INTRODUCER,
    154            "_GREEK": TokenType.INTRODUCER,
    155            "_HEBREW": TokenType.INTRODUCER,
    156            "_HP8": TokenType.INTRODUCER,
    157            "_KEYBCS2": TokenType.INTRODUCER,
    158            "_KOI8R": TokenType.INTRODUCER,
    159            "_KOI8U": TokenType.INTRODUCER,
    160            "_LATIN1": TokenType.INTRODUCER,
    161            "_LATIN2": TokenType.INTRODUCER,
    162            "_LATIN5": TokenType.INTRODUCER,
    163            "_LATIN7": TokenType.INTRODUCER,
    164            "_MACCE": TokenType.INTRODUCER,
    165            "_MACROMAN": TokenType.INTRODUCER,
    166            "_SJIS": TokenType.INTRODUCER,
    167            "_SWE7": TokenType.INTRODUCER,
    168            "_TIS620": TokenType.INTRODUCER,
    169            "_UCS2": TokenType.INTRODUCER,
    170            "_UJIS": TokenType.INTRODUCER,
    171            # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
    172            "_UTF8": TokenType.INTRODUCER,
    173            "_UTF16": TokenType.INTRODUCER,
    174            "_UTF16LE": TokenType.INTRODUCER,
    175            "_UTF32": TokenType.INTRODUCER,
    176            "_UTF8MB3": TokenType.INTRODUCER,
    177            "_UTF8MB4": TokenType.INTRODUCER,
    178            "@@": TokenType.SESSION_PARAMETER,
    179        }
    180
    181        COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SET, TokenType.SHOW}
    182
    183    class Parser(parser.Parser):
    184        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS, TokenType.SCHEMA, TokenType.DATABASE}  # type: ignore
    185
    186        FUNCTIONS = {
    187            **parser.Parser.FUNCTIONS,  # type: ignore
    188            "DATE_ADD": _date_add(exp.DateAdd),
    189            "DATE_SUB": _date_add(exp.DateSub),
    190            "STR_TO_DATE": _str_to_date,
    191            "LOCATE": locate_to_strposition,
    192            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    193            "LEFT": lambda args: exp.Substring(
    194                this=seq_get(args, 0), start=exp.Literal.number(1), length=seq_get(args, 1)
    195            ),
    196        }
    197
    198        FUNCTION_PARSERS = {
    199            **parser.Parser.FUNCTION_PARSERS,  # type: ignore
    200            "GROUP_CONCAT": lambda self: self.expression(
    201                exp.GroupConcat,
    202                this=self._parse_lambda(),
    203                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    204            ),
    205        }
    206
    207        PROPERTY_PARSERS = {
    208            **parser.Parser.PROPERTY_PARSERS,  # type: ignore
    209            "ENGINE": lambda self: self._parse_property_assignment(exp.EngineProperty),
    210        }
    211
    212        STATEMENT_PARSERS = {
    213            **parser.Parser.STATEMENT_PARSERS,  # type: ignore
    214            TokenType.SHOW: lambda self: self._parse_show(),
    215            TokenType.SET: lambda self: self._parse_set(),
    216        }
    217
    218        SHOW_PARSERS = {
    219            "BINARY LOGS": _show_parser("BINARY LOGS"),
    220            "MASTER LOGS": _show_parser("BINARY LOGS"),
    221            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    222            "CHARACTER SET": _show_parser("CHARACTER SET"),
    223            "CHARSET": _show_parser("CHARACTER SET"),
    224            "COLLATION": _show_parser("COLLATION"),
    225            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    226            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    227            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    228            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    229            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    230            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    231            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    232            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    233            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    234            "DATABASES": _show_parser("DATABASES"),
    235            "ENGINE": _show_parser("ENGINE", target=True),
    236            "STORAGE ENGINES": _show_parser("ENGINES"),
    237            "ENGINES": _show_parser("ENGINES"),
    238            "ERRORS": _show_parser("ERRORS"),
    239            "EVENTS": _show_parser("EVENTS"),
    240            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    241            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    242            "GRANTS": _show_parser("GRANTS", target="FOR"),
    243            "INDEX": _show_parser("INDEX", target="FROM"),
    244            "MASTER STATUS": _show_parser("MASTER STATUS"),
    245            "OPEN TABLES": _show_parser("OPEN TABLES"),
    246            "PLUGINS": _show_parser("PLUGINS"),
    247            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    248            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    249            "PRIVILEGES": _show_parser("PRIVILEGES"),
    250            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    251            "PROCESSLIST": _show_parser("PROCESSLIST"),
    252            "PROFILE": _show_parser("PROFILE"),
    253            "PROFILES": _show_parser("PROFILES"),
    254            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    255            "REPLICAS": _show_parser("REPLICAS"),
    256            "SLAVE HOSTS": _show_parser("REPLICAS"),
    257            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    258            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    259            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    260            "SESSION STATUS": _show_parser("STATUS"),
    261            "STATUS": _show_parser("STATUS"),
    262            "TABLE STATUS": _show_parser("TABLE STATUS"),
    263            "FULL TABLES": _show_parser("TABLES", full=True),
    264            "TABLES": _show_parser("TABLES"),
    265            "TRIGGERS": _show_parser("TRIGGERS"),
    266            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    267            "SESSION VARIABLES": _show_parser("VARIABLES"),
    268            "VARIABLES": _show_parser("VARIABLES"),
    269            "WARNINGS": _show_parser("WARNINGS"),
    270        }
    271
    272        SET_PARSERS = {
    273            "GLOBAL": lambda self: self._parse_set_item_assignment("GLOBAL"),
    274            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    275            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    276            "SESSION": lambda self: self._parse_set_item_assignment("SESSION"),
    277            "LOCAL": lambda self: self._parse_set_item_assignment("LOCAL"),
    278            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    279            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    280            "NAMES": lambda self: self._parse_set_item_names(),
    281            "TRANSACTION": lambda self: self._parse_set_transaction(),
    282        }
    283
    284        PROFILE_TYPES = {
    285            "ALL",
    286            "BLOCK IO",
    287            "CONTEXT SWITCHES",
    288            "CPU",
    289            "IPC",
    290            "MEMORY",
    291            "PAGE FAULTS",
    292            "SOURCE",
    293            "SWAPS",
    294        }
    295
    296        TRANSACTION_CHARACTERISTICS = {
    297            "ISOLATION LEVEL REPEATABLE READ",
    298            "ISOLATION LEVEL READ COMMITTED",
    299            "ISOLATION LEVEL READ UNCOMMITTED",
    300            "ISOLATION LEVEL SERIALIZABLE",
    301            "READ WRITE",
    302            "READ ONLY",
    303        }
    304
    305        INTEGER_DIVISION = False
    306
    307        def _parse_show_mysql(self, this, target=False, full=None, global_=None):
    308            if target:
    309                if isinstance(target, str):
    310                    self._match_text_seq(target)
    311                target_id = self._parse_id_var()
    312            else:
    313                target_id = None
    314
    315            log = self._parse_string() if self._match_text_seq("IN") else None
    316
    317            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    318                position = self._parse_number() if self._match_text_seq("FROM") else None
    319                db = None
    320            else:
    321                position = None
    322                db = self._parse_id_var() if self._match_text_seq("FROM") else None
    323
    324            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    325
    326            like = self._parse_string() if self._match_text_seq("LIKE") else None
    327            where = self._parse_where()
    328
    329            if this == "PROFILE":
    330                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    331                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    332                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    333                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    334            else:
    335                types, query = None, None
    336                offset, limit = self._parse_oldstyle_limit()
    337
    338            mutex = True if self._match_text_seq("MUTEX") else None
    339            mutex = False if self._match_text_seq("STATUS") else mutex
    340
    341            return self.expression(
    342                exp.Show,
    343                this=this,
    344                target=target_id,
    345                full=full,
    346                log=log,
    347                position=position,
    348                db=db,
    349                channel=channel,
    350                like=like,
    351                where=where,
    352                types=types,
    353                query=query,
    354                offset=offset,
    355                limit=limit,
    356                mutex=mutex,
    357                **{"global": global_},
    358            )
    359
    360        def _parse_var_from_options(self, options):
    361            for option in options:
    362                if self._match_text_seq(*option.split(" ")):
    363                    return exp.Var(this=option)
    364            return None
    365
    366        def _parse_oldstyle_limit(self):
    367            limit = None
    368            offset = None
    369            if self._match_text_seq("LIMIT"):
    370                parts = self._parse_csv(self._parse_number)
    371                if len(parts) == 1:
    372                    limit = parts[0]
    373                elif len(parts) == 2:
    374                    limit = parts[1]
    375                    offset = parts[0]
    376            return offset, limit
    377
    378        def _default_parse_set_item(self):
    379            return self._parse_set_item_assignment(kind=None)
    380
    381        def _parse_set_item_assignment(self, kind):
    382            if kind in {"GLOBAL", "SESSION"} and self._match_text_seq("TRANSACTION"):
    383                return self._parse_set_transaction(global_=kind == "GLOBAL")
    384
    385            left = self._parse_primary() or self._parse_id_var()
    386            if not self._match(TokenType.EQ):
    387                self.raise_error("Expected =")
    388            right = self._parse_statement() or self._parse_id_var()
    389
    390            this = self.expression(
    391                exp.EQ,
    392                this=left,
    393                expression=right,
    394            )
    395
    396            return self.expression(
    397                exp.SetItem,
    398                this=this,
    399                kind=kind,
    400            )
    401
    402        def _parse_set_item_charset(self, kind):
    403            this = self._parse_string() or self._parse_id_var()
    404
    405            return self.expression(
    406                exp.SetItem,
    407                this=this,
    408                kind=kind,
    409            )
    410
    411        def _parse_set_item_names(self):
    412            charset = self._parse_string() or self._parse_id_var()
    413            if self._match_text_seq("COLLATE"):
    414                collate = self._parse_string() or self._parse_id_var()
    415            else:
    416                collate = None
    417            return self.expression(
    418                exp.SetItem,
    419                this=charset,
    420                collate=collate,
    421                kind="NAMES",
    422            )
    423
    424        def _parse_set_transaction(self, global_=False):
    425            self._match_text_seq("TRANSACTION")
    426            characteristics = self._parse_csv(
    427                lambda: self._parse_var_from_options(self.TRANSACTION_CHARACTERISTICS)
    428            )
    429            return self.expression(
    430                exp.SetItem,
    431                expressions=characteristics,
    432                kind="TRANSACTION",
    433                **{"global": global_},
    434            )
    435
    436    class Generator(generator.Generator):
    437        LOCKING_READS_SUPPORTED = True
    438        NULL_ORDERING_SUPPORTED = False
    439        INTEGER_DIVISION = False
    440
    441        TRANSFORMS = {
    442            **generator.Generator.TRANSFORMS,  # type: ignore
    443            exp.CurrentDate: no_paren_current_date_sql,
    444            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
    445            exp.ILike: no_ilike_sql,
    446            exp.Min: min_or_least,
    447            exp.TableSample: no_tablesample_sql,
    448            exp.TryCast: no_trycast_sql,
    449            exp.DateAdd: _date_add_sql("ADD"),
    450            exp.DateSub: _date_add_sql("SUB"),
    451            exp.DateTrunc: _date_trunc_sql,
    452            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    453            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    454            exp.DayOfYear: rename_func("DAYOFYEAR"),
    455            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    456            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    457            exp.StrToDate: _str_to_date_sql,
    458            exp.StrToTime: _str_to_date_sql,
    459            exp.Trim: _trim_sql,
    460            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    461            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    462            exp.StrPosition: strposition_to_locate_sql,
    463        }
    464
    465        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    466        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    467        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    468        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    469        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    470
    471        PROPERTIES_LOCATION = {
    472            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    473            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    474        }
    475
    476        def show_sql(self, expression):
    477            this = f" {expression.name}"
    478            full = " FULL" if expression.args.get("full") else ""
    479            global_ = " GLOBAL" if expression.args.get("global") else ""
    480
    481            target = self.sql(expression, "target")
    482            target = f" {target}" if target else ""
    483            if expression.name in {"COLUMNS", "INDEX"}:
    484                target = f" FROM{target}"
    485            elif expression.name == "GRANTS":
    486                target = f" FOR{target}"
    487
    488            db = self._prefixed_sql("FROM", expression, "db")
    489
    490            like = self._prefixed_sql("LIKE", expression, "like")
    491            where = self.sql(expression, "where")
    492
    493            types = self.expressions(expression, key="types")
    494            types = f" {types}" if types else types
    495            query = self._prefixed_sql("FOR QUERY", expression, "query")
    496
    497            if expression.name == "PROFILE":
    498                offset = self._prefixed_sql("OFFSET", expression, "offset")
    499                limit = self._prefixed_sql("LIMIT", expression, "limit")
    500            else:
    501                offset = ""
    502                limit = self._oldstyle_limit_sql(expression)
    503
    504            log = self._prefixed_sql("IN", expression, "log")
    505            position = self._prefixed_sql("FROM", expression, "position")
    506
    507            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    508
    509            if expression.name == "ENGINE":
    510                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    511            else:
    512                mutex_or_status = ""
    513
    514            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    515
    516        def _prefixed_sql(self, prefix, expression, arg):
    517            sql = self.sql(expression, arg)
    518            if not sql:
    519                return ""
    520            return f" {prefix} {sql}"
    521
    522        def _oldstyle_limit_sql(self, expression):
    523            limit = self.sql(expression, "limit")
    524            offset = self.sql(expression, "offset")
    525            if limit:
    526                limit_offset = f"{offset}, {limit}" if offset else limit
    527                return f" LIMIT {limit_offset}"
    528            return ""
    529
    530        def setitem_sql(self, expression):
    531            kind = self.sql(expression, "kind")
    532            kind = f"{kind} " if kind else ""
    533            this = self.sql(expression, "this")
    534            expressions = self.expressions(expression)
    535            collate = self.sql(expression, "collate")
    536            collate = f" COLLATE {collate}" if collate else ""
    537            global_ = "GLOBAL " if expression.args.get("global") else ""
    538            return f"{global_}{kind}{this}{expressions}{collate}"
    539
    540        def set_sql(self, expression):
    541            return f"SET {self.expressions(expression)}"

##### Inherited Members

sqlglot.dialects.dialect.Dialect
  get_or_raise
  format_time
  parse
  parse_into
  generate
  transpile
  parser
  generator

class MySQL.Tokenizer(sqlglot.tokens.Tokenizer): View Source

    119    class Tokenizer(tokens.Tokenizer):
    120        QUOTES = ["'", '"']
    121        COMMENTS = ["--", "#", ("/*", "*/")]
    122        IDENTIFIERS = ["`"]
    123        STRING_ESCAPES = ["'", "\\"]
    124        BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
    125        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
    126
    127        KEYWORDS = {
    128            **tokens.Tokenizer.KEYWORDS,
    129            "MEDIUMTEXT": TokenType.MEDIUMTEXT,
    130            "LONGTEXT": TokenType.LONGTEXT,
    131            "MEDIUMBLOB": TokenType.MEDIUMBLOB,
    132            "LONGBLOB": TokenType.LONGBLOB,
    133            "START": TokenType.BEGIN,
    134            "SEPARATOR": TokenType.SEPARATOR,
    135            "_ARMSCII8": TokenType.INTRODUCER,
    136            "_ASCII": TokenType.INTRODUCER,
    137            "_BIG5": TokenType.INTRODUCER,
    138            "_BINARY": TokenType.INTRODUCER,
    139            "_CP1250": TokenType.INTRODUCER,
    140            "_CP1251": TokenType.INTRODUCER,
    141            "_CP1256": TokenType.INTRODUCER,
    142            "_CP1257": TokenType.INTRODUCER,
    143            "_CP850": TokenType.INTRODUCER,
    144            "_CP852": TokenType.INTRODUCER,
    145            "_CP866": TokenType.INTRODUCER,
    146            "_CP932": TokenType.INTRODUCER,
    147            "_DEC8": TokenType.INTRODUCER,
    148            "_EUCJPMS": TokenType.INTRODUCER,
    149            "_EUCKR": TokenType.INTRODUCER,
    150            "_GB18030": TokenType.INTRODUCER,
    151            "_GB2312": TokenType.INTRODUCER,
    152            "_GBK": TokenType.INTRODUCER,
    153            "_GEOSTD8": TokenType.INTRODUCER,
    154            "_GREEK": TokenType.INTRODUCER,
    155            "_HEBREW": TokenType.INTRODUCER,
    156            "_HP8": TokenType.INTRODUCER,
    157            "_KEYBCS2": TokenType.INTRODUCER,
    158            "_KOI8R": TokenType.INTRODUCER,
    159            "_KOI8U": TokenType.INTRODUCER,
    160            "_LATIN1": TokenType.INTRODUCER,
    161            "_LATIN2": TokenType.INTRODUCER,
    162            "_LATIN5": TokenType.INTRODUCER,
    163            "_LATIN7": TokenType.INTRODUCER,
    164            "_MACCE": TokenType.INTRODUCER,
    165            "_MACROMAN": TokenType.INTRODUCER,
    166            "_SJIS": TokenType.INTRODUCER,
    167            "_SWE7": TokenType.INTRODUCER,
    168            "_TIS620": TokenType.INTRODUCER,
    169            "_UCS2": TokenType.INTRODUCER,
    170            "_UJIS": TokenType.INTRODUCER,
    171            # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
    172            "_UTF8": TokenType.INTRODUCER,
    173            "_UTF16": TokenType.INTRODUCER,
    174            "_UTF16LE": TokenType.INTRODUCER,
    175            "_UTF32": TokenType.INTRODUCER,
    176            "_UTF8MB3": TokenType.INTRODUCER,
    177            "_UTF8MB4": TokenType.INTRODUCER,
    178            "@@": TokenType.SESSION_PARAMETER,
    179        }
    180
    181        COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SET, TokenType.SHOW}

##### Inherited Members

sqlglot.tokens.Tokenizer
  reset
  tokenize

class MySQL.Parser(sqlglot.parser.Parser): View Source

    183    class Parser(parser.Parser):
    184        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS, TokenType.SCHEMA, TokenType.DATABASE}  # type: ignore
    185
    186        FUNCTIONS = {
    187            **parser.Parser.FUNCTIONS,  # type: ignore
    188            "DATE_ADD": _date_add(exp.DateAdd),
    189            "DATE_SUB": _date_add(exp.DateSub),
    190            "STR_TO_DATE": _str_to_date,
    191            "LOCATE": locate_to_strposition,
    192            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    193            "LEFT": lambda args: exp.Substring(
    194                this=seq_get(args, 0), start=exp.Literal.number(1), length=seq_get(args, 1)
    195            ),
    196        }
    197
    198        FUNCTION_PARSERS = {
    199            **parser.Parser.FUNCTION_PARSERS,  # type: ignore
    200            "GROUP_CONCAT": lambda self: self.expression(
    201                exp.GroupConcat,
    202                this=self._parse_lambda(),
    203                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    204            ),
    205        }
    206
    207        PROPERTY_PARSERS = {
    208            **parser.Parser.PROPERTY_PARSERS,  # type: ignore
    209            "ENGINE": lambda self: self._parse_property_assignment(exp.EngineProperty),
    210        }
    211
    212        STATEMENT_PARSERS = {
    213            **parser.Parser.STATEMENT_PARSERS,  # type: ignore
    214            TokenType.SHOW: lambda self: self._parse_show(),
    215            TokenType.SET: lambda self: self._parse_set(),
    216        }
    217
    218        SHOW_PARSERS = {
    219            "BINARY LOGS": _show_parser("BINARY LOGS"),
    220            "MASTER LOGS": _show_parser("BINARY LOGS"),
    221            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    222            "CHARACTER SET": _show_parser("CHARACTER SET"),
    223            "CHARSET": _show_parser("CHARACTER SET"),
    224            "COLLATION": _show_parser("COLLATION"),
    225            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    226            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    227            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    228            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    229            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    230            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    231            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    232            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    233            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    234            "DATABASES": _show_parser("DATABASES"),
    235            "ENGINE": _show_parser("ENGINE", target=True),
    236            "STORAGE ENGINES": _show_parser("ENGINES"),
    237            "ENGINES": _show_parser("ENGINES"),
    238            "ERRORS": _show_parser("ERRORS"),
    239            "EVENTS": _show_parser("EVENTS"),
    240            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    241            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    242            "GRANTS": _show_parser("GRANTS", target="FOR"),
    243            "INDEX": _show_parser("INDEX", target="FROM"),
    244            "MASTER STATUS": _show_parser("MASTER STATUS"),
    245            "OPEN TABLES": _show_parser("OPEN TABLES"),
    246            "PLUGINS": _show_parser("PLUGINS"),
    247            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    248            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    249            "PRIVILEGES": _show_parser("PRIVILEGES"),
    250            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    251            "PROCESSLIST": _show_parser("PROCESSLIST"),
    252            "PROFILE": _show_parser("PROFILE"),
    253            "PROFILES": _show_parser("PROFILES"),
    254            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    255            "REPLICAS": _show_parser("REPLICAS"),
    256            "SLAVE HOSTS": _show_parser("REPLICAS"),
    257            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    258            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    259            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    260            "SESSION STATUS": _show_parser("STATUS"),
    261            "STATUS": _show_parser("STATUS"),
    262            "TABLE STATUS": _show_parser("TABLE STATUS"),
    263            "FULL TABLES": _show_parser("TABLES", full=True),
    264            "TABLES": _show_parser("TABLES"),
    265            "TRIGGERS": _show_parser("TRIGGERS"),
    266            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    267            "SESSION VARIABLES": _show_parser("VARIABLES"),
    268            "VARIABLES": _show_parser("VARIABLES"),
    269            "WARNINGS": _show_parser("WARNINGS"),
    270        }
    271
    272        SET_PARSERS = {
    273            "GLOBAL": lambda self: self._parse_set_item_assignment("GLOBAL"),
    274            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    275            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    276            "SESSION": lambda self: self._parse_set_item_assignment("SESSION"),
    277            "LOCAL": lambda self: self._parse_set_item_assignment("LOCAL"),
    278            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    279            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    280            "NAMES": lambda self: self._parse_set_item_names(),
    281            "TRANSACTION": lambda self: self._parse_set_transaction(),
    282        }
    283
    284        PROFILE_TYPES = {
    285            "ALL",
    286            "BLOCK IO",
    287            "CONTEXT SWITCHES",
    288            "CPU",
    289            "IPC",
    290            "MEMORY",
    291            "PAGE FAULTS",
    292            "SOURCE",
    293            "SWAPS",
    294        }
    295
    296        TRANSACTION_CHARACTERISTICS = {
    297            "ISOLATION LEVEL REPEATABLE READ",
    298            "ISOLATION LEVEL READ COMMITTED",
    299            "ISOLATION LEVEL READ UNCOMMITTED",
    300            "ISOLATION LEVEL SERIALIZABLE",
    301            "READ WRITE",
    302            "READ ONLY",
    303        }
    304
    305        INTEGER_DIVISION = False
    306
    307        def _parse_show_mysql(self, this, target=False, full=None, global_=None):
    308            if target:
    309                if isinstance(target, str):
    310                    self._match_text_seq(target)
    311                target_id = self._parse_id_var()
    312            else:
    313                target_id = None
    314
    315            log = self._parse_string() if self._match_text_seq("IN") else None
    316
    317            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    318                position = self._parse_number() if self._match_text_seq("FROM") else None
    319                db = None
    320            else:
    321                position = None
    322                db = self._parse_id_var() if self._match_text_seq("FROM") else None
    323
    324            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    325
    326            like = self._parse_string() if self._match_text_seq("LIKE") else None
    327            where = self._parse_where()
    328
    329            if this == "PROFILE":
    330                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    331                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    332                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    333                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    334            else:
    335                types, query = None, None
    336                offset, limit = self._parse_oldstyle_limit()
    337
    338            mutex = True if self._match_text_seq("MUTEX") else None
    339            mutex = False if self._match_text_seq("STATUS") else mutex
    340
    341            return self.expression(
    342                exp.Show,
    343                this=this,
    344                target=target_id,
    345                full=full,
    346                log=log,
    347                position=position,
    348                db=db,
    349                channel=channel,
    350                like=like,
    351                where=where,
    352                types=types,
    353                query=query,
    354                offset=offset,
    355                limit=limit,
    356                mutex=mutex,
    357                **{"global": global_},
    358            )
    359
    360        def _parse_var_from_options(self, options):
    361            for option in options:
    362                if self._match_text_seq(*option.split(" ")):
    363                    return exp.Var(this=option)
    364            return None
    365
    366        def _parse_oldstyle_limit(self):
    367            limit = None
    368            offset = None
    369            if self._match_text_seq("LIMIT"):
    370                parts = self._parse_csv(self._parse_number)
    371                if len(parts) == 1:
    372                    limit = parts[0]
    373                elif len(parts) == 2:
    374                    limit = parts[1]
    375                    offset = parts[0]
    376            return offset, limit
    377
    378        def _default_parse_set_item(self):
    379            return self._parse_set_item_assignment(kind=None)
    380
    381        def _parse_set_item_assignment(self, kind):
    382            if kind in {"GLOBAL", "SESSION"} and self._match_text_seq("TRANSACTION"):
    383                return self._parse_set_transaction(global_=kind == "GLOBAL")
    384
    385            left = self._parse_primary() or self._parse_id_var()
    386            if not self._match(TokenType.EQ):
    387                self.raise_error("Expected =")
    388            right = self._parse_statement() or self._parse_id_var()
    389
    390            this = self.expression(
    391                exp.EQ,
    392                this=left,
    393                expression=right,
    394            )
    395
    396            return self.expression(
    397                exp.SetItem,
    398                this=this,
    399                kind=kind,
    400            )
    401
    402        def _parse_set_item_charset(self, kind):
    403            this = self._parse_string() or self._parse_id_var()
    404
    405            return self.expression(
    406                exp.SetItem,
    407                this=this,
    408                kind=kind,
    409            )
    410
    411        def _parse_set_item_names(self):
    412            charset = self._parse_string() or self._parse_id_var()
    413            if self._match_text_seq("COLLATE"):
    414                collate = self._parse_string() or self._parse_id_var()
    415            else:
    416                collate = None
    417            return self.expression(
    418                exp.SetItem,
    419                this=charset,
    420                collate=collate,
    421                kind="NAMES",
    422            )
    423
    424        def _parse_set_transaction(self, global_=False):
    425            self._match_text_seq("TRANSACTION")
    426            characteristics = self._parse_csv(
    427                lambda: self._parse_var_from_options(self.TRANSACTION_CHARACTERISTICS)
    428            )
    429            return self.expression(
    430                exp.SetItem,
    431                expressions=characteristics,
    432                kind="TRANSACTION",
    433                **{"global": global_},
    434            )

Parser consumes a list of tokens produced by the `sqlglot.tokens.Tokenizer` and produces a parsed syntax tree.

###### Arguments:

- error_level: the desired error level. Default: ErrorLevel.RAISE
- error_message_context: determines the amount of context to capture from a query string when displaying the error message (in number of characters). Default: 50.
- index_offset: Index offset for arrays eg ARRAY[0] vs ARRAY[1] as the head of a list. Default: 0
- alias_post_tablesample: If the table alias comes after tablesample. Default: False
- max_errors: Maximum number of error messages to include in a raised ParseError. This is only relevant if error_level is ErrorLevel.RAISE. Default: 3
- null_ordering: Indicates the default null ordering method to use if not explicitly set. Options are "nulls_are_small", "nulls_are_large", "nulls_are_last". Default: "nulls_are_small"

##### Inherited Members

sqlglot.parser.Parser
  Parser
  reset
  parse
  parse_into
  check_errors
  raise_error
  expression
  validate_expression

class MySQL.Generator(sqlglot.generator.Generator): View Source

    436    class Generator(generator.Generator):
    437        LOCKING_READS_SUPPORTED = True
    438        NULL_ORDERING_SUPPORTED = False
    439        INTEGER_DIVISION = False
    440
    441        TRANSFORMS = {
    442            **generator.Generator.TRANSFORMS,  # type: ignore
    443            exp.CurrentDate: no_paren_current_date_sql,
    444            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
    445            exp.ILike: no_ilike_sql,
    446            exp.Min: min_or_least,
    447            exp.TableSample: no_tablesample_sql,
    448            exp.TryCast: no_trycast_sql,
    449            exp.DateAdd: _date_add_sql("ADD"),
    450            exp.DateSub: _date_add_sql("SUB"),
    451            exp.DateTrunc: _date_trunc_sql,
    452            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    453            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    454            exp.DayOfYear: rename_func("DAYOFYEAR"),
    455            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    456            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    457            exp.StrToDate: _str_to_date_sql,
    458            exp.StrToTime: _str_to_date_sql,
    459            exp.Trim: _trim_sql,
    460            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    461            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    462            exp.StrPosition: strposition_to_locate_sql,
    463        }
    464
    465        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    466        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    467        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    468        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    469        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    470
    471        PROPERTIES_LOCATION = {
    472            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    473            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    474        }
    475
    476        def show_sql(self, expression):
    477            this = f" {expression.name}"
    478            full = " FULL" if expression.args.get("full") else ""
    479            global_ = " GLOBAL" if expression.args.get("global") else ""
    480
    481            target = self.sql(expression, "target")
    482            target = f" {target}" if target else ""
    483            if expression.name in {"COLUMNS", "INDEX"}:
    484                target = f" FROM{target}"
    485            elif expression.name == "GRANTS":
    486                target = f" FOR{target}"
    487
    488            db = self._prefixed_sql("FROM", expression, "db")
    489
    490            like = self._prefixed_sql("LIKE", expression, "like")
    491            where = self.sql(expression, "where")
    492
    493            types = self.expressions(expression, key="types")
    494            types = f" {types}" if types else types
    495            query = self._prefixed_sql("FOR QUERY", expression, "query")
    496
    497            if expression.name == "PROFILE":
    498                offset = self._prefixed_sql("OFFSET", expression, "offset")
    499                limit = self._prefixed_sql("LIMIT", expression, "limit")
    500            else:
    501                offset = ""
    502                limit = self._oldstyle_limit_sql(expression)
    503
    504            log = self._prefixed_sql("IN", expression, "log")
    505            position = self._prefixed_sql("FROM", expression, "position")
    506
    507            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    508
    509            if expression.name == "ENGINE":
    510                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    511            else:
    512                mutex_or_status = ""
    513
    514            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    515
    516        def _prefixed_sql(self, prefix, expression, arg):
    517            sql = self.sql(expression, arg)
    518            if not sql:
    519                return ""
    520            return f" {prefix} {sql}"
    521
    522        def _oldstyle_limit_sql(self, expression):
    523            limit = self.sql(expression, "limit")
    524            offset = self.sql(expression, "offset")
    525            if limit:
    526                limit_offset = f"{offset}, {limit}" if offset else limit
    527                return f" LIMIT {limit_offset}"
    528            return ""
    529
    530        def setitem_sql(self, expression):
    531            kind = self.sql(expression, "kind")
    532            kind = f"{kind} " if kind else ""
    533            this = self.sql(expression, "this")
    534            expressions = self.expressions(expression)
    535            collate = self.sql(expression, "collate")
    536            collate = f" COLLATE {collate}" if collate else ""
    537            global_ = "GLOBAL " if expression.args.get("global") else ""
    538            return f"{global_}{kind}{this}{expressions}{collate}"
    539
    540        def set_sql(self, expression):
    541            return f"SET {self.expressions(expression)}"

Generator interprets the given syntax tree and produces a SQL string as an output.

###### Arguments:

- time_mapping (dict): the dictionary of custom time mappings in which the key represents a python time format and the output the target time format
- time_trie (trie): a trie of the time_mapping keys
- pretty (bool): if set to True the returned string will be formatted. Default: False.
- quote_start (str): specifies which starting character to use to delimit quotes. Default: '.
- quote_end (str): specifies which ending character to use to delimit quotes. Default: '.
- identifier_start (str): specifies which starting character to use to delimit identifiers. Default: ".
- identifier_end (str): specifies which ending character to use to delimit identifiers. Default: ".
- identify (bool): if set to True all identifiers will be delimited by the corresponding character.
- normalize (bool): if set to True all identifiers will lower cased
- string_escape (str): specifies a string escape character. Default: '.
- identifier_escape (str): specifies an identifier escape character. Default: ".
- pad (int): determines padding in a formatted string. Default: 2.
- indent (int): determines the size of indentation in a formatted string. Default: 4.
- unnest_column_only (bool): if true unnest table aliases are considered only as column aliases
- normalize_functions (str): normalize function names, "upper", "lower", or None Default: "upper"
- alias_post_tablesample (bool): if the table alias comes after tablesample Default: False
- unsupported_level (ErrorLevel): determines the generator's behavior when it encounters unsupported expressions. Default ErrorLevel.WARN.
- null_ordering (str): Indicates the default null ordering method to use if not explicitly set. Options are "nulls_are_small", "nulls_are_large", "nulls_are_last". Default: "nulls_are_small"
- max_unsupported (int): 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 (bool): if the the comma is leading or trailing in select statements 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 or not to preserve comments in the output SQL code. Default: True

def show_sql(self, expression): View Source

    476        def show_sql(self, expression):
    477            this = f" {expression.name}"
    478            full = " FULL" if expression.args.get("full") else ""
    479            global_ = " GLOBAL" if expression.args.get("global") else ""
    480
    481            target = self.sql(expression, "target")
    482            target = f" {target}" if target else ""
    483            if expression.name in {"COLUMNS", "INDEX"}:
    484                target = f" FROM{target}"
    485            elif expression.name == "GRANTS":
    486                target = f" FOR{target}"
    487
    488            db = self._prefixed_sql("FROM", expression, "db")
    489
    490            like = self._prefixed_sql("LIKE", expression, "like")
    491            where = self.sql(expression, "where")
    492
    493            types = self.expressions(expression, key="types")
    494            types = f" {types}" if types else types
    495            query = self._prefixed_sql("FOR QUERY", expression, "query")
    496
    497            if expression.name == "PROFILE":
    498                offset = self._prefixed_sql("OFFSET", expression, "offset")
    499                limit = self._prefixed_sql("LIMIT", expression, "limit")
    500            else:
    501                offset = ""
    502                limit = self._oldstyle_limit_sql(expression)
    503
    504            log = self._prefixed_sql("IN", expression, "log")
    505            position = self._prefixed_sql("FROM", expression, "position")
    506
    507            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    508
    509            if expression.name == "ENGINE":
    510                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    511            else:
    512                mutex_or_status = ""
    513
    514            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"

def setitem_sql(self, expression): View Source

    530        def setitem_sql(self, expression):
    531            kind = self.sql(expression, "kind")
    532            kind = f"{kind} " if kind else ""
    533            this = self.sql(expression, "this")
    534            expressions = self.expressions(expression)
    535            collate = self.sql(expression, "collate")
    536            collate = f" COLLATE {collate}" if collate else ""
    537            global_ = "GLOBAL " if expression.args.get("global") else ""
    538            return f"{global_}{kind}{this}{expressions}{collate}"

def set_sql(self, expression): View Source

    540        def set_sql(self, expression):
    541            return f"SET {self.expressions(expression)}"

##### Inherited Members

sqlglot.generator.Generator
  Generator
  generate
  unsupported
  sep
  seg
  pad_comment
  maybe_comment
  wrap
  no_identify
  normalize_func
  indent
  sql
  uncache_sql
  cache_sql
  characterset_sql
  column_sql
  columndef_sql
  columnconstraint_sql
  autoincrementcolumnconstraint_sql
  compresscolumnconstraint_sql
  generatedasidentitycolumnconstraint_sql
  notnullcolumnconstraint_sql
  primarykeycolumnconstraint_sql
  uniquecolumnconstraint_sql
  create_sql
  describe_sql
  prepend_ctes
  with_sql
  cte_sql
  tablealias_sql
  bitstring_sql
  hexstring_sql
  datatype_sql
  directory_sql
  delete_sql
  drop_sql
  except_sql
  except_op
  fetch_sql
  filter_sql
  hint_sql
  index_sql
  identifier_sql
  national_sql
  partition_sql
  properties_sql
  root_properties
  properties
  with_properties
  locate_properties
  property_sql
  likeproperty_sql
  fallbackproperty_sql
  journalproperty_sql
  freespaceproperty_sql
  afterjournalproperty_sql
  checksumproperty_sql
  mergeblockratioproperty_sql
  datablocksizeproperty_sql
  blockcompressionproperty_sql
  isolatedloadingproperty_sql
  lockingproperty_sql
  withdataproperty_sql
  insert_sql
  intersect_sql
  intersect_op
  introducer_sql
  pseudotype_sql
  returning_sql
  rowformatdelimitedproperty_sql
  table_sql
  tablesample_sql
  pivot_sql
  tuple_sql
  update_sql
  values_sql
  var_sql
  into_sql
  from_sql
  group_sql
  having_sql
  join_sql
  lambda_sql
  lateral_sql
  limit_sql
  offset_sql
  lock_sql
  literal_sql
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  query_modifiers
  select_sql
  schema_sql
  star_sql
  structkwarg_sql
  parameter_sql
  sessionparameter_sql
  placeholder_sql
  subquery_sql
  qualify_sql
  union_sql
  union_op
  unnest_sql
  where_sql
  window_sql
  partition_by_sql
  window_spec_sql
  withingroup_sql
  between_sql
  bracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  extract_sql
  trim_sql
  concat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  unique_sql
  if_sql
  in_sql
  in_unnest_op
  interval_sql
  return_sql
  reference_sql
  anonymous_sql
  paren_sql
  neg_sql
  not_sql
  alias_sql
  aliases_sql
  attimezone_sql
  add_sql
  and_sql
  connector_sql
  bitwiseand_sql
  bitwiseleftshift_sql
  bitwisenot_sql
  bitwiseor_sql
  bitwiserightshift_sql
  bitwisexor_sql
  cast_sql
  currentdate_sql
  collate_sql
  command_sql
  comment_sql
  transaction_sql
  commit_sql
  rollback_sql
  altercolumn_sql
  renametable_sql
  altertable_sql
  droppartition_sql
  addconstraint_sql
  distinct_sql
  ignorenulls_sql
  respectnulls_sql
  intdiv_sql
  dpipe_sql
  div_sql
  floatdiv_sql
  overlaps_sql
  distance_sql
  dot_sql
  eq_sql
  escape_sql
  glob_sql
  gt_sql
  gte_sql
  ilike_sql
  is_sql
  like_sql
  similarto_sql
  lt_sql
  lte_sql
  mod_sql
  mul_sql
  neq_sql
  nullsafeeq_sql
  nullsafeneq_sql
  or_sql
  slice_sql
  sub_sql
  trycast_sql
  use_sql
  binary
  function_fallback_sql
  func
  format_args
  text_width
  format_time
  expressions
  op_expressions
  naked_property
  set_operation
  tag_sql
  token_sql
  userdefinedfunction_sql
  joinhint_sql
  kwarg_sql
  when_sql
  merge_sql