results = new FilterIterator<>(results, edge -> { if (!query.showHidden() && Graph.Hidden.isHidden(edge.label())) { return false;
@Override public <R> Optional<R> get(String key) { if (key == null) { throw Graph.Variables.Exceptions.variableKeyCanNotBeNull(); } if (key.isEmpty()) { throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty(); } Vertex vertex = this.queryVariableVertex(key); if (vertex == null) { return Optional.empty(); } String type = vertex.value(Hidden.hide(VARIABLE_TYPE)); if (!Arrays.asList(TYPES).contains(Hidden.hide(type))) { throw Graph.Variables.Exceptions .dataTypeOfVariableValueNotSupported(type); } // The value of key VARIABLE_TYPE is the name of variable value return Optional.of(vertex.value(Hidden.hide(type))); }
map.put(Hidden.unHide(P.ID), this.id); map.put(Hidden.unHide(P.TYPE), this.type); map.put(Hidden.unHide(P.NAME), this.name); map.put(Hidden.unHide(P.STATUS), this.status.string()); map.put(Hidden.unHide(P.PROGRESS), this.progress); map.put(Hidden.unHide(P.CREATE), this.create); map.put(Hidden.unHide(P.RETRIES), this.retries); map.put(Hidden.unHide(P.DESCRIPTION), this.description); map.put(Hidden.unHide(P.UPDATE), this.update); map.put(Hidden.unHide(P.DEPENDENCIES), value); map.put(Hidden.unHide(P.CALLABLE), this.callable.getClass().getName()); if (this.input != null) { map.put(Hidden.unHide(P.INPUT), this.input); map.put(Hidden.unHide(P.RESULT), this.result);
schema.getVertexLabel(Hidden.hide(VARIABLES)); createPropertyKey(Hidden.hide(VARIABLE_KEY), DataType.TEXT, Cardinality.SINGLE); createPropertyKey(Hidden.hide(VARIABLE_TYPE), DataType.TEXT, Cardinality.SINGLE); createPropertyKey(Hidden.hide(BYTE_VALUE), DataType.BYTE, Cardinality.SINGLE); createPropertyKey(Hidden.hide(BOOLEAN_VALUE), DataType.BOOLEAN, Cardinality.SINGLE); createPropertyKey(Hidden.hide(INTEGER_VALUE), DataType.INT, Cardinality.SINGLE); createPropertyKey(Hidden.hide(LONG_VALUE), DataType.LONG, Cardinality.SINGLE); createPropertyKey(Hidden.hide(FLOAT_VALUE), DataType.FLOAT, Cardinality.SINGLE); createPropertyKey(Hidden.hide(DOUBLE_VALUE), DataType.DOUBLE, Cardinality.SINGLE); createPropertyKey(Hidden.hide(STRING_VALUE), DataType.TEXT, Cardinality.SINGLE); createPropertyKey(Hidden.hide(BYTE_VALUE + UNIFORM_LIST), DataType.BYTE, Cardinality.LIST); createPropertyKey(Hidden.hide(BOOLEAN_VALUE + UNIFORM_LIST), DataType.BOOLEAN, Cardinality.LIST); createPropertyKey(Hidden.hide(INTEGER_VALUE + UNIFORM_LIST), DataType.INT, Cardinality.LIST); createPropertyKey(Hidden.hide(LONG_VALUE + UNIFORM_LIST), DataType.LONG, Cardinality.LIST); createPropertyKey(Hidden.hide(FLOAT_VALUE + UNIFORM_LIST),
final Neo4jNode node = vertex.getBaseVertex(); final Neo4jGraphAPI graph = ((Neo4jGraph) vertex.graph()).getBaseGraph(); final String prefixedKey = Graph.Hidden.hide(key); if (node.hasProperty(key)) { if (node.getProperty(key).equals(VERTEX_PROPERTY_TOKEN)) {
vertex.property(Hidden.hide(VARIABLE_KEY), key); Object object = HugeVariables.extractSingleObject(value); if (object == null) { vertex.property(Hidden.hide(STRING_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), STRING_VALUE + suffix); return; vertex.property(Hidden.hide(BYTE_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), BYTE_VALUE + suffix); } else if (object instanceof Boolean) { vertex.property(Hidden.hide(BOOLEAN_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), BOOLEAN_VALUE + suffix); } else if (object instanceof Integer) { vertex.property(Hidden.hide(INTEGER_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), INTEGER_VALUE + suffix); } else if (object instanceof Long) { vertex.property(Hidden.hide(LONG_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), LONG_VALUE + suffix); } else if (object instanceof Float) { vertex.property(Hidden.hide(FLOAT_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), FLOAT_VALUE + suffix); } else if (object instanceof Double) { vertex.property(Hidden.hide(DOUBLE_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), DOUBLE_VALUE + suffix); } else if (object instanceof String) { vertex.property(Hidden.hide(STRING_VALUE + suffix), value); vertex.property(Hidden.hide(VARIABLE_TYPE), STRING_VALUE + suffix);
for (Cell cell : result.listCells()) { String key = Bytes.toString(CellUtil.cloneQualifier(cell)); if (!Graph.Hidden.isHidden(key)) { rawProps.put(key, CellUtil.cloneValue(cell)); } else if (key.equals(Constants.TO)) {
results = new FilterIterator<>(results, edge -> { if (!query.showHidden() && Graph.Hidden.isHidden(edge.label())) { return false;
map.put(Hidden.unHide(P.ID), this.id); map.put(Hidden.unHide(P.TYPE), this.type); map.put(Hidden.unHide(P.NAME), this.name); map.put(Hidden.unHide(P.CALLABLE), this.callable.getClass().getName()); map.put(Hidden.unHide(P.STATUS), this.status.string()); map.put(Hidden.unHide(P.PROGRESS), this.progress); map.put(Hidden.unHide(P.CREATE), this.create); map.put(Hidden.unHide(P.RETRIES), this.retries); map.put(Hidden.unHide(P.DESCRIPTION), this.description); map.put(Hidden.unHide(P.UPDATE), this.update); map.put(Hidden.unHide(P.DEPENDENCIES), value); map.put(Hidden.unHide(P.INPUT), this.input); map.put(Hidden.unHide(P.RESULT), this.result);
if (Graph.Hidden.isHidden(label)) step.removeLabel(label);
@Override public void load(Vertex vertex, Result result) { if (result.isEmpty()) { throw new HBaseGraphNotFoundException(vertex, "Vertex does not exist: " + vertex.id()); } String label = null; Long createdAt = null; Long updatedAt = null; Map<String, byte[]> rawProps = new HashMap<>(); for (Cell cell : result.listCells()) { String key = Bytes.toString(CellUtil.cloneQualifier(cell)); if (!Graph.Hidden.isHidden(key)) { rawProps.put(key, CellUtil.cloneValue(cell)); } else if (key.equals(Constants.LABEL)) { label = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.CREATED_AT)) { createdAt = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.UPDATED_AT)) { updatedAt = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } } final String labelStr = label; Map<String, Object> props = rawProps.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> ValueUtils.deserializePropertyValue(graph, ElementType.VERTEX, labelStr, e.getKey(), e.getValue()))); HBaseVertex newVertex = new HBaseVertex(graph, vertex.id(), label, createdAt, updatedAt, props); ((HBaseVertex) vertex).copyFrom(newVertex); } }
public LabelMetadata deserialize(Result result) { byte[] bytes = result.getRow(); PositionedByteRange buffer = new SimplePositionedByteRange(bytes); String label = OrderedBytes.decodeString(buffer); ElementType type = OrderedBytes.decodeInt8(buffer) == 1 ? ElementType.VERTEX : ElementType.EDGE; ValueType idType = null; Long createdAt = null; Long updatedAt = null; Map<String, ValueType> props = new HashMap<>(); for (Cell cell : result.listCells()) { String key = Bytes.toString(CellUtil.cloneQualifier(cell)); if (!Graph.Hidden.isHidden(key)) { ValueType propType = ValueType.valueOf(((Byte) ValueUtils.deserialize(CellUtil.cloneValue(cell))).intValue()); props.put(key, propType); } else if (key.equals(Constants.ELEMENT_ID)) { idType = ValueType.valueOf(((Byte) ValueUtils.deserialize(CellUtil.cloneValue(cell))).intValue()); } else if (key.equals(Constants.CREATED_AT)) { createdAt = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.UPDATED_AT)) { updatedAt = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } } return new LabelMetadata(type, label, idType, createdAt, updatedAt, props); } }
public Iterator<Vertex> queryVertices(Query query) { Iterator<HugeVertex> results = this.queryVerticesFromBackend(query); // Filter unused or incorrect records results = new FilterIterator<>(results, vertex -> { assert vertex.schemaLabel() != VertexLabel.NONE; // Filter hidden results if (!query.showHidden() && Graph.Hidden.isHidden(vertex.label())) { return false; } // Process results that query from left index or primary-key if (query.resultType().isVertex() && !filterResultFromIndexQuery(query, vertex)) { // Only index query will come here return false; } return true; }); @SuppressWarnings("unchecked") Iterator<Vertex> r = (Iterator<Vertex>) joinTxVertices(query, results); return r; }
private ValueType getPropertyType(LabelMetadata labelMetadata, String propertyKey, Object value, boolean doValidate) { Map<String, ValueType> propertyTypes = labelMetadata.propertyTypes(); if (!Graph.Hidden.isHidden(propertyKey)) { ValueType propertyType = propertyTypes.get(propertyKey); if (doValidate) { if (propertyType == null) { throw new HBaseGraphNotValidException("Property '" + propertyKey + "' has not been defined"); } ValueType valueType = ValueUtils.getValueType(value); if (value != null && propertyType != ValueType.ANY && (!(propertyType == ValueType.COUNTER && valueType == ValueType.LONG)) && (propertyType != valueType)) { throw new HBaseGraphNotValidException("Property '" + propertyKey + "' not of type " + propertyType); } } return propertyType; } return null; }
@Override public <R> Optional<R> get(String key) { if (key == null) { throw Graph.Variables.Exceptions.variableKeyCanNotBeNull(); } if (key.isEmpty()) { throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty(); } Vertex vertex = this.queryVariableVertex(key); if (vertex == null) { return Optional.empty(); } String type = vertex.value(Hidden.hide(VARIABLE_TYPE)); if (!Arrays.asList(TYPES).contains(Hidden.hide(type))) { throw Graph.Variables.Exceptions .dataTypeOfVariableValueNotSupported(type); } // The value of key VARIABLE_TYPE is the name of variable value return Optional.of(vertex.value(Hidden.hide(type))); }
private void initialize(final Neo4jGraphAPI baseGraph, final Configuration configuration) { this.configuration.copy(configuration); this.baseGraph = baseGraph; this.neo4jGraphVariables = new Neo4jGraphVariables(this); this.tx().readWrite(); final Optional<Boolean> hasMultiProperties = this.neo4jGraphVariables.get(Graph.Hidden.hide(CONFIG_MULTI_PROPERTIES)); final Optional<Boolean> hasMetaProperties = this.neo4jGraphVariables.get(Graph.Hidden.hide(CONFIG_META_PROPERTIES)); boolean supportsMetaProperties = hasMetaProperties.orElse(this.configuration.getBoolean(CONFIG_META_PROPERTIES, false)); boolean supportsMultiProperties = hasMultiProperties.orElse(this.configuration.getBoolean(CONFIG_MULTI_PROPERTIES, false)); if (supportsMultiProperties != supportsMetaProperties) throw new IllegalArgumentException(this.getClass().getSimpleName() + " currently supports either both meta-properties and multi-properties or neither"); if (!hasMultiProperties.isPresent()) this.neo4jGraphVariables.set(Graph.Hidden.hide(CONFIG_MULTI_PROPERTIES), supportsMultiProperties); if (!hasMetaProperties.isPresent()) this.neo4jGraphVariables.set(Graph.Hidden.hide(CONFIG_META_PROPERTIES), supportsMetaProperties); this.trait = supportsMultiProperties ? MultiMetaNeo4jTrait.instance() : NoMultiNoMetaNeo4jTrait.instance(); if (supportsMultiProperties) LOGGER.warn(this.getClass().getSimpleName() + " multi/meta-properties feature is considered experimental and should not be used in a production setting until this warning is removed"); this.tx().commit(); }
@Override public <V> Property<V> setProperty(final Neo4jVertexProperty vertexProperty, final String key, final V value) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null != vertexPropertyNode) { vertexPropertyNode.setProperty(key, value); return new Neo4jProperty<>(vertexProperty, key, value); } else { final Neo4jNode vertexNode = ((Neo4jVertex) vertexProperty.element()).getBaseVertex(); final Neo4jNode newVertexPropertyNode = ((WrappedGraph<Neo4jGraphAPI>) vertexProperty.element().graph()).getBaseGraph().createNode(VERTEX_PROPERTY_LABEL, vertexProperty.label()); newVertexPropertyNode.setProperty(T.key.getAccessor(), vertexProperty.key()); newVertexPropertyNode.setProperty(T.value.getAccessor(), vertexProperty.value()); newVertexPropertyNode.setProperty(vertexProperty.key(), vertexProperty.value()); newVertexPropertyNode.setProperty(key, value); vertexNode.connectTo(newVertexPropertyNode, Graph.Hidden.hide(vertexProperty.key())); vertexNode.setProperty(vertexProperty.key(), VERTEX_PROPERTY_TOKEN); Neo4jHelper.setVertexPropertyNode(vertexProperty, newVertexPropertyNode); return new Neo4jProperty<>(vertexProperty, key, value); } }
public static boolean hasLabels(final Traversal.Admin<?, ?> traversal) { for (final Step<?, ?> step : traversal.getSteps()) { for (final String label : step.getLabels()) { if (!Graph.Hidden.isHidden(label)) return true; } if (step instanceof TraversalParent) { for (final Traversal.Admin<?, ?> local : ((TraversalParent) step).getLocalChildren()) { if (TraversalHelper.hasLabels(local)) return true; } for (final Traversal.Admin<?, ?> global : ((TraversalParent) step).getGlobalChildren()) { if (TraversalHelper.hasLabels(global)) return true; } } } return false; }
/** * Determines whether the property key/value for the specified thing can be legally set. This is typically used as * a pre-condition check prior to setting a property. * * @param key the key of the property * @param value the value of the property * @throws IllegalArgumentException whether the key/value pair is legal and if not, a clear reason exception * message is provided */ public static void validateProperty(final String key, final Object value) throws IllegalArgumentException { if (null == value) throw Property.Exceptions.propertyValueCanNotBeNull(); if (null == key) throw Property.Exceptions.propertyKeyCanNotBeNull(); if (key.isEmpty()) throw Property.Exceptions.propertyKeyCanNotBeEmpty(); if (Graph.Hidden.isHidden(key)) throw Property.Exceptions.propertyKeyCanNotBeAHiddenKey(key); }