diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java index 91a8709039..4bc3fffb80 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java @@ -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; @@ -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 ); diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyList.java b/core/src/main/java/org/polypheny/db/type/entity/PolyList.java index 3e5c6499bc..bbe1a55d1f 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyList.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyList.java @@ -100,6 +100,12 @@ public static PolyList of( E... values ) { } + @SuppressWarnings("unused") + public static PolyList ofArray( E[] values ) { + return new PolyList<>( values ); + } + + /** * Required due to limitation of call, where interfaces lead to errors. */ diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java index 096a3b5eee..2696bd9bdb 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java @@ -96,6 +96,7 @@ PolyBigDecimal.class, PolyTimeStamp.class, PolyDocument.class, + PolyDictionary.class, PolyMap.class, PolyList.class, PolyGraph.class, diff --git a/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java b/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java index 59ff11cd68..ed08d7452f 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java +++ b/core/src/main/java/org/polypheny/db/type/entity/document/PolyDocument.java @@ -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; @@ -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; @@ -66,8 +70,19 @@ public PolyDocument( Pair... 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() { + } ).writeValueAsString( this ); + } catch ( JsonProcessingException e ) { + log.warn( "Error on serializing typed JSON." ); + return null; + } } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java index 948d2c0c07..3b196414a0 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyDictionary.java @@ -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; @@ -26,8 +28,10 @@ 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; @@ -35,6 +39,7 @@ import org.polypheny.db.type.entity.relational.PolyMap; import org.polypheny.db.util.BuiltInMethod; +@Slf4j public class PolyDictionary extends PolyMap { @@ -62,6 +67,18 @@ public Expression asExpression() { } + @Override + public @Nullable String toTypedJson() { + try { + return JSON_WRAPPER.writerFor( new TypeReference() { + } ).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 ); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java index 4dabf9150b..f2ef015ae3 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java @@ -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; @@ -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." ); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/relational/PolyMap.java b/core/src/main/java/org/polypheny/db/type/entity/relational/PolyMap.java index a45ebf221e..bbe1d898bf 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/relational/PolyMap.java +++ b/core/src/main/java/org/polypheny/db/type/entity/relational/PolyMap.java @@ -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; @@ -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; @@ -45,6 +48,7 @@ @EqualsAndHashCode(callSuper = true) @Value(staticConstructor = "of") @NonFinal +@Slf4j public class PolyMap extends PolyValue implements Map { @Delegate @@ -119,6 +123,17 @@ public Expression asExpression() { } + @Override + public @Nullable String toTypedJson() { + try { + return JSON_WRAPPER.writerFor( new TypeReference>() { + } ).writeValueAsString( this ); + } catch ( JsonProcessingException e ) { + log.warn( "Error on serializing typed JSON." ); + return null; + } + } + @Override public PolySerializable copy() { return PolySerializable.deserialize( serialize(), PolyMap.class ); diff --git a/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java b/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java index 4aec709d19..ee15e65b25 100644 --- a/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java +++ b/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java @@ -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 ), diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java index 0b74c4db65..875a80801e 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java @@ -68,7 +68,7 @@ public Pair 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(