From b737ee75da2515a4a53956e41ae85e29dd67f21d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 6 Aug 2023 09:48:08 +0200 Subject: Adding upstream version 17.9.1. Signed-off-by: Daniel Baumann --- docs/sqlglot.html | 349 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 178 insertions(+), 171 deletions(-) (limited to 'docs/sqlglot.html') diff --git a/docs/sqlglot.html b/docs/sqlglot.html index b59ef04..797f8a0 100644 --- a/docs/sqlglot.html +++ b/docs/sqlglot.html @@ -96,7 +96,7 @@

SQLGlot logo

-

SQLGlot is a no-dependency SQL parser, transpiler, optimizer, and engine. It can be used to format SQL or translate between 19 different dialects like DuckDB, Presto, Spark, Snowflake, and BigQuery. It aims to read a wide variety of SQL inputs and output syntactically correct SQL in the targeted dialects.

+

SQLGlot is a no-dependency SQL parser, transpiler, optimizer, and engine. It can be used to format SQL or translate between 19 different dialects like DuckDB, Presto, Spark, Snowflake, and BigQuery. It aims to read a wide variety of SQL inputs and output syntactically and semantically correct SQL in the targeted dialects.

It is a very comprehensive generic SQL parser with a robust test suite. It is also quite performant, while being written purely in Python.

@@ -227,7 +227,7 @@
-

Comments are also preserved in a best-effort basis when transpiling SQL code:

+

Comments are also preserved on a best-effort basis when transpiling SQL code:

