Skip to content

Commit

Permalink
minor adjustment for model serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Oct 18, 2023
1 parent c6b0dcc commit e8af3b3
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.rex.RexProgramBuilder;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.PolyTypeFamily;
import org.polypheny.db.type.entity.PolyBoolean;
import org.polypheny.db.type.entity.PolyList;
import org.polypheny.db.type.entity.PolyValue;
Expand Down Expand Up @@ -98,7 +99,7 @@ static Type javaClass( JavaTypeFactory typeFactory, AlgDataType type ) {


public static Class<?> javaRowClass( JavaTypeFactory typeFactory, AlgDataType type ) {
if ( type.isStruct() && type.getFieldCount() == 1 ) {
if ( type.isStruct() && type.getFieldCount() == 1 && !PolyTypeFamily.GRAPH.contains( type ) ) {
type = type.getFieldList().get( 0 ).getType();
}
final Type clazz = typeFactory.getJavaClass( type );
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/polypheny/db/type/entity/PolyList.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public static <E extends PolyValue> PolyList<E> of( E... values ) {
}


@SuppressWarnings("unused")
public static <E extends PolyValue> PolyList<E> ofArray( E[] values ) {
return new PolyList<>( values );
}


/**
* Required due to limitation of call, where interfaces lead to errors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
PolyBigDecimal.class,
PolyTimeStamp.class,
PolyDocument.class,
PolyDictionary.class,
PolyMap.class,
PolyList.class,
PolyGraph.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.polypheny.db.type.entity.document;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import io.activej.serializer.BinaryInput;
import io.activej.serializer.BinaryOutput;
import io.activej.serializer.BinarySerializer;
Expand All @@ -30,6 +32,8 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.entity.PolyString;
Expand Down Expand Up @@ -66,8 +70,19 @@ public PolyDocument( Pair<PolyString, PolyValue>... value ) {


public static PolyDocument parse( String string ) {
log.warn( "todo wfwefcw" );
return null;
throw new GenericRuntimeException( "error on parsing Document" );
}


@Override
public @Nullable String toTypedJson() {
try {
return JSON_WRAPPER.writerFor( new TypeReference<PolyDocument>() {
} ).writeValueAsString( this );
} catch ( JsonProcessingException e ) {
log.warn( "Error on serializing typed JSON." );
return null;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.polypheny.db.type.entity.graph;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import io.activej.serializer.BinaryInput;
import io.activej.serializer.BinaryOutput;
import io.activej.serializer.BinarySerializer;
Expand All @@ -26,15 +28,18 @@
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.algebra.enumerable.EnumUtils;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.relational.PolyMap;
import org.polypheny.db.util.BuiltInMethod;

@Slf4j
public class PolyDictionary extends PolyMap<PolyString, PolyValue> {


Expand Down Expand Up @@ -62,6 +67,18 @@ public Expression asExpression() {
}


@Override
public @Nullable String toTypedJson() {
try {
return JSON_WRAPPER.writerFor( new TypeReference<PolyDictionary>() {
} ).writeValueAsString( this );
} catch ( JsonProcessingException e ) {
log.warn( "Error on serializing typed JSON." );
return null;
}
}


public static PolyDictionary fromString( String json ) {
return PolyValue.fromTypedJson( json, PolyDictionary.class );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeField;
import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.entity.PolyList;
Expand Down Expand Up @@ -351,7 +352,7 @@ public int compareTo( @NotNull PolyValue o ) {

@Override
public Expression asExpression() {
throw new RuntimeException( "Cannot transform PolyPath." );
throw new GenericRuntimeException( "Cannot transform PolyPath." );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.polypheny.db.type.entity.relational;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import io.activej.serializer.BinaryInput;
import io.activej.serializer.BinaryOutput;
import io.activej.serializer.BinarySerializer;
Expand All @@ -32,6 +34,7 @@
import lombok.Value;
import lombok.experimental.Delegate;
import lombok.experimental.NonFinal;
import lombok.extern.slf4j.Slf4j;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.jetbrains.annotations.NotNull;
Expand All @@ -45,6 +48,7 @@
@EqualsAndHashCode(callSuper = true)
@Value(staticConstructor = "of")
@NonFinal
@Slf4j
public class PolyMap<K extends PolyValue, V extends PolyValue> extends PolyValue implements Map<K, V> {

@Delegate
Expand Down Expand Up @@ -119,6 +123,17 @@ public Expression asExpression() {
}


@Override
public @Nullable String toTypedJson() {
try {
return JSON_WRAPPER.writerFor( new TypeReference<PolyMap<PolyValue, PolyValue>>() {
} ).writeValueAsString( this );
} catch ( JsonProcessingException e ) {
log.warn( "Error on serializing typed JSON." );
return null;
}
}

@Override
public PolySerializable copy() {
return PolySerializable.deserialize( serialize(), PolyMap.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public enum BuiltInMethod {
MAP_OF_ENTRIES( ImmutableMap.class, "copyOf", List.class ),
ARRAY( Functions.class, "array", Object[].class ),
FLAT_PRODUCT( Functions.class, "flatProduct", int[].class, boolean.class, FlatProductInputType[].class ),
LIST_N( PolyList.class, "of", Comparable[].class ),
LIST_N( PolyList.class, "ofArray", PolyValue[].class ),
LIST2( ComparableList.class, "of", Object.class, Object.class ),
LIST3( ComparableList.class, "of", Object.class, Object.class, Object.class ),
LIST4( ComparableList.class, "of", Object.class, Object.class, Object.class, Object.class ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Pair<PolyString, RexNode> getRex( CypherContext context, RexType type ) {
for ( AlgDataTypeField pathField : field.getType().getFieldList() ) {
if ( pathField.getName().equals( name ) ) {
// search r -> RowType(Path(r:Edge, n:Node))
RexIndexRef pathRef = context.rexBuilder.makeInputRef( node.getRowType().getFieldList().get( field.getIndex() ).getType(), field.getIndex() );
RexIndexRef pathRef = context.rexBuilder.makeInputRef( field.getType(), field.getIndex() );
return Pair.of(
PolyString.of( name ),
context.rexBuilder.makeCall(
Expand Down

0 comments on commit e8af3b3

Please sign in to comment.