Gremlin hasId using property of parent - gremlin

I would like to filter out by an id. The value of the id is on a property of the parent. Example:
g.V('1234')
.as('parent')
.out()
.has(id, parent.childId). <--- how do I get the parent id?
How would one approach this?
The closest I've been able to get is the following query, but it seems to ignore the has and simply returns all results of out.
g.V('123')
.as('parent')
.values('childId')
.as('childIdValue')
.select('parent')
.out('hasChild')
.has('id', select('childIdValue'))
EDIT
It works as expected when a vertex property other than the Id is used. Example:
g.V('123')
.as('parent')
.values('childId')
.as('childIdValue')
.select('parent')
.out('hasChild')
.has('childProp', select('childIdValue'))
I've tried all variations of id that I can think of. 'id', id, id().

You can compare an ID using a where by approach. For example something like:
where(eq('parent')).by('childProp').by('childId')

Related

How to ensure ordering of response for two different nodes in gremlin?

For my data model, I have the following:
type defines an item
The project owns an item
Type is connected to anchors (Suppose the anchor is country)
Item is connected to a particular anchor instance (anchor instance
will have corresponding value for anchor, suppose US)
I am trying to read an item along with the type, anchorNames and anchorValues.
Following is the query I have written:
g.V().hasLabel('Type').as('t')
.outE('DEFINES').inV().hasLabel('Item').has('dataId',’test-id').has('version','1').as('i')
.inE('OWNS').outV().hasLabel('Project').select('i')
.project('i','t','anchorNames','anchorValues')
.by(__.valueMap(true))
.by(__.in().hasLabel('Type').valueMap(true))
.by(out().in().hasLabel('Anchor').values('name').fold())
.by(out().as('AnchorInstance').select('AnchorInstance')
.by(values('value','secondaryValue').fold()).fold())
I get i and t but the result for anchorNames and anchorValues is as follows:
{anchorNames=[status, status, country], anchorValues=[[OK], [US], [FAIL]]}
However I am expecting the following:
{anchorNames=[status, status, country], anchorValues=[[OK], [FAIL], [US]]}
I need the ordering between the anchorNames and anchorValues as shown above.
I think the best approach will be to get the name and the corresponding values together.
g.V().hasLabel('Type').as('t')
.out('DEFINES').hasLabel('Item').has('dataId',’test-id').has('version','1').as('i')
.in('OWNS').hasLabel('Project').select('i')
.project('i','t','anchors')
.by(__.valueMap(true))
.by(__.in().hasLabel('Type').valueMap(true))
.by(out().project('anchorNames','anchorValues')
.by(__.in().hasLabel('Anchor').values('name'))
.by(values('value','secondaryValue').fold()).fold())

cts search to test if the element is not available

Below is the XML structure where I want to get the entries for which element co:isbn is not available:-
<tr:trackingRecord xmlns:tr="https://www.mla.org/Schema/Tracking/tr"
xmlns:co="https://www.mla.org/Schema/commonModule/co"
xmlns:r="http://www.rsuitecms.com/rsuite/ns/metadata">
<tr:journal>
<tr:trackingDetails>
<tr:entry>
<co:trackingEntryID>2015323313</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:volume>21</co:volume>
</tr:entry>
<tr:entry>
<co:trackingEntryID>2015323314</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:isbn>
<co:entry>NA</co:entry>
<co:value>1234567890128</co:value>
</co:isbn>
</tr:entry>
<tr:entry>
<co:trackingEntryID>2015323315</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:volume>21</co:volume>
<co:isbn></co:isbn>
</tr:entry>
<tr:entry>
<co:trackingEntryID>2015323316</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:volume>21</co:volume>
</tr:entry>
</tr:trackingDetails>
</tr:journal>
</tr:trackingRecord>
Please suggest the cts:query for the same.
If you can edit xml structure, add one attribute in entry element, like
<tr:entry isbnPresent="yes"> for isbn present,
<tr:entry isbnPresent="no"> for isbn absent
and based on these field fire search with,
cts:element-attribute-value
on it.
OR
without editing schema, try like, ,
for $i in cts:search(//tr:entry,"2015")
return if(fn:exists($i//co:isbn)) then () else $i

Is there way to change column values of selected rows through Propel?

Rows are selected like that:
$book->getBookGenreToBooks()->???()
I want to change the column «checked» of all selected rows.
Your given solution in your answer is very inefficient since it creates for each update a new query. A better way is to do all changes in one query:
BookGenreQuery::create()
->filterByBookId($book->getId())
->update(array('Checked' => 1));
I don't know how exactly your relations and fields are named by you should get the idea behind it.
$genresToBook = $book->getBookGenreToBooks();
foreach ($genresToBook as $genreToBook) {
$genreToBook->setChecked(1); //Set any data here
}
$genresToBook->save();
This isn't exactly what I want, but that works fine to me.

cannot find the correct syntax for this

I have a row in the table:
//*[contains(text(), 'Cape Town')]
and the delete graphic:
//*[contains(#id, 'DeleteLinkButton')]
in the table.
How do I click on //*[contains(#id, 'DeleteLinkButton')] of row //*[contains(text(), 'Cape Town')]?
If you want to find a node with XPath in relation to another node then in most cases you don't want to use an absolute path starting with / or even //, instead you would use a relative path like .//*[contains(#id, 'DeleteLinkButton')] as that would find descendants of the context node where the id attribute value contains DeleteLinkButton.
So with Javascript in the browser you would have e.g.
var myRow = ...;
and then you could call
myRow.ownerDocument.evaluate('.//*[contains(#id, 'DeleteLinkButton')]', myRow, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();

xquery order by date Time

Say I have the following documents in my database: a_doc1, a_doc2, b_doc1, and b_doc2
All these documents are of the following format
<doc>
....
<updatedTime>2011-02-07T14:41:02.133-05:00</updatedTime>
....
</doc
>
The value of the "updatedTime" element is inserted when the document is created using the fn:current-dateTime()
Now I am trying to do the following:
find all documents whose name starts with "a_"
order these documents by their <updatedTime> element in descending order
Return the first document name from the descending order
I tried the following:
for $doc_name in db:list()
where fn:starts-with($doc_name, 'a_')
order by xs:dateTime(doc($doc_name)/updatedTime) descending
return $doc_name
Say "a_doc1" is created at "2011-02-07T14:40:00.78-05:00" and "a_doc2" is created at "2011-02-07T14:41:02.133-05:00", the desired output is a_doc2. In short the document name(starting with a_) of the most recent document created must be returned.
When I try my sample code, the output returned is : [a_doc1, a_doc2].
The expected output is: [a_doc2, a_doc1].
Thanks,
Sony
order by dateTime(doc($doc_name)/updatedTime/text())
Instead of this use:
order by xs:dateTime(doc($doc_name)/updatedTime)
you should use (xs: http://www.w3.org/2001/XMLSchema):
xs:dateTime($arg as xs:anyAtomicType?) as xs:dateTime?
Example:
xs:dateTime("1999-12-31T12:00:00")
instead of (fn: http://www.w3.org/2005/xpath-functions)
fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime?
Example:
fn:dateTime(xs:date("1999-12-31"), xs:time("12:00:00"))

Resources