summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-09-13 09:17:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-09-13 09:17:40 +0000
commitbdf5cc7bdd5ec93dc928d81e286f7b1e678ba19d (patch)
tree4d46f9407b792f6fd5d767d510e6865ec9640569 /sqlglot/dialects
parentReleasing progress-linux version 18.3.0-1. (diff)
downloadsqlglot-bdf5cc7bdd5ec93dc928d81e286f7b1e678ba19d.tar.xz
sqlglot-bdf5cc7bdd5ec93dc928d81e286f7b1e678ba19d.zip
Merging upstream version 18.4.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects')
-rw-r--r--sqlglot/dialects/clickhouse.py3
-rw-r--r--sqlglot/dialects/dialect.py16
-rw-r--r--sqlglot/dialects/duckdb.py1
-rw-r--r--sqlglot/dialects/mysql.py15
-rw-r--r--sqlglot/dialects/oracle.py45
-rw-r--r--sqlglot/dialects/redshift.py2
6 files changed, 77 insertions, 5 deletions
diff --git a/sqlglot/dialects/clickhouse.py b/sqlglot/dialects/clickhouse.py
index a38a239..4b36663 100644
--- a/sqlglot/dialects/clickhouse.py
+++ b/sqlglot/dialects/clickhouse.py
@@ -313,6 +313,8 @@ class ClickHouse(Dialect):
exp.DataType.Type.LONGTEXT: "String",
exp.DataType.Type.MEDIUMBLOB: "String",
exp.DataType.Type.MEDIUMTEXT: "String",
+ exp.DataType.Type.TINYBLOB: "String",
+ exp.DataType.Type.TINYTEXT: "String",
exp.DataType.Type.TEXT: "String",
exp.DataType.Type.VARBINARY: "String",
exp.DataType.Type.VARCHAR: "String",
@@ -331,6 +333,7 @@ class ClickHouse(Dialect):
exp.DataType.Type.FIXEDSTRING: "FixedString",
exp.DataType.Type.FLOAT: "Float32",
exp.DataType.Type.INT: "Int32",
+ exp.DataType.Type.MEDIUMINT: "Int32",
exp.DataType.Type.INT128: "Int128",
exp.DataType.Type.INT256: "Int256",
exp.DataType.Type.LOWCARDINALITY: "LowCardinality",
diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py
index 1bfbfef..ff22547 100644
--- a/sqlglot/dialects/dialect.py
+++ b/sqlglot/dialects/dialect.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import typing as t
from enum import Enum
+from functools import reduce
from sqlglot import exp
from sqlglot._typing import E
@@ -656,11 +657,18 @@ def ts_or_ds_to_date_sql(dialect: str) -> t.Callable:
def concat_to_dpipe_sql(self: Generator, expression: exp.Concat | exp.SafeConcat) -> str:
expression = expression.copy()
- this, *rest_args = expression.expressions
- for arg in rest_args:
- this = exp.DPipe(this=this, expression=arg)
+ return self.sql(reduce(lambda x, y: exp.DPipe(this=x, expression=y), expression.expressions))
- return self.sql(this)
+
+def concat_ws_to_dpipe_sql(self: Generator, expression: exp.ConcatWs) -> str:
+ expression = expression.copy()
+ delim, *rest_args = expression.expressions
+ return self.sql(
+ reduce(
+ lambda x, y: exp.DPipe(this=x, expression=exp.DPipe(this=delim, expression=y)),
+ rest_args,
+ )
+ )
def regexp_extract_sql(self: Generator, expression: exp.RegexpExtract) -> str:
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
index 684e35e..bf657ed 100644
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -291,6 +291,7 @@ class DuckDB(Dialect):
exp.UnixToStr: lambda self, e: f"STRFTIME(TO_TIMESTAMP({self.sql(e, 'this')}), {self.format_time(e)})",
exp.UnixToTime: rename_func("TO_TIMESTAMP"),
exp.UnixToTimeStr: lambda self, e: f"CAST(TO_TIMESTAMP({self.sql(e, 'this')}) AS TEXT)",
+ exp.VariancePop: rename_func("VAR_POP"),
exp.WeekOfYear: rename_func("WEEKOFYEAR"),
}
diff --git a/sqlglot/dialects/mysql.py b/sqlglot/dialects/mysql.py
index 6327796..46e3f19 100644
--- a/sqlglot/dialects/mysql.py
+++ b/sqlglot/dialects/mysql.py
@@ -119,7 +119,7 @@ class MySQL(Dialect):
QUOTES = ["'", '"']
COMMENTS = ["--", "#", ("/*", "*/")]
IDENTIFIERS = ["`"]
- STRING_ESCAPES = ["'", "\\"]
+ STRING_ESCAPES = ["'", '"', "\\"]
BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
@@ -132,6 +132,8 @@ class MySQL(Dialect):
"LONGBLOB": TokenType.LONGBLOB,
"LONGTEXT": TokenType.LONGTEXT,
"MEDIUMBLOB": TokenType.MEDIUMBLOB,
+ "TINYBLOB": TokenType.TINYBLOB,
+ "TINYTEXT": TokenType.TINYTEXT,
"MEDIUMTEXT": TokenType.MEDIUMTEXT,
"MEDIUMINT": TokenType.MEDIUMINT,
"MEMBER OF": TokenType.MEMBER_OF,
@@ -356,6 +358,15 @@ class MySQL(Dialect):
LOG_DEFAULTS_TO_LN = True
+ def _parse_primary_key_part(self) -> t.Optional[exp.Expression]:
+ this = self._parse_id_var()
+ if not self._match(TokenType.L_PAREN):
+ return this
+
+ expression = self._parse_number()
+ self._match_r_paren()
+ return self.expression(exp.ColumnPrefix, this=this, expression=expression)
+
def _parse_index_constraint(
self, kind: t.Optional[str] = None
) -> exp.IndexColumnConstraint:
@@ -577,8 +588,10 @@ class MySQL(Dialect):
TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
+ TYPE_MAPPING.pop(exp.DataType.Type.TINYTEXT)
TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
+ TYPE_MAPPING.pop(exp.DataType.Type.TINYBLOB)
PROPERTIES_LOCATION = {
**generator.Generator.PROPERTIES_LOCATION,
diff --git a/sqlglot/dialects/oracle.py b/sqlglot/dialects/oracle.py
index 279ed31..378df49 100644
--- a/sqlglot/dialects/oracle.py
+++ b/sqlglot/dialects/oracle.py
@@ -7,6 +7,9 @@ from sqlglot.dialects.dialect import Dialect, no_ilike_sql, rename_func, trim_sq
from sqlglot.helper import seq_get
from sqlglot.tokens import TokenType
+if t.TYPE_CHECKING:
+ from sqlglot._typing import E
+
def _parse_xml_table(self: Oracle.Parser) -> exp.XMLTable:
this = self._parse_string()
@@ -69,6 +72,16 @@ class Oracle(Dialect):
FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
**parser.Parser.FUNCTION_PARSERS,
+ "JSON_ARRAY": lambda self: self._parse_json_array(
+ exp.JSONArray,
+ expressions=self._parse_csv(lambda: self._parse_format_json(self._parse_bitwise())),
+ ),
+ "JSON_ARRAYAGG": lambda self: self._parse_json_array(
+ exp.JSONArrayAgg,
+ this=self._parse_format_json(self._parse_bitwise()),
+ order=self._parse_order(),
+ ),
+ "JSON_TABLE": lambda self: self._parse_json_table(),
"XMLTABLE": _parse_xml_table,
}
@@ -82,6 +95,38 @@ class Oracle(Dialect):
# Reference: https://stackoverflow.com/a/336455
DISTINCT_TOKENS = {TokenType.DISTINCT, TokenType.UNIQUE}
+ # Note: this is currently incomplete; it only implements the "JSON_value_column" part
+ def _parse_json_column_def(self) -> exp.JSONColumnDef:
+ this = self._parse_id_var()
+ kind = self._parse_types(allow_identifiers=False)
+ path = self._match_text_seq("PATH") and self._parse_string()
+ return self.expression(exp.JSONColumnDef, this=this, kind=kind, path=path)
+
+ def _parse_json_table(self) -> exp.JSONTable:
+ this = self._parse_format_json(self._parse_bitwise())
+ path = self._match(TokenType.COMMA) and self._parse_string()
+ error_handling = self._parse_on_handling("ERROR", "ERROR", "NULL")
+ empty_handling = self._parse_on_handling("EMPTY", "ERROR", "NULL")
+ self._match(TokenType.COLUMN)
+ expressions = self._parse_wrapped_csv(self._parse_json_column_def, optional=True)
+
+ return exp.JSONTable(
+ this=this,
+ expressions=expressions,
+ path=path,
+ error_handling=error_handling,
+ empty_handling=empty_handling,
+ )
+
+ def _parse_json_array(self, expr_type: t.Type[E], **kwargs) -> E:
+ return self.expression(
+ expr_type,
+ null_handling=self._parse_on_handling("NULL", "NULL", "ABSENT"),
+ return_type=self._match_text_seq("RETURNING") and self._parse_type(),
+ strict=self._match_text_seq("STRICT"),
+ **kwargs,
+ )
+
def _parse_column(self) -> t.Optional[exp.Expression]:
column = super()._parse_column()
if column:
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py
index 351c5df..554cbd3 100644
--- a/sqlglot/dialects/redshift.py
+++ b/sqlglot/dialects/redshift.py
@@ -5,6 +5,7 @@ import typing as t
from sqlglot import exp, transforms
from sqlglot.dialects.dialect import (
concat_to_dpipe_sql,
+ concat_ws_to_dpipe_sql,
rename_func,
ts_or_ds_to_date_sql,
)
@@ -123,6 +124,7 @@ class Redshift(Postgres):
TRANSFORMS = {
**Postgres.Generator.TRANSFORMS,
exp.Concat: concat_to_dpipe_sql,
+ exp.ConcatWs: concat_ws_to_dpipe_sql,
exp.CurrentTimestamp: lambda self, e: "SYSDATE",
exp.DateAdd: lambda self, e: self.func(
"DATEADD", exp.var(e.text("unit") or "day"), e.expression, e.this