Why does SELECT then performing a step like hasId() change what was selected? - gremlin

Am I not using select() properly in my code? When I re-select("pair") for some reason, what it contained originally has been updated after performing some step. Shouldn't what was labeled using as() preserve what was contained?
g.V()
.hasLabel("Project")
.hasId("parentId","childId").as("pair")
.select("pair")
.hasId("parentId").as("parent")
.select("pair") // no longer what it was originally set to

I think this is expected. You (presumably) find two vertices with hasId("parentId","childId") and so the first select("pair") would of course show each vertex. But, then you filter again, hasId("parentId") and kill the traverser that contains the vertex with the id of "childId". It gets filtered away and therefore never triggers the second/last select("pair") step and would only therefore return the one vertex that has the id of "parentId".

Related

How to filter edges by attributes in Gephi?

I have some edges with their corresponding labels, and I want to filter in only records with label 1, but it just doesn't work as shown below.
The function works to filter in nodes but doesn't work for edges. I thought it would be due to that there were too many edges, then I tried .gexf files with only hundreds of edges, but the problem remains. I also tried to create a new column in the app or create the column using Python in the .gexf file, but both failed. Sometimes an error arises: an error occurred while fetching data.
I wonder how to filter in only matched edges on Gephi?
It seems that you must have an entry for every edge in the Label column.
What you can do in your situation:
Sort the edges according to Label by clicking on the column name (might click twice).
Select edges that don't have a label yet.
Right-click: Edit all edges.
Give a default Label in the edit menu.
If you don't already have labels and want to manually assign them in the Data Table, you can also use Fill column with a value and give a default value to every edge.
This is probably a bug since we get a NullPointerException sometimes, probably because filtering doesn't expect null values in the label column (at least judging after a quick glance at the stack trace). You might file this to their GitHub Issue Page over here.
In addition:
A useful tutorial notes: "However, looking at the "catalogue" of filters, we see no filter on Label. The reason is that Label is an internal property of nodes, inaccessible to filters. So we must first copy the Labels of the nodes in a new attribute, which we will be able to apply a filter on." Whilst the tutorial refers to nodes the same idea works for edges: create a new edge column named whatever you choose and copy your edge labels into it. You can filter using this new column. NB: I can find the filter under Attributes: Equal but not Attributes: Partition, but it may help you. NNB: If you can't see the filter after creating the new column, you may have to hit Reset at the top of the Filters panel.

Gremlin where query won't use values from labeled vertices

I'm trying to find the edge between 2 vertexes in a single query on Neptun, but something is really weird.
Here's the query
g.V().has("PRINCIPAL", "principal id", "Test User").as("principal").id().as("principal_id")
.select("principal").out().hasLabel("LICENSE").as("license").valueMap(true).as("license_vm")
.select("license").in("is attached to").as("attachments")
.select("license").inE().where(outV().hasId(select("principal").id()))
.valueMap(true)
I know it's complicated, but here's the idea:
Visit a PRINCIPAL vertex, save a reference to is as "principal" and a reference to its id as "principal_id"
Visit its out() vertices and label them as "license", I'm also saving their valuemaps for later
return to license, and get all of the in() vertices that are associated by an edge labelled "is attached to", save a reference to those as "attachments"
return to license, but now, I want to get the in-edge that points to my "principal" (from earlier). This is where it gets weird, no matter what I do here, I can't get it to recognize the principal in a where clause. THe above example fails, but if I copy-paste the literal id, it works fine
What am I missing?
Replace the where step on the second to last line of the query with:
filter(out().where(eq('principal')).by(T.id))
That should get it working.
The hasId step can take either a predicate such as gt(123) or a list of one or more ID values. That's why it works when you use the ID value.

Can we filter multiple labels simultaneously

I have a scenario where I have to check multiple vertices with different labels and match their properties under a parent vertex. And then return the parent vertex if everything matches fine.
I tried writing queries with 'and' clause and 'where' clause but none is working:
Here are my trials:
g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().inV().aggregate('x').hasLabel('schedule').has('name', '3').as('b').select('x').hasLabel('states').has('name', 'federal').as('c').select('a')
g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().where(inV().hasLabel('schedule').has('name', '3')).where(inV().hasLabel('states').has('name', 'federal')).select('a')
g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().and(inV().hasLabel('schedule').has('name', '3'),inV().hasLabel('states').has('name', 'federal')).select('a')
g.V().hasLabel('schedule').inE().outV().hasLabel('url').as('a').outE().inV().aggregate('x').hasLabel('schedule').has('name', '3').as('b').select('x').unfold().hasLabel('states').has('name', 'federal').as('c').select('a')
Please guide me through the right path
You can definitely simplify your approach. I don't think you need the step labels and select() for what you are doing which is good, because they add cost to your traversal. I tried to re-write the first traversal you supplied and I"m hoping I have the logic right, but regardless, I'm thinking you will get the idea for what you need to do when you see the change:
g.V().hasLabel('schedule').in().hasLabel('url').
where(and(out().hasLabel('schedule').has('name', '3'),
out().hasLabel('states').has('name', 'federal')))
You already have the "parent" that you want to return on the first line, so just do a filter with where() and add your filtering logic there to traverse away from each of those "parents".

check duplicate values in oracle forms multi record block

What I wanted is to display an alert when I move to the next row if the record that I inserted is already one of the records in the multi record block.
and in what trigger must I put it?
There are several options you can use.
One is to POST values entered (in WHEN-NEW-RECORD-INSTANCE) trigger. It will, well, post everything you entered so far. Then, you can write a WHEN-VALIDATE-ITEM trigger which SELECTs from that table and checks whether such a value already exists. Alternatively, if there's the UNIQUE CONSTRAINT on that (those) column(s), database will do its job itself, i.e. raise an exception.
Another option is to literally loop through all rows in a block and compare the first row's value with all the others, then the second row's values with all of them, etc.
Or, you can use a Record Group (usually used for Lists of Values). Basically, you'd check whether value you entered exists in a record group. More info, along with a FMB file, on Craig's blog.
Or, you can use calculated items, as described enter link description here (FMB attached as well).
As you can see, quite a few ways to do that; explore each of them and pick the one you find the most useful / attractive / easy to implement.

Order of different collection type in java?

Just wanted to confirm the in what order we get the elements from different collection
List
ArrayList:- the sequence in which we put the element we get them in same sequence
LinkedList:- when we add an element in linked list with add(E e) it will be added at last when we get it with itertator it will start from first element to last element. So we can say
the sequence in which we put the element we get them in reverse sequence
Set
HashSet:- No sequence(for getting the elemnets) is guaranted. It will be a random sequence
Tresset:- Will get the elements as per their natural ordering or comparator defined at the time of creation
Map
HashMap:- No sequence(for getting the elemnets) is guaranted. It will be a random sequence
TreeMap:- Will get the elements as per their natural ordering of key or comparator defined at the time of creation
Please let me know if it is correct?
Yup - apart from your use of the word random. The order from a hash set/map won't actually be random; it will just be implementation-specific and unpredicatable. Not quite the same thing - in particular, you shouldn't use it as a source of randomness - but you're right that you shouldn't rely on it being any specific ordering.
This ordering is what you would get if you used an iterator. I think the Java Doc are clear enough for this to be apparent. Mind you this is not all on one page.

Resources