I'm trying to calculate the delta value between two rows for one particular
column. OrientDB doesn't support joins as far as I can tell so I'm trying
to accomplish same with sub queries, but I get results i don't understand.
Can someone suggest proper way to accomplish this.
package DeltaTest;
import java.util.List;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
public class Delta {
public Delta() {
}
public static class Activity {
private Long received;
private String key;
private Long time;
public Long getReceived() {
return received;
}
public void setReceived(Long received) {
this.received = received;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
}
public static void main(String[] args) {
OObjectDatabaseTx db = new OObjectDatabaseTx("plocal:c:/temp/testdb");
if (db.exists()) {
db.open("admin", "admin");
db.drop();
}
db.create();
db.getEntityManager().registerEntityClass(Activity.class);
Activity activity = new Activity();
activity.setReceived(Long.valueOf(100));
activity.setKey("wsbroker1");
activity.setTime(Long.valueOf(10));
db.save(activity);
activity.setReceived(Long.valueOf(120));
activity.setTime(Long.valueOf(11));
db.save(activity);
activity.setReceived(Long.valueOf(130));
activity.setTime(Long.valueOf(12));
db.save(activity);
activity.setReceived(Long.valueOf(150));
activity.setTime(Long.valueOf(13));
db.save(activity);
activity.setReceived(Long.valueOf(190));
activity.setTime(Long.valueOf(14));
db.save(activity);
String query = "select key, received as previous, $temp[0].current as
current, $temp[0].delta as delta from Activity, let $temp = (select
received as current, ($parent.current.current - current) as delta from
Activity order by time limit 1)";
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>(query),
new Object[0]);
for (ODocument doc : result) {
System.out.println(doc);
}
db.close();
}
}
This is the output. The 'delta' column is reporting the calculation and
not the actual value:
#-2:1{key:wsbroker1,previous:100,current:100,delta:sql.$parent.current.current
- current} v0
#-2:2{key:wsbroker1,previous:120,current:100,delta:sql.$parent.current.current
- current} v0
#-2:3{key:wsbroker1,previous:130,current:100,delta:sql.$parent.current.current
- current} v0
#-2:4{key:wsbroker1,previous:150,current:100,delta:sql.$parent.current.current
- current} v0
#-2:5{key:wsbroker1,previous:190,current:100,delta:sql.$parent.current.current
- current} v0
--
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.