use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
try (Statement statement = tx.acquireStatement()) {
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
indexes.addAll(uniqueIndexes);
indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
ArrayList<IndexResult> result = new ArrayList<>();
for (NewIndexDescriptor index : indexes) {
try {
String type;
if (uniqueIndexes.contains(index)) {
type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
} else {
type = IndexType.NODE_LABEL_PROPERTY.typeName();
}
result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
} catch (IndexNotFoundKernelException e) {
throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
}
}
return result.stream();
}
}
use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.
the class SchemaIndex method orderedByText.
@Procedure
@Description("apoc.index.orderedByText(label,key,operator,value,sort-relevance,limit) yield node - schema string search which keeps index order and adds limit, operator is 'STARTS WITH' or 'CONTAINS'")
public Stream<NodeResult> orderedByText(@Name("label") String label, @Name("key") String key, @Name("operator") String operator, @Name("value") String value, @Name("relevance") boolean relevance, @Name("limit") long limit) throws SchemaRuleNotFoundException, IndexNotFoundKernelException, DuplicateSchemaRuleException {
SortedIndexReader sortedIndexReader = getSortedIndexReader(label, key, limit, getSort(value, value, relevance));
PrimitiveLongIterator it = queryForString(sortedIndexReader, operator, value);
return Util.toLongStream(it).mapToObj(id -> new NodeResult(db.getNodeById(id)));
}
use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.
the class LoadCsv method csv.
@Procedure
@Description("apoc.load.csv('url',{config}) YIELD lineNo, list, map - load CSV fom URL as stream of values,\n config contains any of: {skip:1,limit:5,header:false,sep:'TAB',ignore:['tmp'],arraySep:';',mapping:{years:{type:'int',arraySep:'-',array:false,name:'age',ignore:false}}")
public Stream<CSVResult> csv(@Name("url") String url, @Name("config") Map<String, Object> config) {
boolean failOnError = booleanValue(config, "failOnError", true);
try {
CountingReader reader = FileUtils.readerFor(url);
char separator = separator(config, "sep", DEFAULT_SEP);
char arraySep = separator(config, "arraySep", DEFAULT_ARRAY_SEP);
long skip = longValue(config, "skip", 0L);
boolean hasHeader = booleanValue(config, "header", true);
long limit = longValue(config, "limit", Long.MAX_VALUE);
EnumSet<Results> results = EnumSet.noneOf(Results.class);
for (String result : value(config, "results", asList("map", "list"))) {
results.add(Results.valueOf(result));
}
List<String> ignore = value(config, "ignore", emptyList());
List<String> nullValues = value(config, "nullValues", emptyList());
Map<String, Map<String, Object>> mapping = value(config, "mapping", Collections.emptyMap());
Map<String, Mapping> mappings = createMapping(mapping, arraySep, ignore);
CSVReader csv = new CSVReader(reader, separator);
String[] header = getHeader(hasHeader, csv, ignore, mappings);
boolean checkIgnore = !ignore.isEmpty() || mappings.values().stream().anyMatch(m -> m.ignore);
return StreamSupport.stream(new CSVSpliterator(csv, header, url, skip, limit, checkIgnore, mappings, nullValues, results), false);
} catch (IOException e) {
if (!failOnError)
return Stream.of(new CSVResult(new String[0], new String[0], 0, true, Collections.emptyMap(), emptyList(), EnumSet.noneOf(Results.class)));
else
throw new RuntimeException("Can't read CSV from URL " + cleanUrl(url), e);
}
}
use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.
the class Locks method lockInfo.
@Procedure("apoc.monitor.locks")
@Deprecated
@Description("deprecated, the information is not provided by neo4j anymore.\napoc.monitor.locks(minWaitTime) yield advertedDeadLocks, lockCount, contendedLockCount, minimumWaitTimeMs, contendedLocks, info")
public Stream<LockInfoResult> lockInfo(@Name("minWaitTime") Long minWaitTime) {
if (minWaitTime == null || minWaitTime < 0)
minWaitTime = 0L;
ObjectName objectName = getObjectName(database, JMX_OBJECT_NAME);
CompositeData[] locks = getAttribute(objectName, JMX_LOCKS_KEY);
List<Map<String, Object>> lockInfos = getContentedLocks(objectName, minWaitTime);
Long avertedDeadLocks = getAttribute(objectName, JMX_NR_ADVERTED_DEADLOCKS_KEY);
LockInfoResult info = new LockInfoResult(minWaitTime, locks.length, avertedDeadLocks, lockInfos.size(), lockInfos);
return Stream.of(info);
}
use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.
the class Kernel method kernel.
@Procedure
@Description("apoc.monitor.kernel() returns informations about the neo4j kernel")
public Stream<KernelInfoResult> kernel() {
ObjectName objectName = getObjectName(database, JMX_OBJECT_NAME);
KernelInfoResult info = new KernelInfoResult(getAttribute(objectName, READ_ONLY), getAttribute(objectName, KERNEL_VERSION), getAttribute(objectName, STORE_ID), getAttribute(objectName, START_TIME), getAttribute(objectName, DB_NAME), getAttribute(objectName, STORE_LOG_VERSION), getAttribute(objectName, STORE_CREATION_DATE));
return Stream.of(info);
}
Aggregations