Ejemplo n.º 1
0
        private void ScanEverythingBelongingToNodes(NodeMappings nodeMappings)
        {
            using (NodeCursor nodeCursor = _cursors.allocateNodeCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor())
            {
                _dataRead.allNodesScan(nodeCursor);
                while (nodeCursor.Next())
                {
                    // each node
                    SortedLabels labels = SortedLabels.From(nodeCursor.Labels());
                    nodeCursor.Properties(propertyCursor);
                    MutableIntSet propertyIds = IntSets.mutable.empty();

                    while (propertyCursor.Next())
                    {
                        Value currentValue           = propertyCursor.PropertyValue();
                        int   propertyKeyId          = propertyCursor.PropertyKey();
                        Pair <SortedLabels, int> key = Pair.of(labels, propertyKeyId);
                        UpdateValueTypeInMapping(currentValue, key, nodeMappings.LabelSetANDNodePropertyKeyIdToValueType);

                        propertyIds.add(propertyKeyId);
                    }
                    propertyCursor.Close();

                    MutableIntSet oldPropertyKeySet = nodeMappings.LabelSetToPropertyKeys.getOrDefault(labels, _emptyPropertyIdSet);

                    // find out which old properties we did not visited and mark them as nullable
                    if (oldPropertyKeySet == _emptyPropertyIdSet)
                    {
                        if (propertyIds.size() == 0)
                        {
                            // Even if we find property key on other nodes with those labels, set all of them nullable
                            nodeMappings.NullableLabelSets.Add(labels);
                        }

                        propertyIds.addAll(oldPropertyKeySet);
                    }
                    else
                    {
                        MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                        currentPropertyIdsHelperSet.addAll(propertyIds);
                        propertyIds.removeAll(oldPropertyKeySet);                                     // only the brand new ones in propIds now
                        oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);                     // only the old ones that are not on the new node

                        propertyIds.addAll(oldPropertyKeySet);
                        propertyIds.forEach(id =>
                        {
                            Pair <SortedLabels, int> key = Pair.of(labels, id);
                            nodeMappings.LabelSetANDNodePropertyKeyIdToValueType[key].setNullable();
                        });

                        propertyIds.addAll(currentPropertyIdsHelperSet);
                    }

                    nodeMappings.LabelSetToPropertyKeys[labels] = propertyIds;
                }
                nodeCursor.Close();
            }
        }
Ejemplo n.º 2
0
        private void ScanEverythingBelongingToRelationships(RelationshipMappings relMappings)
        {
            using (RelationshipScanCursor relationshipScanCursor = _cursors.allocateRelationshipScanCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor())
            {
                _dataRead.allRelationshipsScan(relationshipScanCursor);
                while (relationshipScanCursor.Next())
                {
                    int typeId = relationshipScanCursor.Type();
                    relationshipScanCursor.Properties(propertyCursor);
                    MutableIntSet propertyIds = IntSets.mutable.empty();

                    while (propertyCursor.Next())
                    {
                        int propertyKey = propertyCursor.PropertyKey();

                        Value           currentValue = propertyCursor.PropertyValue();
                        Pair <int, int> key          = Pair.of(typeId, propertyKey);
                        UpdateValueTypeInMapping(currentValue, key, relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType);

                        propertyIds.add(propertyKey);
                    }
                    propertyCursor.Close();

                    MutableIntSet oldPropertyKeySet = relMappings.RelationshipTypeIdToPropertyKeys.getOrDefault(typeId, _emptyPropertyIdSet);

                    // find out which old properties we did not visited and mark them as nullable
                    if (oldPropertyKeySet == _emptyPropertyIdSet)
                    {
                        if (propertyIds.size() == 0)
                        {
                            // Even if we find property key on other rels with this type, set all of them nullable
                            relMappings.NullableRelationshipTypes.Add(typeId);
                        }

                        propertyIds.addAll(oldPropertyKeySet);
                    }
                    else
                    {
                        MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                        currentPropertyIdsHelperSet.addAll(propertyIds);
                        propertyIds.removeAll(oldPropertyKeySet);                                     // only the brand new ones in propIds now
                        oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);                     // only the old ones that are not on the new rel

                        propertyIds.addAll(oldPropertyKeySet);
                        propertyIds.forEach(id =>
                        {
                            Pair <int, int> key = Pair.of(typeId, id);
                            relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType[key].setNullable();
                        });

                        propertyIds.addAll(currentPropertyIdsHelperSet);
                    }

                    relMappings.RelationshipTypeIdToPropertyKeys[typeId] = propertyIds;
                }
                relationshipScanCursor.Close();
            }
        }
