|
@@ -5,6 +5,7 @@
|
|
|
*/
|
|
|
package org.elasticsearch.xpack.sql.expression.gen.processor;
|
|
|
|
|
|
+import org.elasticsearch.common.io.stream.NamedWriteable;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
|
|
@@ -16,17 +17,40 @@ public class ConstantProcessor implements Processor {
|
|
|
public static String NAME = "c";
|
|
|
|
|
|
private final Object constant;
|
|
|
+ private final boolean namedWriteable;
|
|
|
+ private final Class<?> clazz;
|
|
|
|
|
|
public ConstantProcessor(Object value) {
|
|
|
this.constant = value;
|
|
|
+ this.namedWriteable = value instanceof NamedWriteable;
|
|
|
+ this.clazz = namedWriteable ? value.getClass() : null;
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
public ConstantProcessor(StreamInput in) throws IOException {
|
|
|
- constant = in.readGenericValue();
|
|
|
+ namedWriteable = in.readBoolean();
|
|
|
+ if (namedWriteable) {
|
|
|
+ try {
|
|
|
+ clazz = ConstantProcessor.class.getClassLoader().loadClass(in.readString());
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
+ throw new IOException(e);
|
|
|
+ }
|
|
|
+ constant = in.readNamedWriteable((Class<NamedWriteable>) clazz);
|
|
|
+ } else {
|
|
|
+ clazz = null;
|
|
|
+ constant = in.readGenericValue();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
- out.writeGenericValue(constant);
|
|
|
+ out.writeBoolean(namedWriteable);
|
|
|
+ if (namedWriteable) {
|
|
|
+ out.writeString(constant.getClass().getName());
|
|
|
+ out.writeNamedWriteable((NamedWriteable) constant);
|
|
|
+ } else {
|
|
|
+ out.writeGenericValue(constant);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|