Open andreyvk opened 9 years ago
This will be helpful, iwas looking for something like this. Thanks
There's a little curvy way to execute a function (at least idempotent one): you can use it as an SQL query - smth like
$fooResults = $client->query( 'select functionName(arg1, arg2)');
I've tried to use it (just tested it with a single-query function), but it works in a rather strange way: if the query selects all of the objects that mathes the criteria (select from myEdge where edgeProp ='whatever') it gives me an object with @rids in OData:
[ { "rid": "#-2:1", "version": 0, "oClass": null, "oData": { "functionName": [ "#13:1", "#13:2", "#13:3", "#13:4", "#13:7", "#13:24" ] }
But if I want to get just the the specific edge property, ex., manually assigned ID, and change the query inside the function like that: select myID from myEdge where edgeProp ='whatever' - I do not receive any result but notice:
Notice: Uninitialized string offset: 0 in D:\myprojectpath\vendor\ostico\phporient\src\PhpOrient\Protocols\Binary\Data\ID.php on line 45
Any ideas how to go through it? It would be very handy to use Orient functions here...
@grreeenn this is an interesting approach. Havent tried it. If i do, i'll let u know. Thanks!
@andreyvk , by the way, I constructed the function that returns 4-dimensional array with the data that I need (not just RIDs), and the PhpOrient gets it just right :)
@grreeenn wow! that's useful )) any chance to drop a piece of code or at least a description here?
I'd be interested in this too!
Scott
@smolinari i sort of figured it out. actually, we can just return JSON from the function. You can use fetchplan
to vary your attributes. The solution is as follows:
var g=orient.getGraph();
var gres=g.command("sql","select @this.toJSON() as json from MyClass limit 3");
var res = [];
for(var i in gres) {
res.push(gres[i].getProperty("json"));
}
return res;
Functions are primarily used to do some routine stuff and normally should not return much. so returning JSON should be more than enough for the time being
As I understand, when you return array or object from the function, it turns to PHP array on PHP side automatically; I can't bring my function here (it's rather long company-specific function for parsing flights connections), but it returns me an array like this Array ( [combination0] => Array ( [dstStart-dstVia1] => Array ( [0] => Array ([fltID] => 1561614 [departure] => 2015-07-24 07:00:00 [arrival] => 2015-07-24 07:20:00 ) [1] => Array ( [fltID] => 16161656 [departure] => 2015-07-24 07:00:00 [arrival] => 2015-07-24 07:20:00 )) [dstVia1-dstVia2] => Array ( [0] => Array ( [fltID] => 654654 [departure] => 2015-07-24 07:30:00 [arrival] => 2015-07-24 07:00:00 ) ) [dstVia2-dstFinish] => Array ( [0] => Array ( [fltID] => 464564 [departure] => 2015-07-24 07:45:00 [arrival] => 2015-07-24 07:45:00 ) ) ) [combination1] => Array ( [dstStart-dstVia1] => Array ( [0] => Array ( [fltID] => 6846545 [departure] => 2015-07-24 07:00:00 [arrival] => 2015-07-24 07:20:00 ) [1] => Array ( [fltID] => 8466456 [departure] => 2015-07-24 07:00:00 [arrival] => 2015-07-24 07:20:00 ) [2] => Array ( [fltID] => 4634564 [departure] => 2015-07-24 07:15:00 [arrival] => 2015-07-24 07:35:00 ) ) [dstVia1-dstVia2] => Array ( [0] => Array ( [fltID] => 8464848 [departure] => 2015-07-24 07:30:00 [arrival] => 2015-07-24 07:00:00 ) ) [dstVia2-dstVia3] => Array ( [0] => Array ( [fltID] => 13454456 [departure] => 2015-07-24 07:10:00 [arrival] => 2015-07-24 08:25:00 ) ) [dstVia3-dstVia4] => Array ( [0] => Array ( [fltID] => 1545464 [departure] => 2015-07-24 10:15:00 [arrival] => 2015-07-24 10:30:00 ) ) [dstVia4-dstVia5] => Array ( [0] => Array ( [fltID] => 484645 [departure] => 2015-07-24 10:40:00 [arrival] => 2015-07-24 10:55:00 ) ) [dstVia5-dstVia6] => Array ( [0] => Array ( [fltID] => 465464 [departure] => 2015-07-24 11:00:00 [arrival] => 2015-07-24 11:00:00 ) ) [dstVia6-dstFinish] => Array ( [0] => Array ( [fltID] => 51864684 [departure] => 2015-07-24 11:00:00 [arrival] => 2015-07-24 11:00:00 ) ) ) )
it retrurns by executing a regular SQL query, just with the function call inside the select
$fooResults = $client->query( 'select getPath(dstStart, dstFinish, "departureInDateTimeFormat")');
@grreeenn this does not show much, but i can infer that this array is built with JS code somehow and its very specific to whatever records you are dealing with. In any case, I've got the idea, thanks ))
Hi,
Is there any milestone for supporting executing functions? For instance: