OrientDB - convert String to Link in queries - type-conversion

I have a map where the KEYS (although of type string) are meant to be LINKS (e.g. "#1:1", "#1:2") and I want to somehow be able to convert those string keys to LINKS and directly use them in queries.
E.g.
select * from CONVERT_TO_LINK( myMap.keys()[0] )
How can I do such a conversion?
Thanks

JS Function:
Test Code:
create class v1 extends v
create property v1.myMap embeddedmap
create vertex v set name="pippo"
create vertex v1 set myMap={"#9:8":"something"}
select expand(link) from (select toLink(myMap.keys()[0]) as link from v1)
Result:
Hope this helps.

Why not using select * from myMap.keys()[0].convert('LINK') built-in method?

Related

End points in Flask Admin using different fields than ID

I've got an Order object where the edit screen for an Order object with ID of 5 looks something like this: /admin/order/edit/?id=8&url=%2Fadmin%2Forder%2F
If I've got a field on the Order object called invoice, is there a way to use a URL end point for the edit screen using the invoice field?
Generally, using column_extra_row_actions you can create an action that accepts row_id (Order.ID in your case) as parameter, and you can specify a function that will get the 'invoice'.
Alternatively, you can add an extra column to the view that does not exist in your database, and fill it with an appropriate link.
from flask import Markup
class MyModelView(ModelView):
....
column_list = ['edit link'] + the_rest_of_columns_you_display
column_formatters = {'edit link': lambda v, c, m, n: Markup('''
<a href='/admin/order/edit/?invoice=%d'>Edit</a>
''' % m.invoice }
Additionally, you need to override the edit_view function so it will accept whatever parameters you need, and the respective template.

OrientDB Include property from edge connected to specific vertex

I have the following case:
(p:p1)
V1 ---E1---\
\
V2 (with properties)
/
V1 ---E1---/
(p:p2)
So two vertices of class V1 are connected to another Vertex of type V2, both edges are of the same class E1 which has the property "p".
I would like a query that:
Targets a V1 instance (by rid)
Reads all V2 records (including all properties) that are connected to the selected V1 by the edge class E1
Also includes the property p from the connecting E1-edge in the returned documents.
I have tried with:
SELECT *,in('E1')[p] as p FROM (SELECT EXPAND(out('E1')) FROM <V1-rid>) UNWIND p
But that would of course give 2 results since the projection returns values from both the E1 edges. I only want to inlcude p form the edge between my selected V1 and V2.
I have some other connections to V2 as well which need to be included, but I wanted to specify the problem more precise to reduce the question complexity and I think (hope) they won't interfere with the answer.
Update
Clarification:
I would like the result to be whole V2-records with appended properties "p", so if V2 has properties v2p1:, v2p2, the resulting records should look something like:
{
"v2p1": <value>,
"v2p2": <value>,
"p": <value>
}
Where the last "p" value is from the edge and the other properties are from the actual V2 records.
You could use this query
SELECT FROM (
MATCH {CLASS:v1, AS:v1, WHERE: (#rid=#29:0)}.outE('e1'){AS:e1}.inV('e1'){AS:v2} RETURN v1, e1.p, v2
)
I hope that is clear enough.
try this:
select *,traversedEdge(-1).p as p from(traverse outE('E1'),inV('E1') from #21:0) where #class='V2'

Orange3 : String Variable

I do not manage to create an Orange table with StringVariables.
The following code:
d = Orange.data.Domain([Orange.data.StringVariable("s")])
makes this error:
TypeError: variables must be primitive
It seems that StringVariable is for metadata only. So I'm worried about this because my data has a lot of strings that it would be crazy to put in a discrete structure (each string value is different).
Is there a solution for putting strings in a table ?
Thanks in advance for the answers,
Best,
mike
This question might be old but I found it via Google and wanted to provide a simple example of how to use meta "columns".
You need to specify the meta variables the same way you specify the "normal" variables just do it inside the metas parameter inside the Domain constructor.
from Orange.data import *
taskid = StringVariable(name="taskid")
logdata = StringVariable(name="logdata")
domain = Domain([] , metas=[taskid, logdata])
data = Table(domain, [
["uuid1","some more stuff"],
["uuid2","some more stuff"]
]);
out_data = data;

How do I get the contents of all of the nodes in a root node with SQL and XQuery?

I have the following table structure:
CREATE TABLE SpecialTable
(
Key UNIQUEIDENTIFIER,
XMLField VARCHAR(MAX)
)
In the first tuple:
Key = "28384841-17283848-7836-18292939"
XMLField =
"<RootNode>
<ForeignKey>92383829-27374848-1298-19283789</ForeignKey>
<ForeignKey>47585853-27374848-4759-19283939</ForeignKey>
<ForeignKey>37383829-27374848-3747-19283930</ForeignKey>
</RootNode>"
In another tuple, I see:
Key = "89984841-17283848-7836-18292939"
XMLField =
"<RootNode>
<ForeignKey>92383829-27374848-1298-19283789</ForeignKey>
<ForeignKey>37383829-27374848-3747-19283930</ForeignKey>
</RootNode>"
In a further tuple, I see:
Key = "11114841-17283848-7836-18292939"
XMLField =
"<RootNode>
<ForeignKey>37383829-27374848-3747-19283930</ForeignKey>
</RootNode>"
What I need to do is to get the following dataset out:
Key ForeignKey
28384841-17283848-7836-18292939 92383829-27374848-1298-19283789
28384841-17283848-7836-18292939 47585853-27374848-4759-19283939
28384841-17283848-7836-18292939 37383829-27374848-3747-19283930
89984841-17283848-7836-18292939 92383829-27374848-1298-19283789
89984841-17283848-7836-18292939 37383829-27374848-3747-19283930
11114841-17283848-7836-18292939 37383829-27374848-3747-19283930
I must say that this is a simplified data set and that the data was more complex than this and I have got to a point where I cannot get any further.
I have tried this:
SELECT sp.Key,
x.XmlCol.Query('.')
FROM SpecialTable AS sp
CROSS APPLY sp.XMLField.nodes('/RootNode') x(XmlCol)
However, it seems just to show the Key and the whole of the XML of the XMLField.
Also, I tried this:
SELECT sp.Key,
x.XmlCol.Query('ForeignKey[text]')
FROM SpecialTable AS sp
CROSS APPLY sp.XMLField.nodes('/RootNode') x(XmlCol)
And I get only the first value in the first ForeignKey node and not the others.
What am I doing wrong?
Kindest regards,
QuietLeni
First of all - if your data looks like XML, quacks like XML, smells like XML - then it IS XML and you should use the XML datatype to store it!
Also: be aware that Key is a very generic term, and also a T-SQL reserved keyword, so it makes for a really bad column name - use something more meaningful that doesn't clash with a keyword!
Once you've done that, you should be able to use this code to get your desired results:
SELECT
[Key],
ForeignKey = xc.value('.', 'varchar(50)')
FROM
dbo.SpecialTable
CROSS APPLY
XMLField.nodes('/RootNode/ForeignKey') AS XT(XC)
This will only work if you column XMLField is of XML datatype !! (which it really should be anyway)

Specifying a DB table dynamically? Is it possible?

I am writing a BSP and based on user-input I need to select data from different DB tables. These tables are in different packages. Is it possible to specify the table I want to use, based on its path, like this:
data: path1 type string value 'package1/DbTableName',
path2 type string value 'package2/OtherDbTableName',
table_to_use type string.
if some condition
table_to_use = path1.
elseif some condition
table_to_use = path2.
endif.
select *
from table_to_use
...
endselect
I am new to ABAP & Open SQL and am aware this could be an easy/silly question :) Any help at all would be very much appreciated!
You can define the name of the table to use in a variable, and then use the variable in the FROM close of your request :
data tableName type tabname.
if <some condition>.
tableName='PA0001'.
else.
tableName='PA0002'.
endif.
select * from (tableName) where ...
there are a few limitation to this method, as the stable can not contains fields of type RAWSTRING, STRING or SSTRING.
as for the fact that the table are in different package, i don't think it matters.
Regards,