Using "BETEEN" operator on a LONG-EMBEDDED-LIST property declared in OrientDB 2.2.17 - orientdb

I am using OrientDB 2.2.17 (enterprise edition) and I have a problem searching on the data:
I have a vertex called: EN70 with a property: EP70_4 from type 'embedded list = LONG'.
I added a record to this vertex with the value of [2,3,4] in this 'EP70_4' property.
The index on this property: Not_Unique (sbtree). [must support range queries]
SELECT * FROM EN70 WHERE (EP70_4 >= 1) is working and returns my record.
SELECT * FROM EN70 WHERE (EP70_4 <= 3) is working and returns my record.
The operator "Between" is not woking and throw exception:
SELECT * FROM EN70 WHERE (EP70_4 BETWEEN 1 AND 3 )
I tried to simulate a "between" operator:
SELECT * FROM EN70 WHERE ((EP70_4 >= 1) AND (EP70_4 <= 3)) IS NOT WORKING
but it is not working.
both sections 6 and 7 throws an exception:
Error on using index EN70.EP70_4 in query 'SELECT * FROM EN70 WHERE (EP70_4 BETWEEN 1 AND 3 )'. Probably you need to rebuild indexes. Now executing query using cluster scan
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Long
at com.orientechnologies.common.serialization.types.OLongSerializer.preprocess(OLongSerializer.java:36)
at com.orientechnologies.orient.core.index.sbtree.local.OSBTree.iterateEntriesBetweenAscOrder(OSBTree.java:1474)
at com.orientechnologies.orient.core.index.sbtree.local.OSBTree.iterateEntriesBetween(OSBTree.java:771)
at com.orientechnologies.orient.core.index.engine.OSBTreeIndexEngine.iterateEntriesBetween(OSBTreeIndexEngine.java:185)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.doIterateIndexEntriesBetween(OAbstractPaginatedStorage.java:2065)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.iterateIndexEntriesBetween(OAbstractPaginatedStorage.java:2053)
at com.orientechnologies.orient.core.index.OIndexMultiValues.iterateEntriesBetween(OIndexMultiValues.java:275)
at com.orientechnologies.orient.core.index.OIndexAbstractDelegate.iterateEntriesBetween(OIndexAbstractDelegate.java:104)
at com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue.iterateEntriesBetween(OIndexTxAwareMultiValue.java:339)
at com.orientechnologies.orient.core.sql.operator.OQueryOperatorBetween.executeIndexQuery(OQueryOperatorBetween.java:131)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchForIndexes(OCommandExecutorSQLSelect.java:2184)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchInClasses(OCommandExecutorSQLSelect.java:1001)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetAbstract.assignTarget(OCommandExecutorSQLResultsetAbstract.java:209)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.assignTarget(OCommandExecutorSQLSelect.java:530)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearch(OCommandExecutorSQLSelect.java:512)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.execute(OCommandExecutorSQLSelect.java:488)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:74)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:2624)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:2570)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:69)
at com.orientechnologies.orient.server.network.protocol.http.command.post.OServerCommandPostCommand.execute(OServerCommandPostCommand.java:106)
at com.orientechnologies.orient.graph.server.command.OServerCommandPostCommandGraph.execute(OServerCommandPostCommandGraph.java:37)
at com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpAbstract.service(ONetworkProtocolHttpAbstract.java:169)
at com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpAbstract.execute(ONetworkProtocolHttpAbstract.java:622)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)
What can it be??? Please help me...

I'd say it's a bug, I strongly suggest you to report it here: https://github.com/orientechnologies/orientdb/issues

Related

Cast integer to decimal in DQL

I use Doctrine with a Postgres database and want to update the integer field "voting".
It's a procentual value, saved as integer between 0 and 100, based on the two integer fields "voteCountPro" and "voteCount".
I have to cast one of the integers to a decimal value. (See: Division ( / ) not giving my answer in postgresql)
This doesn't work in DQL and fails with the message:
[Syntax Error] line 0, col 363: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ':'
UPDATE statement s
SET s.voting = (s.voteCountPro::decimal / s.voteCount) * 100
WHERE s.id = :id
How can I set the value?
Install https://github.com/oroinc/doctrine-extensions, register the CAST function and write:
UPDATE statement s
SET s.voting = (CAST(s.voteCountPro as decimal) / s.voteCount) * 100
WHERE s.id = :id

NULLIF how to set it properly in this query

