summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-25 07:53:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-25 07:53:30 +0000
commite51d429336ceef2172126778e03e855447c4f681 (patch)
tree1d2cde90eea69620352b50b4ced088edddad04eb
parentAdding upstream version 6.2.0. (diff)
downloadsqlglot-e51d429336ceef2172126778e03e855447c4f681.tar.xz
sqlglot-e51d429336ceef2172126778e03e855447c4f681.zip
Adding upstream version 6.2.1.upstream/6.2.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--sqlglot/__init__.py2
-rw-r--r--sqlglot/expressions.py6
-rw-r--r--tests/test_expressions.py31
3 files changed, 37 insertions, 2 deletions
diff --git a/sqlglot/__init__.py b/sqlglot/__init__.py
index 44d349b..9ac1759 100644
--- a/sqlglot/__init__.py
+++ b/sqlglot/__init__.py
@@ -20,7 +20,7 @@ from sqlglot.generator import Generator
from sqlglot.parser import Parser
from sqlglot.tokens import Tokenizer, TokenType
-__version__ = "6.2.0"
+__version__ = "6.2.1"
pretty = False
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index 9299132..de615d6 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -912,14 +912,18 @@ class Properties(Expression):
@staticmethod
def _convert_value(value):
+ if value is None:
+ return NULL
if isinstance(value, Expression):
return value
+ if isinstance(value, bool):
+ return Boolean(this=value)
if isinstance(value, str):
return Literal.string(value)
if isinstance(value, numbers.Number):
return Literal.number(value)
if isinstance(value, list):
- return Tuple(expressions=[_convert_value(v) for v in value])
+ return Tuple(expressions=[Properties._convert_value(v) for v in value])
raise ValueError(f"Unsupported type '{type(value)}' for value '{value}'")
diff --git a/tests/test_expressions.py b/tests/test_expressions.py
index 59d584c..64ad02d 100644
--- a/tests/test_expressions.py
+++ b/tests/test_expressions.py
@@ -414,3 +414,34 @@ class TestExpressions(unittest.TestCase):
self.assertEqual(parse_one("heLLO()").sql(normalize_functions=None), "heLLO()")
self.assertEqual(parse_one("SUM(x)").sql(normalize_functions="lower"), "sum(x)")
self.assertEqual(parse_one("sum(x)").sql(normalize_functions="upper"), "SUM(x)")
+
+ def test_properties_from_dict(self):
+ self.assertEqual(
+ exp.Properties.from_dict(
+ {
+ "FORMAT": "parquet",
+ "PARTITIONED_BY": [exp.to_identifier("a"), exp.to_identifier("b")],
+ "custom": 1,
+ "TABLE_FORMAT": exp.to_identifier("test_format"),
+ "ENGINE": None,
+ "COLLATE": True,
+ }
+ ),
+ exp.Properties(
+ expressions=[
+ exp.FileFormatProperty(this=exp.Literal.string("FORMAT"), value=exp.Literal.string("parquet")),
+ exp.PartitionedByProperty(
+ this=exp.Literal.string("PARTITIONED_BY"),
+ value=exp.Tuple(expressions=[exp.to_identifier("a"), exp.to_identifier("b")]),
+ ),
+ exp.AnonymousProperty(this=exp.Literal.string("custom"), value=exp.Literal.number(1)),
+ exp.TableFormatProperty(
+ this=exp.Literal.string("TABLE_FORMAT"), value=exp.to_identifier("test_format")
+ ),
+ exp.EngineProperty(this=exp.Literal.string("ENGINE"), value=exp.NULL),
+ exp.CollateProperty(this=exp.Literal.string("COLLATE"), value=exp.TRUE),
+ ]
+ ),
+ )
+
+ self.assertRaises(ValueError, exp.Properties.from_dict, {"FORMAT": {"key": "value"}})