Skip to content

Commit

Permalink
Revert "Allow attribute type conversions on WRITE (typedb#5098)" (typ…
Browse files Browse the repository at this point in the history
…edb#5099)

This reverts commit cb17833.
  • Loading branch information
haikalpribadi authored Apr 8, 2019
1 parent cb17833 commit 63097e8
Show file tree
Hide file tree
Showing 100 changed files with 277 additions and 479 deletions.
73 changes: 8 additions & 65 deletions concept/type/AttributeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import grakn.core.concept.Label;
import grakn.core.concept.thing.Attribute;

import grakn.core.concept.Schema;
import java.time.ZoneId;
import java.util.function.Function;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -230,58 +227,20 @@ default boolean isAttributeType() {
* @param <D> The data type.
*/
class DataType<D> {
public static final DataType<String> STRING = new DataType<>(
String.class,
Schema.VertexProperty.VALUE_STRING,
(v) -> v
);

public static final DataType<Boolean> BOOLEAN = new DataType<>(
Boolean.class,
Schema.VertexProperty.VALUE_BOOLEAN,
(v) -> v
);

public static final DataType<Integer> INTEGER = new DataType<>(
Integer.class,
Schema.VertexProperty.VALUE_INTEGER,
(v) -> v
);

public static final DataType<Long> LONG = new DataType<>(
Long.class,
Schema.VertexProperty.VALUE_LONG,
(v) -> v
);

public static final DataType<Double> DOUBLE = new DataType<>(
Double.class,
Schema.VertexProperty.VALUE_DOUBLE,
(v) -> v
);

public static final DataType<Float> FLOAT = new DataType<>(
Float.class,
Schema.VertexProperty.VALUE_FLOAT,
(v) -> v
);

public static final DataType<LocalDateTime> DATE = new DataType<>(
LocalDateTime.class,
Schema.VertexProperty.VALUE_DATE,
(d) -> d.atZone(ZoneId.of("Z")).toInstant().toEpochMilli()
);
public static final DataType<Boolean> BOOLEAN = new DataType<>(Boolean.class);
public static final DataType<LocalDateTime> DATE = new DataType<>(LocalDateTime.class);
public static final DataType<Double> DOUBLE = new DataType<>(Double.class);
public static final DataType<Float> FLOAT = new DataType<>(Float.class);
public static final DataType<Integer> INTEGER = new DataType<>(Integer.class);
public static final DataType<Long> LONG = new DataType<>(Long.class);
public static final DataType<String> STRING = new DataType<>(String.class);

private static final List<DataType<?>> values = list(BOOLEAN, DATE, DOUBLE, FLOAT, INTEGER, LONG, STRING);

private final Class<D> dataClass;
private final Schema.VertexProperty vertexProperty;
private final Function<D, Object> persistedValueSupplier;

private DataType(Class<D> dataClass, Schema.VertexProperty vertexProperty, Function<D, Object> persistedValueProvider) {
private DataType(Class<D> dataClass) {
this.dataClass = dataClass;
this.vertexProperty = vertexProperty;
this.persistedValueSupplier = persistedValueProvider;
}

@CheckReturnValue
Expand All @@ -294,11 +253,6 @@ public String name() {
return dataClass.getName();
}

@CheckReturnValue
public Schema.VertexProperty getVertexProperty(){
return vertexProperty;
}

@Override
public String toString() {
return name();
Expand All @@ -309,17 +263,6 @@ public static List<DataType<?>> values() {
return values;
}

/**
* Converts the provided value into the data type and format that will be persisted.
*
* @param value The value to be converted
* @return The String representation of the value
*/
@CheckReturnValue
public Object getPersistedValue(D value){
return persistedValueSupplier.apply(value);
}

@SuppressWarnings("unchecked")
@CheckReturnValue
public static <D> DataType<D> of(Class<D> name) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/ClusterMemberMapReduce.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package grakn.core.graql.analytics;

import grakn.core.concept.ConceptId;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.KeyValue;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import grakn.core.concept.ConceptId;
import grakn.core.graql.exception.GraqlQueryException;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MemoryComputeKey;
import org.apache.tinkerpop.gremlin.process.computer.Messenger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package grakn.core.graql.analytics;

import grakn.core.graql.exception.GraqlQueryException;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MemoryComputeKey;
import org.apache.tinkerpop.gremlin.process.computer.Messenger;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/CountMapReduce.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package grakn.core.graql.analytics;

import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package grakn.core.graql.analytics;

import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.structure.Vertex;

import java.io.Serializable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import grakn.core.concept.ConceptId;
import grakn.core.concept.LabelId;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.KeyValue;
import org.apache.tinkerpop.gremlin.structure.Vertex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.common.collect.Sets;
import grakn.core.common.util.CommonUtil;
import grakn.core.concept.LabelId;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MessageScope;
import org.apache.tinkerpop.gremlin.process.computer.Messenger;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/GraknMapReduce.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import grakn.core.common.util.CommonUtil;
import grakn.core.concept.LabelId;
import grakn.core.concept.type.AttributeType;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.process.computer.KeyValue;
import org.apache.tinkerpop.gremlin.process.computer.MapReduce;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/GraknVertexProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.common.collect.Sets;
import grakn.core.common.util.CommonUtil;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/KCoreVertexProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.common.collect.Iterators;
import grakn.core.graql.exception.GraqlQueryException;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MemoryComputeKey;
import org.apache.tinkerpop.gremlin.process.computer.Messenger;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/MedianVertexProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.common.collect.Sets;
import grakn.core.concept.LabelId;
import grakn.core.concept.type.AttributeType;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MemoryComputeKey;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/ShortestPathVertexProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.common.collect.Iterators;
import grakn.core.concept.ConceptId;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MemoryComputeKey;
import org.apache.tinkerpop.gremlin.process.computer.MessageScope;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/SumMapReduce.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import grakn.core.concept.LabelId;
import grakn.core.concept.type.AttributeType;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;

Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/analytics/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import grakn.core.concept.LabelId;
import grakn.core.concept.type.SchemaConcept;
import grakn.core.server.session.TransactionOLTP;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import graql.lang.Graql;
import org.apache.tinkerpop.gremlin.process.computer.KeyValue;
import org.apache.tinkerpop.gremlin.structure.Vertex;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/executor/ComputeExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import grakn.core.graql.analytics.SumMapReduce;
import grakn.core.graql.analytics.Utility;
import grakn.core.graql.exception.GraqlQueryException;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import grakn.core.server.session.TransactionOLTP;
import graql.lang.Graql;
import graql.lang.pattern.Pattern;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/executor/ConceptBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import grakn.core.concept.type.Type;
import grakn.core.graql.exception.GraqlQueryException;
import grakn.core.server.exception.InvalidKBException;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import graql.lang.Graql;
import graql.lang.pattern.Pattern;
import graql.lang.property.IsaProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import grakn.core.graql.reasoner.atom.predicate.IdPredicate;
import grakn.core.graql.reasoner.atom.predicate.ValuePredicate;
import grakn.core.graql.reasoner.query.ReasonerQuery;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import graql.lang.property.HasAttributeProperty;
import graql.lang.property.IsaProperty;
import graql.lang.property.VarProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
import java.util.Set;
import java.util.stream.Stream;

import static grakn.core.concept.Schema.ImplicitType.KEY;
import static grakn.core.concept.Schema.ImplicitType.KEY_OWNER;
import static grakn.core.concept.Schema.ImplicitType.KEY_VALUE;
import static grakn.core.server.kb.Schema.ImplicitType.KEY;
import static grakn.core.server.kb.Schema.ImplicitType.KEY_OWNER;
import static grakn.core.server.kb.Schema.ImplicitType.KEY_VALUE;
import static graql.lang.Graql.var;

public class HasAttributeTypeExecutor implements PropertyExecutor.Definable {
Expand Down
6 changes: 3 additions & 3 deletions server/src/graql/executor/property/ValueExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import grakn.core.graql.reasoner.atom.Atomic;
import grakn.core.graql.reasoner.atom.AtomicFactory;
import grakn.core.graql.reasoner.query.ReasonerQuery;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import grakn.core.server.kb.concept.Serialiser;
import graql.lang.Graql;
import graql.lang.property.ValueProperty;
Expand Down Expand Up @@ -156,7 +156,7 @@ public boolean isValueEquality() {
public <S, E> GraphTraversal<S, E> apply(GraphTraversal<S, E> traversal) {
// Compare to a given value
AttributeType.DataType<?> dataType = AttributeType.DataType.of(value().getClass());
Schema.VertexProperty property = dataType.getVertexProperty();
Schema.VertexProperty property = Schema.VertexProperty.ofDataType(dataType);
traversal.has(property.name(), predicate());
return traversal;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ public static class Variable extends Comparison<Statement, java.lang.String> {

private static final Map<Graql.Token.Comparator, Function<java.lang.String, P<java.lang.String>>> PREDICATES_VAR = varPredicates();
private static final java.lang.String[] VALUE_PROPERTIES = AttributeType.DataType.values().stream()
.map(AttributeType.DataType::getVertexProperty).distinct()
.map(Schema.VertexProperty::ofDataType).distinct()
.map(Enum::name).toArray(java.lang.String[]::new);

Variable(Graql.Token.Comparator comparator, Statement value) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/gremlin/GraqlTraversal.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.common.collect.Sets;
import grakn.core.concept.ConceptId;
import grakn.core.graql.gremlin.fragment.Fragment;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import grakn.core.server.session.TransactionOLTP;
import graql.lang.statement.Variable;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/gremlin/fragment/AbstractFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package grakn.core.graql.gremlin.fragment;

import com.google.auto.value.AutoValue;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import grakn.core.server.session.TransactionOLTP;
import graql.lang.statement.Variable;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import grakn.core.graql.gremlin.spanningtree.graph.Node;
import grakn.core.graql.gremlin.spanningtree.graph.NodeId;
import grakn.core.graql.gremlin.spanningtree.util.Weighted;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import grakn.core.server.session.TransactionOLTP;
import graql.lang.statement.Variable;
import org.apache.tinkerpop.gremlin.process.traversal.P;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import java.util.Collection;

import static grakn.core.concept.Schema.VertexProperty.INDEX;
import static grakn.core.server.kb.Schema.VertexProperty.INDEX;

@AutoValue
abstract class AttributeIndexFragment extends Fragment {
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/gremlin/fragment/DataTypeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import java.util.Collection;

import static grakn.core.concept.Schema.VertexProperty.DATA_TYPE;
import static grakn.core.server.kb.Schema.VertexProperty.DATA_TYPE;

@AutoValue
abstract class DataTypeFragment extends Fragment {
Expand Down
8 changes: 4 additions & 4 deletions server/src/graql/gremlin/fragment/Fragments.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import grakn.core.concept.type.AttributeType;
import grakn.core.graql.executor.property.ValueExecutor;
import grakn.core.concept.printer.StringPrinter;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import graql.lang.property.VarProperty;
import graql.lang.statement.Variable;
import org.apache.tinkerpop.gremlin.process.traversal.P;
Expand All @@ -38,9 +38,9 @@
import javax.annotation.Nullable;
import java.util.Set;

import static grakn.core.concept.Schema.EdgeLabel.SUB;
import static grakn.core.concept.Schema.VertexProperty.LABEL_ID;
import static grakn.core.concept.Schema.VertexProperty.THING_TYPE_LABEL_ID;
import static grakn.core.server.kb.Schema.EdgeLabel.SUB;
import static grakn.core.server.kb.Schema.VertexProperty.LABEL_ID;
import static grakn.core.server.kb.Schema.VertexProperty.THING_TYPE_LABEL_ID;
import static java.util.stream.Collectors.joining;

/**
Expand Down
2 changes: 1 addition & 1 deletion server/src/graql/gremlin/fragment/IdFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.auto.value.AutoValue;
import grakn.core.concept.ConceptId;
import grakn.core.concept.Schema;
import grakn.core.server.kb.Schema;
import grakn.core.server.session.TransactionOLTP;
import graql.lang.property.IdProperty;
import graql.lang.statement.Variable;
Expand Down
Loading

0 comments on commit 63097e8

Please sign in to comment.