JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

Make all beans "Serializable"

Open eolivelli opened this issue 8 years ago • 5 comments

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

eolivelli avatar Mar 22 '17 11:03 eolivelli

So you want to serializable the parse tree? Could give a concrete usecase?

wumpz avatar Mar 22 '17 13:03 wumpz

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

eolivelli avatar Mar 22 '17 13:03 eolivelli

Another use case is distributed processing with Spark. The DeParse class cannot be serialized and used to execute SQL in a distributed environment.

mark-kreider avatar Aug 14 '17 21:08 mark-kreider

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:

  1. clone by deparse and parse

  2. or clone by Apache Commons Lang3 SerializationUtils.clone() (which we depend on already)

  3. or implement Cloneable (which is meh)

  4. is better than 1) since you can use it for Clauses and don't need to parse the full statement.

manticore-projects avatar Apr 29 '23 14:04 manticore-projects

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

wumpz avatar May 04 '23 20:05 wumpz