SPARQL Parse Error: unexpected terminal - count

I've been using gruff to create and execute some simple SPARQL queries, but have run into some trouble. The following query works (prefixes have been left out):
SELECT ?k
WHERE
{ ?k rdf:type uw:pcservice . }
However, when I introduce the COUNT function, as seen below, I get the following error in gruff:
Error: Parse error: unexpected terminal ( (value: :|(|).
Expected terminals: (* varname reduced distinct).
[condition type: sparql-parse-error-unexpected-terminal]
SELECT (COUNT(?k) AS ?count)
WHERE
{ ?k rdf:type uw:pcservice . }
Not sure what is causing this. Any clues would be appreciated. Thanks.

Given the error it sounds like this tool doesn't support SPARQL 1.1. It's expecting a vanilla SELECT [*|varname|reduced|distinct], excluding aggregates and assignment.

Related

CREATE FUNCTION throws SQL Error (1064) (42000)

I'm trying to create a stored function in a MariaDB database.
I copied the function I'm trying to create from the MariaDB Docs:
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
//
DELIMITER ;
Unfortunately, I get the following error:
SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
What baffles me most is that the given code is supposed to resolve the very error code I'm getting according to the MariaDB docs
The solution is to specify a distinct delimiter for the duration of the process, using the DELIMITER command
It turned out, the client I used to issue the command, DBeaver, was causing the trouble.
After switching over to MySqlWorkbench everything worked as expected.
Apparently, DBeaver didn't recognise the delimiters correctly..
I think you may have forgotten to select the database you want this routine to be stored into.
So try adding a use as the first line
use `test`;
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
//
DELIMITER ;

update array elements with try catch

I'm trying to update large complexe json files and exit with detailled error message when detecting incoherent data (with jq 1.6).
I started to use functions and try/catch to produce a kind of java stacktrace containing input data from each level => easy, thank you JQ
But when I started to update array elements (using |=), I didn't find the solution
Here is a very simple example :
echo '{"array": [{"foo":"bar"}]}' | jq -c '.array[] |= try . catch (.)'
output : {"array":[{"__jq":0}]}
Do I made a mistake ? Is it a normal behaviour ?
Thanks for your help
The try-catch isn't really an expression, it yields no meaningful value, it merely executes some expression:
try-catch
Errors can be caught by using try EXP catch EXP. The first expression is executed, and if it fails then the second is executed with the error message. The output of the handler, if any, is output as if it had been the output of the expression to try.
emphasis mine.
So it would be wrong to use the value, you should perform the assignment within the try expression.
$ echo '{"array": [{"foo":"bar"}]}' | jq -c 'try (.array[] |= .) catch (.)'
You have stumbled upon a bug in jq 1.6. Using jq 1.5, one obtains the correct output:
{"array":[{"foo":"bar"}]}
However, the expression .array[] |= try . catch (.) is not one would ever use in practice, because if .array is a JSON array or JSON object, it just says: do nothing.
To understand try ... catch ..., it might help to consider this example:
$ jq -n 'try error("abc") catch ("The error message was " + .)'
"The error message was abc"

neo4j apoc - extraneous input '('

what am I doing wrong with the query
WITH [1] AS a, [2] AS b
RETURN apoc.coll.union(a,b);
Although it returns the result ([1,2]) In the browser it keeps telling me extraneous input '(', expecting...
Is this a problem or just "Lint garbage"? I am trying to identify a problem with another query where the same Lint message pops up in the same kind of use of the apoc function.
EDIT:
As discussed in the comments, CALL is not appropriate to functions (like apoc.coll.union). So I believe this behavior is a bug in the lint of Neo4j Browser. I opened an issue in the Neo4j Browser repo.
ORIGINAL ANSWER:
I believe the problem is that a user defined procedure (like apoc.coll.union) should be called with CALL and not after the RETURN statement. You can try something like:
WITH [1] AS a, [2] AS b
CALL apoc.coll.union(a,b) as r
RETURN r

what is needed in order to use db.scan ()

I'm trying to get the scan function to work, but it seems i'm missing something: According to the documention this should work:
var iter = new ydn.db.KeyIterator('contact');
db.scan([iter], function(keys, values)
But every time i call the function i get the following error:
Uncaught ydn.error.ArgumentException: Iterator argument must be an array.
A contact sore with the name 'contact' exists and i tried different libraries ydb-db but none of them worked.
Documentation is outdated. It should be:
db.scan(function(keys, values), [iter]
See unit test for it use case.

Conditional insert xquery failing with error "unexpected insert, expecting else"

I am trying to execute the xquery on Sedna database to conditionally update the container, as below
if(fn:exists(doc("blog")/entries/entry[#active="1" and #id="1"]/comments)) then
UPDATE insert <comment active="1"><name>sunil.s</name><email>suni.l.s#gmail.com</email><desc>desbbh</desc></comment> into doc("blog")/entries/entry[#active="1" and #id="1"]/comments
else
UPDATE insert <comments><comment active="1"><name>sunil.s</name><email>sunil.s#gmail.com</email><desc>sdd</desc></comment></comments> into doc("blog")/entries/entry[#active="1" and #id="1"]
But this query always failing with below error
SEDNA Message: ERROR XPST0003 It is a static error if an expression is
not a valid instance of the grammar defined in A.1 EBNF. Details: at
(2:8), syntax error, unexpected insert, expecting else
The error indicate that it is expecting else instead of insert in the second line.
Can someone please help me understand problem with the query and possible fix?
Your query assumes the existence of an expression with syntax like
UPDATE insert expr into expr
There is no such expression in XQuery (or the XQuery Update Facility). Instead, it appears to be a non-standard syntax supported by Sedna.
However, the documentation (http://www.sedna.org/progguide/ProgGuidesu6.html#x12-430002.3) refers to it as a "statement", not an "expression", suggesting that it must be the 'top-level' (outermost) construct in your query.
To accomplish this, you could rewrite your query as:
UPDATE
insert
if ... then <comment>...</comment> else <comments>...</comments>
into
if ... then doc("blog")/.../comments else doc("blog")/...
Unfortunately, this repeats the 'if' condition; it's not clear whether Sedna provides a syntax for factoring that out, e.g.
UPDATE
let $c := ...
insert
if $c then <comment>...</comment> else <comments>...</comments>
into
if $c then doc("blog")/.../comments else doc("blog")/...

Resources