diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py index 4fca719442..e568b6d951 100644 --- a/sqlglot/expressions.py +++ b/sqlglot/expressions.py @@ -1035,6 +1035,7 @@ class Clone(Expression): "this": True, "when": False, "kind": False, + "shallow": False, "expression": False, } diff --git a/sqlglot/generator.py b/sqlglot/generator.py index 5ae4538c79..c3fa3200a5 100644 --- a/sqlglot/generator.py +++ b/sqlglot/generator.py @@ -793,14 +793,16 @@ def create_sql(self, expression: exp.Create) -> str: def clone_sql(self, expression: exp.Clone) -> str: this = self.sql(expression, "this") + shallow = "SHALLOW " if expression.args.get("shallow") else "" + this = f"{shallow}CLONE {this}" when = self.sql(expression, "when") if when: kind = self.sql(expression, "kind") expr = self.sql(expression, "expression") - return f"CLONE {this} {when} ({kind} => {expr})" + return f"{this} {when} ({kind} => {expr})" - return f"CLONE {this}" + return this def describe_sql(self, expression: exp.Describe) -> str: return f"DESCRIBE {self.sql(expression, 'this')}" diff --git a/sqlglot/parser.py b/sqlglot/parser.py index ab6fb999b7..a50ef69638 100644 --- a/sqlglot/parser.py +++ b/sqlglot/parser.py @@ -1303,6 +1303,8 @@ def extend_props(temp_props: t.Optional[exp.Properties]) -> None: if self._match_text_seq("WITH", "NO", "SCHEMA", "BINDING"): no_schema_binding = True + shallow = self._match_text_seq("SHALLOW") + if self._match_text_seq("CLONE"): clone = self._parse_table(schema=True) when = self._match_texts({"AT", "BEFORE"}) and self._prev.text.upper() @@ -1314,7 +1316,12 @@ def extend_props(temp_props: t.Optional[exp.Properties]) -> None: clone_expression = self._match(TokenType.FARROW) and self._parse_bitwise() self._match(TokenType.R_PAREN) clone = self.expression( - exp.Clone, this=clone, when=when, kind=clone_kind, expression=clone_expression + exp.Clone, + this=clone, + when=when, + kind=clone_kind, + shallow=shallow, + expression=clone_expression, ) return self.expression( diff --git a/tests/dialects/test_databricks.py b/tests/dialects/test_databricks.py index 38a7952386..f13d0f2b76 100644 --- a/tests/dialects/test_databricks.py +++ b/tests/dialects/test_databricks.py @@ -5,6 +5,7 @@ class TestDatabricks(Validator): dialect = "databricks" def test_databricks(self): + self.validate_identity("CREATE TABLE target SHALLOW CLONE source") self.validate_identity("INSERT INTO a REPLACE WHERE cond VALUES (1), (2)") self.validate_identity("SELECT c1 : price") self.validate_identity("CREATE FUNCTION a.b(x INT) RETURNS INT RETURN x + 1")