Ejemplo n.º 3
0
        private IList <NodePropertySchemaInfoResult> ProduceResultsForNodes(NodeMappings nodeMappings)
        {
            IList <NodePropertySchemaInfoResult> results = new List <NodePropertySchemaInfoResult>();

            foreach (SortedLabels labelSet in nodeMappings.LabelSetToPropertyKeys.Keys)
            {
                // lookup label names and produce list of names and produce String out of them
                IList <string> labelNames = new List <string>();
                for (int i = 0; i < labelSet.NumberOfLabels(); i++)
                {
                    string name = nodeMappings.LabelIdToLabelName[labelSet.Label(i)];
                    labelNames.Add(name);
                }
                labelNames.Sort();                         // this is optional but waaaaay nicer
                StringBuilder labelsConcatenator = new StringBuilder();
                foreach (string item in labelNames)
                {
                    labelsConcatenator.Append(":`").Append(item).Append("`");
                }
                string labels = labelsConcatenator.ToString();

                // lookup property value types
                MutableIntSet propertyIds = nodeMappings.LabelSetToPropertyKeys[labelSet];
                if (propertyIds.size() == 0)
                {
                    results.Add(new NodePropertySchemaInfoResult(labels, labelNames, null, null, false));
                }
                else
                {
                    propertyIds.forEach(propId =>
                    {
                        string propName = _propertyIdToPropertyNameMapping[propId];
                        ValueTypeListHelper valueTypeListHelper = nodeMappings.LabelSetANDNodePropertyKeyIdToValueType[Pair.of(labelSet, propId)];
                        if (nodeMappings.NullableLabelSets.Contains(labelSet))
                        {
                            results.Add(new NodePropertySchemaInfoResult(labels, labelNames, propName, valueTypeListHelper.CypherTypesList, false));
                        }
                        else
                        {
                            results.Add(new NodePropertySchemaInfoResult(labels, labelNames, propName, valueTypeListHelper.CypherTypesList, valueTypeListHelper.Mandatory));
                        }
                    });
                }
            }
            return(results);
        }
Ejemplo n.º 4
0
        private IList <RelationshipPropertySchemaInfoResult> ProduceResultsForRelationships(RelationshipMappings relMappings)
        {
            IList <RelationshipPropertySchemaInfoResult> results = new List <RelationshipPropertySchemaInfoResult>();

            foreach (int?typeId in relMappings.RelationshipTypeIdToPropertyKeys.Keys)
            {
                // lookup typ name
                string name = relMappings.RelationshipTypIdToRelationshipName[typeId];
                name = ":`" + name + "`";                         // escaping

                // lookup property value types
                MutableIntSet propertyIds = relMappings.RelationshipTypeIdToPropertyKeys[typeId];
                if (propertyIds.size() == 0)
                {
                    results.Add(new RelationshipPropertySchemaInfoResult(name, null, null, false));
                }
                else
                {
                    string finalName = name;
                    propertyIds.forEach(propId =>
                    {
                        string propName = _propertyIdToPropertyNameMapping[propId];
                        ValueTypeListHelper valueTypeListHelper = relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType[Pair.of(typeId, propId)];
                        if (relMappings.NullableRelationshipTypes.Contains(typeId))
                        {
                            results.Add(new RelationshipPropertySchemaInfoResult(finalName, propName, valueTypeListHelper.CypherTypesList, false));
                        }
                        else
                        {
                            results.Add(new RelationshipPropertySchemaInfoResult(finalName, propName, valueTypeListHelper.CypherTypesList, valueTypeListHelper.Mandatory));
                        }
                    });
                }
            }
            return(results);
        }