sql = """
@@ -742,97 +742,100 @@ make check  # Full test suite & linter checks
  67"""The default schema used by SQLGlot (e.g. in the optimizer)."""
  68
  69
- 70def parse(sql: str, read: DialectType = None, **opts) -> t.List[t.Optional[Expression]]:
- 71    """
- 72    Parses the given SQL string into a collection of syntax trees, one per parsed SQL statement.
- 73
- 74    Args:
- 75        sql: the SQL code string to parse.
- 76        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
- 77        **opts: other `sqlglot.parser.Parser` options.
- 78
- 79    Returns:
- 80        The resulting syntax tree collection.
- 81    """
- 82    dialect = Dialect.get_or_raise(read)()
- 83    return dialect.parse(sql, **opts)
- 84
- 85
- 86@t.overload
- 87def parse_one(sql: str, *, into: t.Type[E], **opts) -> E:
- 88    ...
- 89
- 90
- 91@t.overload
- 92def parse_one(sql: str, **opts) -> Expression:
- 93    ...
- 94
- 95
- 96def parse_one(
- 97    sql: str,
- 98    read: DialectType = None,
- 99    dialect: DialectType = None,
-100    into: t.Optional[exp.IntoType] = None,
-101    **opts,
-102) -> Expression:
-103    """
-104    Parses the given SQL string and returns a syntax tree for the first parsed SQL statement.
-105
-106    Args:
-107        sql: the SQL code string to parse.
-108        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
-109        dialect: the SQL dialect (alias for read)
-110        into: the SQLGlot Expression to parse into.
-111        **opts: other `sqlglot.parser.Parser` options.
-112
-113    Returns:
-114        The syntax tree for the first parsed statement.
-115    """
-116
-117    dialect = Dialect.get_or_raise(read or dialect)()
-118
-119    if into:
-120        result = dialect.parse_into(into, sql, **opts)
-121    else:
-122        result = dialect.parse(sql, **opts)
-123
-124    for expression in result:
-125        if not expression:
-126            raise ParseError(f"No expression was parsed from '{sql}'")
-127        return expression
-128    else:
-129        raise ParseError(f"No expression was parsed from '{sql}'")
-130
-131
-132def transpile(
-133    sql: str,
-134    read: DialectType = None,
-135    write: DialectType = None,
-136    identity: bool = True,
-137    error_level: t.Optional[ErrorLevel] = None,
-138    **opts,
-139) -> t.List[str]:
-140    """
-141    Parses the given SQL string in accordance with the source dialect and returns a list of SQL strings transformed
-142    to conform to the target dialect. Each string in the returned list represents a single transformed SQL statement.
-143
-144    Args:
-145        sql: the SQL code string to transpile.
-146        read: the source dialect used to parse the input string (eg. "spark", "hive", "presto", "mysql").
-147        write: the target dialect into which the input should be transformed (eg. "spark", "hive", "presto", "mysql").
-148        identity: if set to `True` and if the target dialect is not specified the source dialect will be used as both:
-149            the source and the target dialect.
-150        error_level: the desired error level of the parser.
-151        **opts: other `sqlglot.generator.Generator` options.
-152
-153    Returns:
-154        The list of transpiled SQL statements.
-155    """
-156    write = (read if write is None else write) if identity else write
-157    return [
-158        Dialect.get_or_raise(write)().generate(expression, **opts)
-159        for expression in parse(sql, read, error_level=error_level)
-160    ]
+ 70def parse(
+ 71    sql: str, read: DialectType = None, dialect: DialectType = None, **opts
+ 72) -> t.List[t.Optional[Expression]]:
+ 73    """
+ 74    Parses the given SQL string into a collection of syntax trees, one per parsed SQL statement.
+ 75
+ 76    Args:
+ 77        sql: the SQL code string to parse.
+ 78        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
+ 79        dialect: the SQL dialect (alias for read).
+ 80        **opts: other `sqlglot.parser.Parser` options.
+ 81
+ 82    Returns:
+ 83        The resulting syntax tree collection.
+ 84    """
+ 85    dialect = Dialect.get_or_raise(read or dialect)()
+ 86    return dialect.parse(sql, **opts)
+ 87
+ 88
+ 89@t.overload
+ 90def parse_one(sql: str, *, into: t.Type[E], **opts) -> E:
+ 91    ...
+ 92
+ 93
+ 94@t.overload
+ 95def parse_one(sql: str, **opts) -> Expression:
+ 96    ...
+ 97
+ 98
+ 99def parse_one(
+100    sql: str,
+101    read: DialectType = None,
+102    dialect: DialectType = None,
+103    into: t.Optional[exp.IntoType] = None,
+104    **opts,
+105) -> Expression:
+106    """
+107    Parses the given SQL string and returns a syntax tree for the first parsed SQL statement.
+108
+109    Args:
+110        sql: the SQL code string to parse.
+111        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
+112        dialect: the SQL dialect (alias for read)
+113        into: the SQLGlot Expression to parse into.
+114        **opts: other `sqlglot.parser.Parser` options.
+115
+116    Returns:
+117        The syntax tree for the first parsed statement.
+118    """
+119
+120    dialect = Dialect.get_or_raise(read or dialect)()
+121
+122    if into:
+123        result = dialect.parse_into(into, sql, **opts)
+124    else:
+125        result = dialect.parse(sql, **opts)
+126
+127    for expression in result:
+128        if not expression:
+129            raise ParseError(f"No expression was parsed from '{sql}'")
+130        return expression
+131    else:
+132        raise ParseError(f"No expression was parsed from '{sql}'")
+133
+134
+135def transpile(
+136    sql: str,
+137    read: DialectType = None,
+138    write: DialectType = None,
+139    identity: bool = True,
+140    error_level: t.Optional[ErrorLevel] = None,
+141    **opts,
+142) -> t.List[str]:
+143    """
+144    Parses the given SQL string in accordance with the source dialect and returns a list of SQL strings transformed
+145    to conform to the target dialect. Each string in the returned list represents a single transformed SQL statement.
+146
+147    Args:
+148        sql: the SQL code string to transpile.
+149        read: the source dialect used to parse the input string (eg. "spark", "hive", "presto", "mysql").
+150        write: the target dialect into which the input should be transformed (eg. "spark", "hive", "presto", "mysql").
+151        identity: if set to `True` and if the target dialect is not specified the source dialect will be used as both:
+152            the source and the target dialect.
+153        error_level: the desired error level of the parser.
+154        **opts: other `sqlglot.generator.Generator` options.
+155
+156    Returns:
+157        The list of transpiled SQL statements.
+158    """
+159    write = (read if write is None else write) if identity else write
+160    return [
+161        Dialect.get_or_raise(write)().generate(expression, **opts)
+162        for expression in parse(sql, read, error_level=error_level)
+163    ]
 
@@ -882,26 +885,29 @@ make check # Full test suite & linter checks
def - parse( sql: str, read: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, **opts) -> List[Optional[sqlglot.expressions.Expression]]: + parse( sql: str, read: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, **opts) -> List[Optional[sqlglot.expressions.Expression]]:
-
71def parse(sql: str, read: DialectType = None, **opts) -> t.List[t.Optional[Expression]]:
-72    """
-73    Parses the given SQL string into a collection of syntax trees, one per parsed SQL statement.
-74
-75    Args:
-76        sql: the SQL code string to parse.
-77        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
-78        **opts: other `sqlglot.parser.Parser` options.
-79
-80    Returns:
-81        The resulting syntax tree collection.
-82    """
-83    dialect = Dialect.get_or_raise(read)()
-84    return dialect.parse(sql, **opts)
+            
71def parse(
+72    sql: str, read: DialectType = None, dialect: DialectType = None, **opts
+73) -> t.List[t.Optional[Expression]]:
+74    """
+75    Parses the given SQL string into a collection of syntax trees, one per parsed SQL statement.
+76
+77    Args:
+78        sql: the SQL code string to parse.
+79        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
+80        dialect: the SQL dialect (alias for read).
+81        **opts: other `sqlglot.parser.Parser` options.
+82
+83    Returns:
+84        The resulting syntax tree collection.
+85    """
+86    dialect = Dialect.get_or_raise(read or dialect)()
+87    return dialect.parse(sql, **opts)
 
@@ -912,6 +918,7 @@ make check # Full test suite & linter checks
  • sql: the SQL code string to parse.
  • read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
  • +
  • dialect: the SQL dialect (alias for read).
  • **opts: other sqlglot.parser.Parser options.
@@ -935,40 +942,40 @@ make check # Full test suite & linter checks
-
 97def parse_one(
- 98    sql: str,
- 99    read: DialectType = None,
-100    dialect: DialectType = None,
-101    into: t.Optional[exp.IntoType] = None,
-102    **opts,
-103) -> Expression:
-104    """
-105    Parses the given SQL string and returns a syntax tree for the first parsed SQL statement.
-106
-107    Args:
-108        sql: the SQL code string to parse.
-109        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
-110        dialect: the SQL dialect (alias for read)
-111        into: the SQLGlot Expression to parse into.
-112        **opts: other `sqlglot.parser.Parser` options.
-113
-114    Returns:
-115        The syntax tree for the first parsed statement.
-116    """
-117
-118    dialect = Dialect.get_or_raise(read or dialect)()
-119
-120    if into:
-121        result = dialect.parse_into(into, sql, **opts)
-122    else:
-123        result = dialect.parse(sql, **opts)
-124
-125    for expression in result:
-126        if not expression:
-127            raise ParseError(f"No expression was parsed from '{sql}'")
-128        return expression
-129    else:
-130        raise ParseError(f"No expression was parsed from '{sql}'")
+            
100def parse_one(
+101    sql: str,
+102    read: DialectType = None,
+103    dialect: DialectType = None,
+104    into: t.Optional[exp.IntoType] = None,
+105    **opts,
+106) -> Expression:
+107    """
+108    Parses the given SQL string and returns a syntax tree for the first parsed SQL statement.
+109
+110    Args:
+111        sql: the SQL code string to parse.
+112        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
+113        dialect: the SQL dialect (alias for read)
+114        into: the SQLGlot Expression to parse into.
+115        **opts: other `sqlglot.parser.Parser` options.
+116
+117    Returns:
+118        The syntax tree for the first parsed statement.
+119    """
+120
+121    dialect = Dialect.get_or_raise(read or dialect)()
+122
+123    if into:
+124        result = dialect.parse_into(into, sql, **opts)
+125    else:
+126        result = dialect.parse(sql, **opts)
+127
+128    for expression in result:
+129        if not expression:
+130            raise ParseError(f"No expression was parsed from '{sql}'")
+131        return expression
+132    else:
+133        raise ParseError(f"No expression was parsed from '{sql}'")
 
@@ -1004,35 +1011,35 @@ make check # Full test suite & linter checks
-
133def transpile(
-134    sql: str,
-135    read: DialectType = None,
-136    write: DialectType = None,
-137    identity: bool = True,
-138    error_level: t.Optional[ErrorLevel] = None,
-139    **opts,
-140) -> t.List[str]:
-141    """
-142    Parses the given SQL string in accordance with the source dialect and returns a list of SQL strings transformed
-143    to conform to the target dialect. Each string in the returned list represents a single transformed SQL statement.
-144
-145    Args:
-146        sql: the SQL code string to transpile.
-147        read: the source dialect used to parse the input string (eg. "spark", "hive", "presto", "mysql").
-148        write: the target dialect into which the input should be transformed (eg. "spark", "hive", "presto", "mysql").
-149        identity: if set to `True` and if the target dialect is not specified the source dialect will be used as both:
-150            the source and the target dialect.
-151        error_level: the desired error level of the parser.
-152        **opts: other `sqlglot.generator.Generator` options.
-153
-154    Returns:
-155        The list of transpiled SQL statements.
-156    """
-157    write = (read if write is None else write) if identity else write
-158    return [
-159        Dialect.get_or_raise(write)().generate(expression, **opts)
-160        for expression in parse(sql, read, error_level=error_level)
-161    ]
+            
136def transpile(
+137    sql: str,
+138    read: DialectType = None,
+139    write: DialectType = None,
+140    identity: bool = True,
+141    error_level: t.Optional[ErrorLevel] = None,
+142    **opts,
+143) -> t.List[str]:
+144    """
+145    Parses the given SQL string in accordance with the source dialect and returns a list of SQL strings transformed
+146    to conform to the target dialect. Each string in the returned list represents a single transformed SQL statement.
+147
+148    Args:
+149        sql: the SQL code string to transpile.
+150        read: the source dialect used to parse the input string (eg. "spark", "hive", "presto", "mysql").
+151        write: the target dialect into which the input should be transformed (eg. "spark", "hive", "presto", "mysql").
+152        identity: if set to `True` and if the target dialect is not specified the source dialect will be used as both:
+153            the source and the target dialect.
+154        error_level: the desired error level of the parser.
+155        **opts: other `sqlglot.generator.Generator` options.
+156
+157    Returns:
+158        The list of transpiled SQL statements.
+159    """
+160    write = (read if write is None else write) if identity else write
+161    return [
+162        Dialect.get_or_raise(write)().generate(expression, **opts)
+163        for expression in parse(sql, read, error_level=error_level)
+164    ]
 
-- cgit v1.2.3