Skip to content

Commit eb0a989

Browse files
authored
feat!: support udf environment property (#5045)
* feat!: support udf environment property * fix test typo * refactor environment gen
1 parent 9b871d5 commit eb0a989

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

sqlglot/expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,10 @@ class LanguageProperty(Property):
28692869
arg_types = {"this": True}
28702870

28712871

2872+
class EnviromentProperty(Property):
2873+
arg_types = {"expressions": True}
2874+
2875+
28722876
# spark ddl
28732877
class ClusteredByProperty(Property):
28742878
arg_types = {"expressions": True, "sorted_by": False, "buckets": True}

sqlglot/generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class Generator(metaclass=_Generator):
139139
exp.DynamicProperty: lambda *_: "DYNAMIC",
140140
exp.EmptyProperty: lambda *_: "EMPTY",
141141
exp.EncodeColumnConstraint: lambda self, e: f"ENCODE {self.sql(e, 'this')}",
142+
exp.EnviromentProperty: lambda self, e: f"ENVIRONMENT ({self.expressions(e, flat=True)})",
142143
exp.EphemeralColumnConstraint: lambda self,
143144
e: f"EPHEMERAL{(' ' + self.sql(e, 'this')) if e.this else ''}",
144145
exp.ExcludeColumnConstraint: lambda self, e: f"EXCLUDE {self.sql(e, 'this').lstrip()}",
@@ -543,6 +544,7 @@ class Generator(metaclass=_Generator):
543544
exp.EmptyProperty: exp.Properties.Location.POST_SCHEMA,
544545
exp.EncodeProperty: exp.Properties.Location.POST_EXPRESSION,
545546
exp.EngineProperty: exp.Properties.Location.POST_SCHEMA,
547+
exp.EnviromentProperty: exp.Properties.Location.POST_SCHEMA,
546548
exp.ExecuteAsProperty: exp.Properties.Location.POST_SCHEMA,
547549
exp.ExternalProperty: exp.Properties.Location.POST_CREATE,
548550
exp.FallbackProperty: exp.Properties.Location.POST_NAME,

sqlglot/parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,9 @@ class Parser(metaclass=_Parser):
963963
"DISTSTYLE": lambda self: self._parse_property_assignment(exp.DistStyleProperty),
964964
"EMPTY": lambda self: self.expression(exp.EmptyProperty),
965965
"ENGINE": lambda self: self._parse_property_assignment(exp.EngineProperty),
966+
"ENVIRONMENT": lambda self: self.expression(
967+
exp.EnviromentProperty, expressions=self._parse_wrapped_csv(self._parse_assignment)
968+
),
966969
"EXECUTE": lambda self: self._parse_property_assignment(exp.ExecuteAsProperty),
967970
"EXTERNAL": lambda self: self.expression(exp.ExternalProperty),
968971
"FALLBACK": lambda self, **kwargs: self._parse_fallback(**kwargs),

tests/dialects/test_databricks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,8 @@ def test_analyze(self):
338338
self.validate_identity(
339339
"ANALYZE TABLE ctlg.db.tbl PARTITION(foo = 'foo', bar = 'bar') COMPUTE STATISTICS NOSCAN"
340340
)
341+
342+
def test_udf_environment_property(self):
343+
self.validate_identity(
344+
"""CREATE FUNCTION a() ENVIRONMENT (dependencies = '["foo1==1", "foo2==2"]', environment_version = 'None')"""
345+
)

0 commit comments

Comments
 (0)