BufferUnderflowException while querying OrientDB using OrientDB studio - orientdb

BufferUnderflowException thrown while executing the below query.
SELECT
FROM
(
match { class: a, AS: a }
.out('aTob') { AS: b, WHERE: (field1 is defined and field1 = true) }
.out('bToC') { WHERE: (field2 = 'XYZ'), AS: c }
return a
)
This query works fine when I add a LIMIT of 121 records.
If I add a limit of 122 or run the query without a limit, it throws "BufferUnderflowException"

Related

select one output query SPARQL

I've written this query in sparql:
SELECT ?spouse
WHERE {
dbr:Zach_Galifianakis dbp:spouse ?spouse.
}
and I have this output:
2012
""#en
"Quinn Lundberg"#en
(https://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=SELECT+%3Fspouse%0D%0AWHERE+%7B%0D%0Adbr%3AZach_Galifianakis+dbp%3Aspouse+%3Fspouse.%0D%0A%7D%0D%0A&format=text%2Fhtml&timeout=30000&signal_void=on&signal_unconnected=on)
I don't understand how to select only the name "Quinn Lundberg"#en. I've tried using FILTER clause but it doesn't work.
Not a generic solution, but this will fetch only the name for your case:
SELECT *
WHERE {
dbr:Zach_Galifianakis dbp:spouse ?spouse.
FILTER (strlen(str(?spouse)) > 0 && lang(?spouse) = 'en')
}
Output

Nested wherehas with different relation in Eloquent

Here is some relation between Eloquent classes in a Laravel 5 application:
B belongs to A
B has one C
Table are built with the correct foreign keys.
Here is a scope method of A:
public function scopeMyScope(Builder $query)
{
return $query->whereHas('B.C', function($q) {
$q->whereRaw("1=1");
});
}
If we call A::myScope()->get(), it results in an SQL error, because laravel built this query:
select * from "a" where (select count(*) from "b" where "a"."a.b_id" = "b"."id" and (select count(*) from "c" where "c"."b_id" = "b"."id" and 1=1) >=1 ) >= 1
The error is:
Illuminate\Database\QueryException with message 'SQLSTATE[42703]: Undefined column: 7 ERROR: column c.b_id does not exist
So, the query built is wrong because there is no c.b_id column (because B hasOne C, so the join column is in C). Am I doing something wrong or is it a bug in laravel's query builder?
From what I can understand, you need to do a nested whereHas, so:
public function scopeMyScope(Builder $query)
{
// b is the name of the relationship...
return $query->whereHas('b', function($q)
{
// c is the name of the relationship...
$q->whereHas('c', function()
{
$q->where(1, 1);
});
}
}
Does this solve your problem?

How can I execute this Postgres query in Sequelize?

I need to translate this join query into Sequelize. I have associated the three tables involved in the join:
tracks.belongsToMany(tracks_playlists, { foreignKey: 'track_id' });
tracks.belongsToMany(tracks_meta, { foreignKey: 'track_id' });
tracks_meta.belongsToMany(tracks_playlists, { foreignKey: 'track_id'});
Here's the raw query that works:
SELECT tracks_playlists.playlist_id, tracks_playlists.track_id, tracks.track, tracks.track_type, tracks_meta.status, tracks_meta.app_id, tracks_meta.description, tracks_meta.ip
FROM tracks_playlists
INNER JOIN tracks on tracks_playlists.track_id = tracks.track_id
INNER JOIN tracks_meta on tracks.track_id = tracks_meta.track_id
WHERE tracks_playlists.playlist_id = 4;
When I try to run the following code
self.tracks_playlists_table.find({
where: {
playlist_id: 4
},
include: [{
model: self.tracks_table
}]
})
.then(function(resp) {
console.log(resp);
});
it spits out this error:
relation "playlists.trackstracks_playlists" does not exist
This is the query that it generates from my code:
SELECT "TracksPlaylists".*, "Tracks"."track_id" AS "Tracks.track_id",
"Tracks"."track" AS "Tracks.track", "Tracks"."track_type" AS "Tracks.track_type", "Tracks"."created" AS "Tracks.created", "Tracks"."updated" AS "Tracks.updated", "Tracks.trackstracks_playlists"."created" AS "Tracks.trackstracks_playlists.created", "Tracks.trackstracks_playlists"."updated" AS "Tracks.trackstracks_playlists.updated", "Tracks.trackstracks_playlists"."track_id" AS "Tracks.trackstracks_playlists.track_id"
FROM (SELECT "TracksPlaylists"."track_playlist_id", "TracksPlaylists"."track_id", "TracksPlaylists"."playlist_id", "TracksPlaylists"."created", "TracksPlaylists"."updated"
FROM "playlists"."tracks_playlists" AS "TracksPlaylists"
WHERE "TracksPlaylists"."playlist_id" = 4 LIMIT 1) AS "TracksPlaylists"
LEFT OUTER JOIN ("playlists"."trackstracks_playlists" AS "Tracks.trackstracks_playlists"
INNER JOIN "playlists"."tracks" AS "Tracks"
ON "Tracks"."track_id" = "Tracks.trackstracks_playlists"."track_id")
ON "TracksPlaylists"."track_playlist_id" = "Tracks.trackstracks_playlists"."track_id";
Why is it creating the column "trackstracks_playlists"?

How to sort a query result by the result of a function in mongoDB

How does one sort a query result by the result of a function in mongoDB? In SQL i have the follow code:
select field1,
field2,
myFunction(field1, 0)
from myTable
where field4 = 5
order by 3
I create the function below (inside mongodb) like alternative for my sql query. May not be ideal, but solved my problem:
function() {
var list = Array();
// myColletion is myTable equivalent
db.myCollection.find({ field4: 5}).forEach(
function (vet) {
list.push([ vet.field1,
vet.field2,
myFunction(vet.field1, 0)])
}
);
list.sort(function(a,b){return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));});
return list;
}

Set ANORM SELECT parameter to null

I'm trying to execute SELECT statement, where parameters might have null values:
SQL(
"""
SELECT id FROM devices WHERE
name = {name}
""")
.on("name" -> device.name)()
.collectFirst {
...
}.getOrElse {
...
}
device.name can return null. With db.default.logStatements=true I see that generated SQL looks like this: SELECT id FROM devices WHERE name = NULL.
name = NULL is not quite valid for Postgre SQL, but I've enabled it using transform_null_equals. Now when I execute SQL from log using pgAdmin, it works perfectly fine. However, ANORM does not find anything.
Following code does return result:
SQL(
"""
SELECT id FROM devices WHERE
name = NULL
""")
.on("name" -> device.name)()
.collectFirst {
...
}.getOrElse {
...
}
What's wrong with it?!