JSqlParser
JSqlParser copied to clipboard
Make all beans "Serializable"
It would be great to make every Statement fully serializable. I have not digged into the internals but a "implements java.io.Serializable" and a fixed serialVersionUID field in every generated class would be enough to do the trick
@wumpz do you think it would be possible ? if you give me some advice on how to implement it I can file a PR
So you want to serializable the parse tree? Could give a concrete usecase?
in HerdDB we use keep the parse tree together with the "access plan" for the query and access plans are cached in Java Heap. We need to put a memory bound on the memory used for the "plan cache", and so I have to estimate the size of all the jSQLParser objects
In the meantime we are using Kryo, which is able to serialize Java object even if they are not "serializable" I wanted to use JOL (http://openjdk.java.net/projects/code-tools/jol/) but it licenced as GPL and cannot be used in Apache2 licensed projects.
So my actual usecase is to estimate the memory usage of a parse tree
Secondary I would like to swap that cache to disk and so I will have to "serialize" the object to disk
We are going to replace the parse tree with another internal representation but currently we are stuck to storing the raw parse tree with the plan
Actually I would like to know if this kind of implementation could be done on jSQLParser, but I don't know if it will be really useful
Another use case is distributed processing with Spark. The DeParse class cannot be serialized and used to execute SQL in a distributed environment.
So you want to serializable the parse tree? Could give a concrete usecase?
Deep Cloning without any further effort.
At the moment, you can not really derive a SELECT from an existing SELECT and modify the WHERE clause because you will tamper with the original SELECT.
So you either need to:
-
clone by deparse and parse
-
or clone by Apache Commons Lang3
SerializationUtils.clone()(which we depend on already) -
or implement
Cloneable(which is meh) -
is better than 1) since you can use it for
Clausesand don't need to parse the full statement.
Huh. That's an old one.
I am still no fan of it: https://medium.com/codex/effective-java-implement-serializable-with-great-caution-df123eb51cdf