Skip to content

Commit

Permalink
Support Values in compiled runtime
Browse files Browse the repository at this point in the history
- Introduce tracking of ValueType and AnyValueType as
representation types in CodeGenType
- Let parameters stay as type AnyValue
- Let property values stay as type Value
- Let literal lists and maps be AnyValue
- Handle AnyValue/Value types internally in a bunch of places
  • Loading branch information
henriknyman committed Apr 9, 2018
1 parent 7de99d8 commit 6054796
Show file tree
Hide file tree
Showing 47 changed files with 1,403 additions and 320 deletions.
5 changes: 5 additions & 0 deletions community/codegen/pom.xml
Expand Up @@ -85,6 +85,11 @@ the relevant Commercial Agreement.
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-values</artifactId>
<version>3.4.0-alpha01</version>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -21,11 +21,14 @@

import java.util.Arrays;

import org.neo4j.values.AnyValue;

import static org.neo4j.codegen.TypeReference.BOOLEAN;
import static org.neo4j.codegen.TypeReference.DOUBLE;
import static org.neo4j.codegen.TypeReference.INT;
import static org.neo4j.codegen.TypeReference.LONG;
import static org.neo4j.codegen.TypeReference.OBJECT;
import static org.neo4j.codegen.TypeReference.VALUE;
import static org.neo4j.codegen.TypeReference.arrayOf;
import static org.neo4j.codegen.TypeReference.typeReference;

Expand Down Expand Up @@ -462,6 +465,10 @@ else if ( value instanceof Boolean )
{
return (Boolean) value ? TRUE : FALSE;
}
else if ( value instanceof AnyValue )
{
reference = VALUE;
}
else
{
throw new IllegalArgumentException( "Not a valid constant!" );
Expand Down
Expand Up @@ -23,6 +23,8 @@
import java.util.Arrays;
import java.util.List;

import org.neo4j.values.AnyValue;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;

Expand Down Expand Up @@ -180,6 +182,8 @@ public static TypeReference[] typeReferences( Class<?>[] types )
new TypeReference( "", "long", false, true, false, "", long.class.getModifiers() );
public static final TypeReference DOUBLE_ARRAY =
new TypeReference( "", "double", false, true, false, "", double.class.getModifiers() );
public static final TypeReference VALUE =
new TypeReference( "org.neo4j.values", "AnyValue", false, false, false, "", AnyValue.class.getModifiers() );
static final TypeReference[] NO_TYPES = new TypeReference[0];

TypeReference( String packageName, String name, boolean isPrimitive, boolean isArray,
Expand Down
Expand Up @@ -325,7 +325,7 @@ public void notEqual( Expression lhs, Expression rhs )

private void equal( Expression lhs, Expression rhs, boolean equal )
{
assertSameType( lhs, rhs, "compare" );
// assertSameType( lhs, rhs, "compare" ); // TODO: Is this assert unnecessary / too strong?
if ( lhs.type().isPrimitive() )
{
switch ( lhs.type().name() )
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.cypher.internal.compiler.v3_4.common;

import scala.AnyVal;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
Expand All @@ -35,6 +37,9 @@
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.helpers.MathUtil;
import org.neo4j.kernel.impl.util.ValueUtils;
import org.neo4j.values.AnyValue;
import org.neo4j.values.AnyValues;

import static java.lang.String.format;

Expand Down Expand Up @@ -110,7 +115,16 @@ else if ( rhs == null )
{
return -1;
}

else if ( lhs instanceof AnyValue )
{
AnyValue rhsValue = (rhs instanceof AnyValue) ? (AnyValue) rhs : ValueUtils.of( rhs );
return AnyValues.COMPARATOR.compare( (AnyValue) lhs, rhsValue );
}
else if ( rhs instanceof AnyValue )
{
AnyValue lhsValue = (lhs instanceof AnyValue) ? (AnyValue) lhs : ValueUtils.of( lhs );
return AnyValues.COMPARATOR.compare( lhsValue, (AnyValue) rhs );
}
// Compare the types
// TODO: Test coverage for the Orderability CIP
SuperType leftType = SuperType.ofValue( lhs );
Expand Down

0 comments on commit 6054796

Please sign in to comment.