Skip to content

Commit

Permalink
Refactor: fix mutation bug in Column.to_dot, simplify Dot.build (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Sep 12, 2023
1 parent 5d0559b commit 7ae5a94
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from collections import deque
from copy import deepcopy
from enum import auto
from functools import reduce

from sqlglot._typing import E
from sqlglot.errors import ParseError
Expand Down Expand Up @@ -1170,7 +1171,7 @@ def to_dot(self) -> Dot:
parts.append(parent.expression)
parent = parent.parent

return Dot.build(parts)
return Dot.build(deepcopy(parts))


class ColumnPosition(Expression):
Expand Down Expand Up @@ -3795,13 +3796,7 @@ def build(self, expressions: t.Sequence[Expression]) -> Dot:
if len(expressions) < 2:
raise ValueError(f"Dot requires >= 2 expressions.")

a, b, *expressions = expressions
dot = Dot(this=a, expression=b)

for expression in expressions:
dot = Dot(this=dot, expression=expression)

return dot
return t.cast(Dot, reduce(lambda x, y: Dot(this=x, expression=y), expressions))


class DPipe(Binary):
Expand Down

0 comments on commit 7ae5a94

Please sign in to comment.