Update serializer
This commit is contained in:
parent
1c8a41d133
commit
ec579d61dc
2
pom.xml
2
pom.xml
@ -15,7 +15,7 @@
|
|||||||
<micrometer.version>1.9.5</micrometer.version>
|
<micrometer.version>1.9.5</micrometer.version>
|
||||||
<lucene.version>9.4.2</lucene.version>
|
<lucene.version>9.4.2</lucene.version>
|
||||||
<junit.jupiter.version>5.9.0</junit.jupiter.version>
|
<junit.jupiter.version>5.9.0</junit.jupiter.version>
|
||||||
<data.generator.version>1.0.204</data.generator.version>
|
<data.generator.version>1.0.235</data.generator.version>
|
||||||
</properties>
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package it.cavallium.dbengine.client;
|
package it.cavallium.dbengine.client;
|
||||||
|
|
||||||
import it.cavallium.dbengine.client.query.BasicType;
|
import it.cavallium.dbengine.client.query.BaseType;
|
||||||
import it.cavallium.dbengine.client.query.current.data.DocSort;
|
import it.cavallium.dbengine.client.query.current.data.DocSort;
|
||||||
import it.cavallium.dbengine.client.query.current.data.NoSort;
|
import it.cavallium.dbengine.client.query.current.data.NoSort;
|
||||||
import it.cavallium.dbengine.client.query.current.data.NumericSort;
|
import it.cavallium.dbengine.client.query.current.data.NumericSort;
|
||||||
@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public record Sort(@NotNull it.cavallium.dbengine.client.query.current.data.Sort querySort) {
|
public record Sort(@NotNull it.cavallium.dbengine.client.query.current.data.Sort querySort) {
|
||||||
|
|
||||||
public boolean isSorted() {
|
public boolean isSorted() {
|
||||||
return querySort.getBasicType$() != BasicType.NoSort;
|
return querySort.getBaseType$() != BaseType.NoSort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Sort random() {
|
public static Sort random() {
|
||||||
|
@ -3,8 +3,8 @@ package it.cavallium.dbengine.client.query;
|
|||||||
import com.squareup.moshi.JsonAdapter;
|
import com.squareup.moshi.JsonAdapter;
|
||||||
import it.cavallium.dbengine.client.IntOpenHashSetJsonAdapter;
|
import it.cavallium.dbengine.client.IntOpenHashSetJsonAdapter;
|
||||||
import it.cavallium.dbengine.client.query.current.CurrentVersion;
|
import it.cavallium.dbengine.client.query.current.CurrentVersion;
|
||||||
import it.cavallium.dbengine.client.query.current.data.IBasicType;
|
import it.cavallium.dbengine.client.query.current.IBaseType;
|
||||||
import it.cavallium.dbengine.client.query.current.data.IType;
|
import it.cavallium.dbengine.client.query.current.IType;
|
||||||
import it.unimi.dsi.fastutil.booleans.BooleanList;
|
import it.unimi.dsi.fastutil.booleans.BooleanList;
|
||||||
import it.unimi.dsi.fastutil.bytes.ByteList;
|
import it.unimi.dsi.fastutil.bytes.ByteList;
|
||||||
import it.unimi.dsi.fastutil.chars.CharList;
|
import it.unimi.dsi.fastutil.chars.CharList;
|
||||||
@ -40,17 +40,17 @@ public class QueryMoshi extends MoshiPolymorphic<IType> {
|
|||||||
|
|
||||||
// Add all super types with their implementations
|
// Add all super types with their implementations
|
||||||
for (var superTypeClass : CurrentVersion.getSuperTypeClasses()) {
|
for (var superTypeClass : CurrentVersion.getSuperTypeClasses()) {
|
||||||
for (Class<? extends IBasicType> superTypeSubtypesClass : CurrentVersion.getSuperTypeSubtypesClasses(
|
for (Class<? extends IBaseType> superTypeSubtypesClass : CurrentVersion.getSuperTypeSubtypesClasses(
|
||||||
superTypeClass)) {
|
superTypeClass)) {
|
||||||
concreteClasses.add((Class<IType>) (Class) superTypeSubtypesClass);
|
concreteClasses.add((Class<IType>) (Class) superTypeSubtypesClass);
|
||||||
}
|
}
|
||||||
abstractClasses.add((Class<IType>) (Class) superTypeClass);
|
abstractClasses.add((Class<IType>) (Class) superTypeClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add IBasicType with all basic types
|
// Add IBaseType with all basic types
|
||||||
abstractClasses.add((Class<IType>) (Class) IBasicType.class);
|
abstractClasses.add((Class<IType>) (Class) IBaseType.class);
|
||||||
for (BasicType basicType : BasicType.values()) {
|
for (BaseType BaseType : BaseType.values()) {
|
||||||
concreteClasses.add((Class<IType>) (Class) CurrentVersion.VERSION.getClass(basicType));
|
concreteClasses.add((Class<IType>) (Class) CurrentVersion.getClass(BaseType));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.abstractClasses = abstractClasses;
|
this.abstractClasses = abstractClasses;
|
||||||
|
@ -88,7 +88,7 @@ public class QueryParser {
|
|||||||
if (query == null) {
|
if (query == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
switch (query.getBasicType$()) {
|
switch (query.getBaseType$()) {
|
||||||
case StandardQuery:
|
case StandardQuery:
|
||||||
var standardQuery = (it.cavallium.dbengine.client.query.current.data.StandardQuery) query;
|
var standardQuery = (it.cavallium.dbengine.client.query.current.data.StandardQuery) query;
|
||||||
|
|
||||||
@ -130,12 +130,12 @@ public class QueryParser {
|
|||||||
var booleanQuery = (it.cavallium.dbengine.client.query.current.data.BooleanQuery) query;
|
var booleanQuery = (it.cavallium.dbengine.client.query.current.data.BooleanQuery) query;
|
||||||
var bq = new Builder();
|
var bq = new Builder();
|
||||||
for (BooleanQueryPart part : booleanQuery.parts()) {
|
for (BooleanQueryPart part : booleanQuery.parts()) {
|
||||||
Occur occur = switch (part.occur().getBasicType$()) {
|
Occur occur = switch (part.occur().getBaseType$()) {
|
||||||
case OccurFilter -> Occur.FILTER;
|
case OccurFilter -> Occur.FILTER;
|
||||||
case OccurMust -> Occur.MUST;
|
case OccurMust -> Occur.MUST;
|
||||||
case OccurShould -> Occur.SHOULD;
|
case OccurShould -> Occur.SHOULD;
|
||||||
case OccurMustNot -> Occur.MUST_NOT;
|
case OccurMustNot -> Occur.MUST_NOT;
|
||||||
default -> throw new IllegalStateException("Unexpected value: " + part.occur().getBasicType$());
|
default -> throw new IllegalStateException("Unexpected value: " + part.occur().getBaseType$());
|
||||||
};
|
};
|
||||||
bq.add(toQuery(part.query(), analyzer), occur);
|
bq.add(toQuery(part.query(), analyzer), occur);
|
||||||
}
|
}
|
||||||
@ -320,24 +320,24 @@ public class QueryParser {
|
|||||||
var wildcardQuery = (WildcardQuery) query;
|
var wildcardQuery = (WildcardQuery) query;
|
||||||
return new org.apache.lucene.search.WildcardQuery(new Term(wildcardQuery.field(), wildcardQuery.pattern()));
|
return new org.apache.lucene.search.WildcardQuery(new Term(wildcardQuery.field(), wildcardQuery.pattern()));
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + query.getBasicType$());
|
throw new IllegalStateException("Unexpected value: " + query.getBaseType$());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NumberFormat toNumberFormat(it.cavallium.dbengine.client.query.current.data.NumberFormat numberFormat) {
|
private static NumberFormat toNumberFormat(it.cavallium.dbengine.client.query.current.data.NumberFormat numberFormat) {
|
||||||
return switch (numberFormat.getBasicType$()) {
|
return switch (numberFormat.getBaseType$()) {
|
||||||
case NumberFormatDecimal -> new DecimalFormat();
|
case NumberFormatDecimal -> new DecimalFormat();
|
||||||
default -> throw new UnsupportedOperationException("Unsupported type: " + numberFormat.getBasicType$());
|
default -> throw new UnsupportedOperationException("Unsupported type: " + numberFormat.getBaseType$());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<? extends Number> toType(PointType type) {
|
private static Class<? extends Number> toType(PointType type) {
|
||||||
return switch (type.getBasicType$()) {
|
return switch (type.getBaseType$()) {
|
||||||
case PointTypeInt -> Integer.class;
|
case PointTypeInt -> Integer.class;
|
||||||
case PointTypeLong -> Long.class;
|
case PointTypeLong -> Long.class;
|
||||||
case PointTypeFloat -> Float.class;
|
case PointTypeFloat -> Float.class;
|
||||||
case PointTypeDouble -> Double.class;
|
case PointTypeDouble -> Double.class;
|
||||||
default -> throw new UnsupportedOperationException("Unsupported type: " + type.getBasicType$());
|
default -> throw new UnsupportedOperationException("Unsupported type: " + type.getBaseType$());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ public class QueryParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Sort toSort(it.cavallium.dbengine.client.query.current.data.Sort sort) {
|
public static Sort toSort(it.cavallium.dbengine.client.query.current.data.Sort sort) {
|
||||||
switch (sort.getBasicType$()) {
|
switch (sort.getBaseType$()) {
|
||||||
case NoSort:
|
case NoSort:
|
||||||
return null;
|
return null;
|
||||||
case ScoreSort:
|
case ScoreSort:
|
||||||
@ -359,7 +359,7 @@ public class QueryParser {
|
|||||||
case RandomSort:
|
case RandomSort:
|
||||||
return new Sort(new RandomSortField());
|
return new Sort(new RandomSortField());
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + sort.getBasicType$());
|
throw new IllegalStateException("Unexpected value: " + sort.getBaseType$());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import io.netty.handler.codec.ByteToMessageCodec;
|
|||||||
import it.cavallium.dbengine.rpc.current.data.BoxedRPCEvent;
|
import it.cavallium.dbengine.rpc.current.data.BoxedRPCEvent;
|
||||||
import it.cavallium.dbengine.rpc.current.data.ClientBoundRequest;
|
import it.cavallium.dbengine.rpc.current.data.ClientBoundRequest;
|
||||||
import it.cavallium.dbengine.rpc.current.data.ClientBoundResponse;
|
import it.cavallium.dbengine.rpc.current.data.ClientBoundResponse;
|
||||||
import it.cavallium.dbengine.rpc.current.data.IBasicType;
|
import it.cavallium.dbengine.rpc.current.IBaseType;
|
||||||
import it.cavallium.dbengine.rpc.current.data.RPCEvent;
|
import it.cavallium.dbengine.rpc.current.data.RPCEvent;
|
||||||
import it.cavallium.dbengine.rpc.current.data.ServerBoundRequest;
|
import it.cavallium.dbengine.rpc.current.data.ServerBoundRequest;
|
||||||
import it.cavallium.dbengine.rpc.current.data.ServerBoundResponse;
|
import it.cavallium.dbengine.rpc.current.data.ServerBoundResponse;
|
||||||
@ -23,12 +23,13 @@ public class RPCCodecs {
|
|||||||
public static class RPCEventCodec extends ByteToMessageCodec<RPCEvent> {
|
public static class RPCEventCodec extends ByteToMessageCodec<RPCEvent> {
|
||||||
|
|
||||||
public static final ChannelHandler INSTANCE = new RPCEventCodec();
|
public static final ChannelHandler INSTANCE = new RPCEventCodec();
|
||||||
|
public static final BoxedRPCEventSerializer SERIALIZER_INSTANCE = new BoxedRPCEventSerializer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, RPCEvent msg, ByteBuf out) throws Exception {
|
protected void encode(ChannelHandlerContext ctx, RPCEvent msg, ByteBuf out) throws Exception {
|
||||||
try (var bbos = new ByteBufOutputStream(out)) {
|
try (var bbos = new ByteBufOutputStream(out)) {
|
||||||
try (var dos = new DataOutputStream(bbos)) {
|
try (var dos = new DataOutputStream(bbos)) {
|
||||||
BoxedRPCEventSerializer.INSTANCE.serialize(dos, BoxedRPCEvent.of(msg));
|
SERIALIZER_INSTANCE.serialize(dos, BoxedRPCEvent.of(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +38,7 @@ public class RPCCodecs {
|
|||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
||||||
try (var bbis = new ByteBufInputStream(msg)) {
|
try (var bbis = new ByteBufInputStream(msg)) {
|
||||||
try (var dis = new DataInputStream(bbis)) {
|
try (var dis = new DataInputStream(bbis)) {
|
||||||
out.add(BoxedRPCEventSerializer.INSTANCE.deserialize(dis).val());
|
out.add(SERIALIZER_INSTANCE.deserialize(dis).val());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package it.cavallium.dbengine;
|
package it.cavallium.dbengine;
|
||||||
|
|
||||||
import it.cavallium.dbengine.client.Sort;
|
import it.cavallium.dbengine.client.Sort;
|
||||||
import it.cavallium.dbengine.client.query.BasicType;
|
import it.cavallium.dbengine.client.query.BaseType;
|
||||||
|
|
||||||
record ExpectedQueryType(boolean shard, boolean sorted, boolean sortedByScore, boolean complete, boolean onlyCount) {
|
record ExpectedQueryType(boolean shard, boolean sorted, boolean sortedByScore, boolean complete, boolean onlyCount) {
|
||||||
|
|
||||||
public ExpectedQueryType(boolean shard, Sort multiSort, boolean complete, boolean onlyCount) {
|
public ExpectedQueryType(boolean shard, Sort multiSort, boolean complete, boolean onlyCount) {
|
||||||
this(shard, multiSort.isSorted(), multiSort.querySort().getBasicType$() == BasicType.ScoreSort, complete, onlyCount);
|
this(shard, multiSort.isSorted(), multiSort.querySort().getBaseType$() == BaseType.ScoreSort, complete, onlyCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user