I am using the following query to get some tablespaces usage at a glance:
db2 "select substr(tbsp_name,1,30) as Tablespace_Name, tbsp_type as Type, substr(tbsp_state,1,20) as Status, (tbsp_total_size_kb / 1024 ) as Size_Meg, smallint((float(tbsp_free_size_kb)/ float(tbsp_total_size_kb))*100) as Percent_Free_Space, int((tbsp_free_size_kb) / 1024 )as Meg_Free_Space from sysibmadm.tbsp_utilization where smallint((float(tbsp_free_size_kb)/ float(tbsp_total_size_kb))*100) < 20 order by Percent_Free_Space"
however, I'm stuck with the following error:
SQL0801N Division by zero was attempted. SQLSTATE=22012
I understand you can fix this error with a NULLIF however I can't find the correct way to set in in the query, thanks for the help.
( using "DB2 v9.7.0.11", "s150922", "IP23937", and Fix Pack
"11")
Maybe you should use case:
CASE WHEN tbsp_total_size_kb=0 THEN NULL ELSE (tbsp_total_size_kb / 1024 ) END as Size_Meg
if tbsp_total_size_kb can be null IFNULL like this:
CASE WHEN IFNULL(tbsp_total_size_kb,0)=0 THEN NULL ELSE (tbsp_total_size_kb / 1024 ) END as Size_Meg
Try this:
smallint(float(tbsp_free_size_kb) / float(nullif(tbsp_total_size_kb,
0)) * 100)

PostgreSQL View Error Handling

The code given below is a part of a view that I have created. But sometimes it may throw an error saying:
division by zero
The reason for this error is that sum(bills.past_arrear) part may be 0 for some months.
SELECT (SELECT revenue_driver.driver_id
FROM ccdb.revenue_driver
WHERE revenue_driver.driver_desc::text = 'Arrear Collection Efficiency'::text) AS driver_id
,bills.org_unit_id::integer AS section_id
,date_part('Month'::text, bills.due_date) AS mnth
,date_part('Year'::text, bills.due_date) AS yr
,ROUND(SUM(COALESCE(bills.arrear_collected,0::numeric))/sum(bills.past_arrear)*100::numeric, 2) AS per_efficiency
,now() AS creation_dt
FROM ccdb.bills
WHERE bills.due_date::date >= date_trunc('Month'::text,'now'::text::date::timestamp with time zone)::date
AND bills.due_date::date <= 'now'::text::date
AND (bills.bill_type_group_code::text = ANY (ARRAY['EB'::character varying::text, 'Energy'::character varying::text]))
GROUP BY bills.org_unit_id, date_part('Year'::text, bills.due_date), date_part('Month'::text, bills.due_date);
What I want is if ROUND(SUM(COALESCE(bills.arrear_collected,0::numeric))/sum(bills.past_arrear)*100::numeric, 2) throws division by zero error I want to replace the value with 0.
I have not idea how do handle this error. Kindly someone help me on this.
You need to use a CASE WHEN in your select statement like below :-
CASE
WHEN sum(bills.past_arrear) = 0
THEN 0
ELSE ROUND(SUM(COALESCE(bills.arrear_collected, 0::NUMERIC)) / sum(bills.past_arrear) * 10 ‌​0::NUMERIC, 2)
END AS per_efficiency

Doctrine, QueryBuilder : use particular "where" with parenthesis

I got a problem to make a "simple" query with the Doctrine QueryBuilder.
I try to get some "persons" which are on 10 km max.
My query :
$QB = $this->createQueryBuilder('p');
$QB->add('select', 'p')
->add('from', 'MyProject\Bundle\FrontBundle\Entity\Pro p')
->where('p.job = :job')
->andWhere('(3956 * 2 * ASIN(SQRT( POWER(SIN((:latitude - abs(pro.latitude)) * pi()/180 / 2),2) + COS(:latitude * pi()/180 ) * COS(abs(pro.latitude) * pi()/180) * POWER(SIN((:longitude - pro.longitude) * pi()/180 / 2), 2) ))) <= 10')
->addOrderBy('p.dateCreation', 'DESC')
->addOrderBy('p.id', 'DESC')
->setParameter('latitude', $latitude)
->setParameter('longitude', $longitude)
->setParameter('job', $jobId);
The problem is on the second 'where' statement, Doctrine fails on "ASIN" because of the parenthesis that follows. It tries to execute the function...
Is there a way to escape it ? Or another way to construct this condition ?
Thanks for Doctrine professional ;)
If I understand correctly, you can either write a raw SQL query for that, or implement the function ASIN(or any other) in doctrine.
Here you have a bundle that might help:
https://github.com/wiredmedia/doctrine-extensions
You can use its implementation of ASIN function:
https://github.com/wiredmedia/doctrine-extensions/blob/master/lib/DoctrineExtensions/Query/Mysql/Asin.php
And and article about custom DQL functions:
http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html

Using CURRENT_TIMESTAMP, arithmetic operator and parameter with Firebird

Why doesn't this work (when parameter is set to 1) :
SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - ?)
But this works :
SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - 1)
I get error message: "conversion error from string "39723.991882951" "
I'm using Firebird 2.1
EDIT:
I found the answer myself with a little help:
SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - CAST(? as DECIMAL(18,9))
Works if the parameter is given as float value.
What do you want to do exactly? Maybe I can be more helpfull with more details.
SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - ?)
How do you set your parameter in your code? Which language do you use?
If you use Delphi, then your parameter should be passed as Float. Ie:
MyQuery.ParamByName('delta').asFloat := 0.1;
Try this and tell us if it's working
HTH