use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class FulltextIndexProviderTest method prepDB.
@BeforeEach
void prepDB() {
Label hej = label("hej");
Label ha = label("ha");
Label he = label("he");
RelationshipType hejType = RelationshipType.withName("hej");
try (Transaction transaction = db.beginTx()) {
node1 = transaction.createNode(hej, ha, he);
node1.setProperty("hej", "value");
node1.setProperty("ha", "value1");
node1.setProperty("he", "value2");
node1.setProperty("ho", "value3");
node2 = transaction.createNode();
Relationship rel = node1.createRelationshipTo(node2, hejType);
rel.setProperty("hej", "valuuu");
rel.setProperty("ha", "value1");
rel.setProperty("he", "value2");
rel.setProperty("ho", "value3");
transaction.commit();
}
try (Transaction tx = db.beginTx()) {
TokenRead tokenRead = tokenRead(tx);
labelIdHej = tokenRead.nodeLabel(hej.name());
labelIdHa = tokenRead.nodeLabel(ha.name());
labelIdHe = tokenRead.nodeLabel(he.name());
relTypeIdHej = tokenRead.relationshipType(hejType.name());
propIdHej = tokenRead.propertyKey("hej");
propIdHa = tokenRead.propertyKey("ha");
propIdHe = tokenRead.propertyKey("he");
propIdHo = tokenRead.propertyKey("ho");
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldAnswerRangeIfCypherCompatible.
@Test
void shouldAnswerRangeIfCypherCompatible() throws KernelException {
IndexDescriptor indexReference;
Label containsLabel = label("containsLabel");
String containsProp = "containsProp";
long nodea;
long nodeaa;
long nodeaapa;
long nodeapa1;
long nodeapa2;
try (Transaction tx = db.beginTx()) {
createNode(tx, containsLabel, containsProp, "1");
nodea = createNode(tx, containsLabel, containsProp, "a");
nodeaa = createNode(tx, containsLabel, containsProp, "aa");
nodeaapa = createNode(tx, containsLabel, containsProp, "aapa");
nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
createNode(tx, containsLabel, containsProp, "bpa");
createNode(tx, containsLabel, containsProp, "A");
tx.commit();
}
int containsLabelId;
int containsPropertyId;
try (Transaction tx = db.beginTx()) {
TokenRead tokenRead = tokenRead(tx);
containsLabelId = tokenRead.nodeLabel(containsLabel.name());
containsPropertyId = tokenRead.propertyKey(containsProp);
}
indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", true, "apa", true), nodea, nodeaa, nodeaapa, nodeapa1, nodeapa2);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", false, "apa", true), nodeaa, nodeaapa, nodeapa1, nodeapa2);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", true, "apa", false), nodea, nodeaa, nodeaapa);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", false, "apa", false), nodeaa, nodeaapa);
}
controller.restartDbms();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", true, "apa", true), nodea, nodeaa, nodeaapa, nodeapa1, nodeapa2);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", false, "apa", true), nodeaa, nodeaapa, nodeapa1, nodeapa2);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", true, "apa", false), nodea, nodeaa, nodeaapa);
assertQueryResult(ktx, rangeQuery(containsPropertyId, "a", false, "apa", false), nodeaa, nodeaapa);
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class BuiltInProcedures method listLabels.
@SystemProcedure
@Description("List all available labels in the database.")
@Procedure(name = "db.labels", mode = READ)
public Stream<LabelResult> listLabels() {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
AccessMode mode = kernelTransaction.securityContext().mode();
TokenRead tokenRead = kernelTransaction.tokenRead();
List<LabelResult> labelsInUse;
try (KernelTransaction.Revertable ignore = kernelTransaction.overrideWith(SecurityContext.AUTH_DISABLED)) {
// Get all labels that are in use as seen by a super user
labelsInUse = stream(LABELS.inUse(kernelTransaction)).filter(label -> mode.allowsTraverseNode(tokenRead.nodeLabel(label.name()))).map(LabelResult::new).collect(Collectors.toList());
}
return labelsInUse.stream();
}
use of org.neo4j.internal.kernel.api.TokenRead 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;
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class TokensSection method retrieve.
static Stream<RetrieveResult> retrieve(Kernel kernel) throws TransactionFailureException {
try (KernelTransaction tx = kernel.beginTransaction(KernelTransaction.Type.EXPLICIT, LoginContext.AUTH_DISABLED)) {
TokenRead tokens = tx.tokenRead();
List<String> labels = new ArrayList<>(tokens.labelCount());
tokens.labelsGetAllTokens().forEachRemaining(t -> labels.add(t.name()));
List<String> relationshipTypes = new ArrayList<>(tokens.relationshipTypeCount());
tokens.relationshipTypesGetAllTokens().forEachRemaining(t -> relationshipTypes.add(t.name()));
List<String> propertyKeys = new ArrayList<>(tokens.propertyKeyCount());
tokens.propertyKeyGetAllTokens().forEachRemaining(t -> propertyKeys.add(t.name()));
Map<String, Object> data = new HashMap<>();
data.put("labels", labels);
data.put("relationshipTypes", relationshipTypes);
data.put("propertyKeys", propertyKeys);
return Stream.of(new RetrieveResult(Sections.TOKENS, data));
}
}
Aggregations