Skip to content

Best Practices for Serializing and Reconstructing sqlglot Expression Trees #2593

Closed Answered by georgesittas
RobinL asked this question in Q&A
Discussion options

You must be logged in to vote

Hey 👋

My question is: Is there an existing feature in sqlglot that facilitates this kind of serialization and reconstruction of expression trees? If not, are there any best practices or recommendations for achieving this in a more standardized or efficient manner?

Yes, there is: Expression.load and Expression.dump already implement serde for SQLGlot expressions. Observe:

>>> import sqlglot
>>> tree = sqlglot.parse_one("l.first_name")
>>> tree
(COLUMN this:
  (IDENTIFIER this: first_name, quoted: False), table:
  (IDENTIFIER this: l, quoted: False))
>>> tree.dump()
{'class': 'Column', 'args': {'this': {'class': 'Identifier', 'args': {'this': 'first_name', 'quoted': False}}, 'table': {'cl…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RobinL
Comment options

Answer selected by georgesittas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants