Functions mostly broken in 2.1-rc3 ?

91 views
Skip to first unread message

hartmut bischoff

unread,
Jun 3, 2015, 4:32:40 PM6/3/15
to orient-...@googlegroups.com
Hi alltogether,

is the feature of storing Funtions in the Database still usable?

I followed documentation and got completely lost.

First: I fired a simple SQL-Query

Schema:  contracts [n<-link->1] subcategories  [n<-link->1] categories [n<-link->1] industries

To query all contracts belonging to a single industry, (just as in a oldschool-sql-db) one can write

 select name categories.subcategories.contracts from Industries  where name containstext   'ial'

which obviously returns an Array :

#<REST::Model::Myquery:0x00000003ffb880 @attributes={ "name" =>"Basic Materials", "categories"=>[["#21:1"]], "version"=>0, "cluster"=>"-2", "record"=>"0", "fieldTypes"=>"null=e", "created_at"=>2015-06-02 14:11:46 +0200, "updated_at"=>2015-06-02 14:11:46 +0200}>
#<REST::Model::Myquery:0x00000003ff9b20 @attributes={"name"=>"Financial", "categories"=>[["#21:2"]], "version"=>0, "cluster"=>"-2", "record"=>"1", "fieldTypes"=>"null=e", "created_at"=>2015-06-02 14:11:46 +0200, "updated_at"=>2015-06-02 14:11:46 +0200}>
#<REST::Model::Myquery:0x00000003ff83b0 @attributes={"name"=>"Industrial", "categories"=>[["#23:0", "#23:1"]], "version"=>0, "cluster"=>"-2", "record"=>"2", "fieldTypes"=>"null=e", "created_at"=>2015-06-02 14:11:46 +0200, "updated_at"=>2015-06-02 14:11:46 +0200}>

So far, so good – the query is working perfect.

Then I put the same query into a function:
( in Studio: )
return orient.getDatabase().query("select name, categories.subcategories.contracts from Industries  where name containstext 'ial'");
and saved it as »getContracts«

But when I tried to fetch the result via REST I got:

uri: function/hc_database/getContracts
{"result":[{"@type":"d","@version":0,"value":"orient.getDatabase().query(\"select name, categories.subcategories.contracts from Industries  where name containstext 'ial'\")"}]}

just the copy of the query-text....


It turned better.

I switched to javascript:

var gdb = orient.getDatabase();

return gdb.command( "sql", "select name ....

---> "code": 400,
            "reason": "Bad request",
            "content": "Error on parsing script at position #0: Error on execution of the script\nScript: allCategories\n------^\nsun.org.mozilla.javascript.WrappedException: Wrapped com.orientechnologies.orient.core.exception.OConfigurationException: No database instance found in context (<Unknown source>#10) in <Unknown source> at line number 10\nWrapped com.orientechnologies.orient.core.exception.OConfigurationException: No database instance found in context (<Unknown source>#10)\nNo database instance found in context"

Ups.

As only solution which works, I found

language: Javascript
Database-Instance by getGraphNoTx()

To me the consequences of using getGraphNoTx are not clear. The strange behavior of the function-part should be noted as big bug in the development-Version .
strange.


(I am using the current stable 2.0 Version of OrientDB)

Hartmut

Ziink A

unread,
Jun 3, 2015, 6:15:11 PM6/3/15
to orient-...@googlegroups.com
I'm not certain but I think there's a bug in Studio that is causing an error with orient.getDatabase()

hartmut bischoff

unread,
Jun 4, 2015, 1:29:52 AM6/4/15
to orient-...@googlegroups.com


On Thursday, June 4, 2015 at 12:15:11 AM UTC+2, Ziink A wrote:
I'm not certain but I think there's a bug in Studio that is causing an error with orient.getDatabase()


This is what I thought first, too.
Then I tested the feature with the HTTP/REST-API  --- same result – even if I change getDatabase to getGraphNoTx, which worked for me in one single case:

uri:function/hc_database/myTest
{"result"=>[{"@type"=>"d", "@version"=>0, "value"=>"orient.getGraphNoTx().command('sql',\"select name, categories.subcategories.contracts from Industries where name containstext 'ial'\" )"}]}
-------



 

hartmut bischoff

unread,
Jun 4, 2015, 3:59:43 PM6/4/15
to orient-...@googlegroups.com
The documentation is a nightmare.


seems to be the acutal documentation ....

The command "Create Function" is accepted,  and  inserts a function into the OFunctions Class.
Surprisingly in Studio this function is marked as "SQL"  (capital).

No need to reference the Database, just added the plain query  .... and anything works.

Perhaps someone can delete the part of the documentation  where  "return getDatabase() ..." is used, which  points in the very wrong direction  ...


Luca Garulli

unread,
Jun 4, 2015, 4:38:48 PM6/4/15
to orient-...@googlegroups.com
Hi Hartmut,
Where did you find the "return getDatabase() ..." ?

I don't understand where is the problem. Please could you elaborate it more?

Best Regards,

Luca Garulli
CEO at Orient Technologies LTD
the Company behind OrientDB

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hartmut bischoff

unread,
Jun 4, 2015, 11:34:25 PM6/4/15
to orient-...@googlegroups.com




On Thursday, June 4, 2015 at 10:38:48 PM UTC+2, l.garulli wrote:
Hi Hartmut,
Where did you find the "return getDatabase() ..." ?

>>Execute a query
>>
>>Query is an idempotent command. To execute a query use the query()method. Example:
>>
>>return orient.getDatabase().query("select name from ouser");

>>Execute a command
>>
>>Commands can be written in any language supported by JVM. By default OrientDB supports "SQL" and "Javascript".
>>
>>SQL Command
>>
>>var gdb = orient.getGraph();
>>var results = gdb.command( "sql", "select from Employee where company = ?", [ "Orient Technologies" ] );

This might make sense to experienced bodies, for somebody less familar with Orientdb and its diverse API's its confusing.
So I just followed the »instructions«  – the outcome is partly documentated in this thread.
Reply all
Reply to author
Forward
0 new messages