How to delete nodes without in-edge and out-edge - nebula-graph

NebulaGraph version: v3.1.0
How can I delete those nodes which have no links with other nodes?
delete isolated nodes, which has no in-edge and out-edge.

Try the statement as below:
(
lookup on player yield id(vertex) as vid
minus
(lookup on player yield id(vertex) as vid | go 1 step from $-.vid over * bidirect yield distinct id($^) as vid)
)
| delete vertex $-.vid

Related

neo4j delete nodey with children and without

I have simple graph and i want to find category and delete it. If category has children, than delete category and all children. I've made deletion category with children with this command:
MATCH path = (c:Category)-[*]->(cc:Category)
WHERE c.id = "95bec604-5da2-4297-b792-5a866e292df4"
DETACH DELETE path
But this comamnd does not work for single node, without children. How i can achieve it?
Add a 0 as the lower bound for the variable-length pattern. By default it's 1, but when it's 0 (provided the label used for the end node is also on the start node) this will allow it to match even when there are no relationships from the start node.
MATCH path = (c:Category)-[*0..]->(cc:Category)
WHERE c.id = "95bec604-5da2-4297-b792-5a866e292df4"
DETACH DELETE path
In general, this approach would work if you want to delete the entire path:
MATCH path = ( some path )
FOREACH (node IN nodes(path) |
DETACH DELETE node
)

Improve Kusto Query - mailbox audit log search

I am trying to identify shared mailboxes that aren't in use. Checked "Search-MailboxAuditLog" already and some mailboxes do not return any results even tho auditing enabled, but can see activity in Azure sentinel.
Is there a way to improve below Kusto code? (During testing tried mailboxes with activities but sometimes do not get any results from the query)
With Kusto, Is there a way to loop through "mbs" like powershell "foreach ( $item in $mbs)"?
Thanks,
let mbs = datatable (name: string)
[
"xxx1#something.com",
"xxx2#something.com",
"xxx3#something.com",
];
OfficeActivity
| where OfficeWorkload == "Exchange" and TimeGenerated > ago(30d)
| where MailboxOwnerUPN in~ (mbs)
| distinct MailboxOwnerUPN
Update : Need help with the query
Input would be list of shared mailbox UPNs
Output would be list of shared mailboxes with any activity, example MBs with any action in “Operation" filed
"in" doesn't work on datatables (tabular inputs) like that; it is not a "filter", it is an "operator". The "where" is effectively the "foreach" you are referring to.
Given the sample input, the query could probably be written as:
OfficeActivity //tabular input with many records
| TimeGenerated > ago(30d) //Filter records to window of interest first
| where OfficeWorkload == "Exchange" //foreach row
| where MailboxOwnerUPN in~ ( //foreach row
"xxx1#something.com","xxx2#something.com","xxx3#something.com"
)
| distinct MailboxOwnerUPN
You can see it in the docs at https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/inoperator#arguments where "col" is the "column to filter"

Is there any simpler way to see if a field has a certain value?

To see if there is a Todd in my database I currently do the following:
SELECT * FROM MyTable WHERE name='Todd' LIMIT 1
I then check the Cursor to see if its size == 1. Is there a way to return a 0 or 1 from the select statement if the condition is false or true, rather than a list of fields?
You can do
SELECT COUNT(*) it_exists
FROM
(
SELECT 1
FROM MyTable
WHERE name = 'Todd'
LIMIT 1
) q;
An inner select guarantees that LIMIT is applied. Meaning if you have hypothetically thousands of matching rows database engine will stop and return results after the first one instead of going through all of them.
Output
| it_exists |
|-----------|
| 1 |
Here is SQLFiddle demo

SQLite best way to save and traverse arrays of strings

I have a table that looks like this.
| id | coords |
| 0 | [1,0],[4,3],[4,9],[9,3],[1,8]
| 1 | [3,6],[3,8],[7,4],[5,2],[2,1]
.. and more
There will be around 70k-100k rows at most, and the CPU is not very powerful.
What is the fastest and least cpu intensive SQLite statement i can use to determine which id has any given coordinate? No two id's share a coordinate.
Example.
SELECT * FROM mytable WHERE coords LIKE '%[[]3,8]%'
I imagine the LIKE statement above will get pretty intensive right?
You should always try to have a properly normalized database.
In this case, the coordinate list is not in the first normal form.
If you move the coordinates to a separate table, you can search for coordinates with a simple and obvious query, which can be be sped up with an index:
CREATE TABLE MyTable (
ID,
[...]
);
CREATE TABLE MyCoordinates (
MyTableID,
CoordX,
CoordY
);
SELECT MyTableID FROM MyCoordinates WHERE X = ? AND Y = ?;

Neo4j 2.1+ - Cypher - Return number of times a relationship appears when using DISTINCT

I'm struggling with maybe a simple query but I'm unable to find an answer :
Let's give the following simple schema :
Nodes :
Package1
Library1
Library2
Library3
Relationships:
(Library1)-[:USES {in_version:'1.1'}]->(Package1)
(Library2)-[:USES {in_version:'1.2'}]->(Package1)
(Library3)-[:USES {in_version:'1.2'}]->(Package1)
Simple no ?
So what I would like is to return my package node, and group relationships by distinct in_version property and the number of times the in_version is used
This should be the return I would like to have :
package | in_version | usage |
Package 1 | 1.1 | 1 |
Package 1 | 1.2 | 2 |
I tried to combine distinct, collect, ..but I'm struggling currently
Edit
My last query is as follow :
MATCH (p:Package)<-[r:USES]-()
WHERE p.name = 'Package1'
WITH p, collect(r) as v
UNWIND v as x
RETURN distinct x.in_version, count(x) as usage
ORDER BY usage DESC
And I can get the versions and the usage correctly.
But if I want to add the package name to the return, cypher complain about the '.' in x.in_version
MATCH (p:Package)<-[r:USES]-()
WHERE p.name = 'Package1'
WITH p, collect(r) as v
UNWIND v as x
RETURN p.name, distinct x.in_version, count(x) as usage
ORDER BY usage DESC
While the p.name is not necessary for this query as I know it in advance, the goal is to 1st filter packages having the most uses relations and then return this query by package in one time
Thanks in advance
Chris
Try this query
match (lib)-[r:USES]->(pack)
where has(r.in_version)
with pack, collect(r.in_version) as vers,lib
with pack,vers ,collect(lib) as libs,count(lib) as usage
return pack as package,vers as in_version,usage

Resources