use of org.neo4j.common.EntityType in project neo4j by neo4j.
the class GraphCountsSection method constraints.
private static List<Map<String, Object>> constraints(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) {
List<Map<String, Object>> constraints = new ArrayList<>();
Iterator<ConstraintDescriptor> iterator = schemaRead.constraintsGetAll();
while (iterator.hasNext()) {
ConstraintDescriptor constraint = iterator.next();
EntityType entityType = constraint.schema().entityType();
Map<String, Object> data = new HashMap<>();
data.put("properties", map(constraint.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
data.put("type", constraintType(constraint));
int entityTokenId = constraint.schema().getEntityTokenIds()[0];
switch(entityType) {
case NODE:
data.put("label", anonymizer.label(tokens.labelGetName(entityTokenId), entityTokenId));
constraints.add(data);
break;
case RELATIONSHIP:
data.put("relationshipType", anonymizer.relationshipType(tokens.relationshipTypeGetName(entityTokenId), entityTokenId));
constraints.add(data);
break;
default:
}
}
return constraints;
}
use of org.neo4j.common.EntityType in project neo4j by neo4j.
the class SchemaRuleSerialization35 method readMultiTokenSchema.
private static SchemaDescriptor readMultiTokenSchema(ByteBuffer source) throws MalformedSchemaRuleException {
byte schemaDescriptorType = source.get();
EntityType type;
switch(schemaDescriptorType) {
case SIMPLE_LABEL:
type = EntityType.NODE;
break;
case SIMPLE_REL_TYPE:
type = EntityType.RELATIONSHIP;
break;
default:
throw new MalformedSchemaRuleException(format("Got unknown schema descriptor type '%d'.", schemaDescriptorType));
}
int[] entityTokenIds = readTokenIdList(source);
int[] propertyIds = readTokenIdList(source);
return SchemaDescriptor.fulltext(type, entityTokenIds, propertyIds);
}
use of org.neo4j.common.EntityType in project neo4j by neo4j.
the class TokenScanWriteMonitor method dump.
public static void dump(FileSystemAbstraction fs, DatabaseLayout databaseLayout, Dumper dumper, TxFilter txFilter, EntityType entityType) throws IOException {
Path writeLogFile = writeLogBaseFile(databaseLayout, entityType);
String writeLogFileBaseName = writeLogFile.getFileName().toString();
Path[] files = fs.listFiles(databaseLayout.databaseDirectory(), name -> name.getFileName().toString().startsWith(writeLogFileBaseName));
Arrays.sort(files, comparing(file -> file.getFileName().toString().equals(writeLogFileBaseName) ? 0 : millisOf(file)));
long session = 0;
for (Path file : files) {
dumper.file(file);
session = dumpFile(fs, file, dumper, txFilter, session);
}
}
use of org.neo4j.common.EntityType in project neo4j by neo4j.
the class FulltextProcedures method queryFulltextForNodes.
@SystemProcedure
@Description("Query the given full-text index. Returns the matching nodes, and their Lucene query score, ordered by score. " + "Valid keys for the options map are: 'skip' to skip the top N results; 'limit' to limit the number of results returned.")
@Procedure(name = "db.index.fulltext.queryNodes", mode = READ)
public Stream<NodeOutput> queryFulltextForNodes(@Name("indexName") String name, @Name("queryString") String query, @Name(value = "options", defaultValue = "{}") Map<String, Object> options) throws Exception {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
IndexDescriptor indexReference = getValidIndex(name);
awaitOnline(indexReference);
EntityType entityType = indexReference.schema().entityType();
if (entityType != NODE) {
throw new IllegalArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for nodes.");
}
NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
IndexReadSession indexSession = tx.dataRead().indexReadSession(indexReference);
IndexQueryConstraints constraints = queryConstraints(options);
tx.dataRead().nodeIndexSeek(indexSession, cursor, constraints, PropertyIndexQuery.fulltextSearch(query));
Spliterator<NodeOutput> spliterator = new SpliteratorAdaptor<>() {
@Override
public boolean tryAdvance(Consumer<? super NodeOutput> action) {
while (cursor.next()) {
long nodeReference = cursor.nodeReference();
float score = cursor.score();
NodeOutput nodeOutput = NodeOutput.forExistingEntityOrNull(transaction, nodeReference, score);
if (nodeOutput != null) {
action.accept(nodeOutput);
return true;
}
}
cursor.close();
return false;
}
};
Stream<NodeOutput> stream = StreamSupport.stream(spliterator, false);
return stream.onClose(cursor::close);
}
use of org.neo4j.common.EntityType in project neo4j by neo4j.
the class GraphCountsSection method indexes.
private static List<Map<String, Object>> indexes(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) throws IndexNotFoundKernelException {
List<Map<String, Object>> indexes = new ArrayList<>();
Iterator<IndexDescriptor> iterator = schemaRead.indexesGetAll();
while (iterator.hasNext()) {
IndexDescriptor index = iterator.next();
IndexType indexType = index.getIndexType();
if (indexType == IndexType.FULLTEXT) {
/* For full text indexes, we currently do not return its options, which makes returning information on
* this index not useful and if the index type is ignored, this would even be misleading.
*/
continue;
}
EntityType entityType = index.schema().entityType();
Map<String, Object> data = new HashMap<>();
switch(entityType) {
case NODE:
data.put("labels", map(index.schema().getEntityTokenIds(), id -> anonymizer.label(tokens.labelGetName(id), id)));
break;
case RELATIONSHIP:
data.put("relationshipTypes", map(index.schema().getEntityTokenIds(), id -> anonymizer.relationshipType(tokens.relationshipTypeGetName(id), id)));
break;
default:
}
data.put("properties", map(index.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
var indexSample = schemaRead.indexSample(index);
data.put("totalSize", indexSample.indexSize());
data.put("updatesSinceEstimation", indexSample.updates());
data.put("estimatedUniqueSize", indexSample.uniqueValues());
data.put("indexType", indexType.name());
indexes.add(data);
}
return indexes;
}
Aggregations