use of org.neo4j.procedure.Name in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ, deprecatedBy = "SHOW INDEXES command")
public Stream<IndexResult> listIndexes() {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
TokenRead tokenRead = kernelTransaction.tokenRead();
IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
List<IndexResult> result = new ArrayList<>();
for (IndexDescriptor index : indexes) {
IndexResult indexResult;
indexResult = asIndexResult(tokenRead, schemaRead, index);
result.add(indexResult);
}
result.sort(Comparator.comparing(r -> r.name));
return result.stream();
}
use of org.neo4j.procedure.Name 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.Name 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.Name in project neo4j-apoc-procedures by neo4j-contrib.
the class LoadJson method loadJsonStream.
public static Stream<MapResult> loadJsonStream(@Name("url") String url, @Name("headers") Map<String, Object> headers, @Name("payload") String payload, String path, boolean failOnError) {
headers = null != headers ? headers : new HashMap<>();
headers.putAll(extractCredentialsIfNeeded(url, failOnError));
Stream<Object> stream = JsonUtil.loadJson(url, headers, payload, path, failOnError);
return stream.flatMap((value) -> {
if (value instanceof Map) {
return Stream.of(new MapResult((Map) value));
}
if (value instanceof List) {
if (((List) value).isEmpty())
return Stream.empty();
if (((List) value).get(0) instanceof Map)
return ((List) value).stream().map((v) -> new MapResult((Map) v));
return Stream.of(new MapResult(Collections.singletonMap("result", value)));
}
if (!failOnError)
throw new RuntimeException("Incompatible Type " + (value == null ? "null" : value.getClass()));
else
return Stream.of(new MapResult(Collections.emptyMap()));
});
}
use of org.neo4j.procedure.Name in project neo4j-apoc-procedures by neo4j-contrib.
the class DegreeDistribution method degrees.
@Procedure
public Stream<DegreeStats.Result> degrees(@Name(value = "types", defaultValue = "") String types) {
return Util.withStatement(db, (st, ops) -> {
List<DegreeStats> stats = prepareStats(types, ops);
PrimitiveLongIterator it = ops.nodesGetAll();
List<Future> futures = new ArrayList<>();
do {
long[] batch = Util.takeIds(it, 10000);
futures.add(Util.inTxFuture(Pools.DEFAULT, db, (stmt, ro) -> computeDegree(ro, stats, batch)));
Util.removeFinished(futures);
} while (it.hasNext());
Util.waitForFutures(futures);
return stats.stream().map(DegreeStats::done);
});
}
Aggregations