segmentation fault and agtype array error - cypher

If I execute the following query
SELECT * FROM ag_catalog.cypher('graph', $$
match (p:Project)-[:Has]->(t:Task)-[:AssignedTo]->(u:Person)
with distinct t, {tn: t.name, user: collect(u)} as task
with distinct p, {pn: p.name, task: collect(task)} as project
return project
$$) as (p agtype);
the segmentation fault occurs.
and if I execute this query
SELECT * FROM ag_catalog.cypher('graph', $$
match (p:Project)-[:Has]->(t:Task)-[:AssignedTo]->(u:Person)
with p, t, collect(u) as users
with p, {tn: t.name, users: users} as task
with p, collect(task) as tasks
with {pn: p.name, tasks:tasks} as project
return project
$$) as (p agtype);
the error message "container is not an agtype array" is shown.
run the query and see the result. The above query works fine with neo4j.

Related

Hive Terminal RuntimeException after query execution

I have executed this query on HIVE, using that dataset:
https://data.europa.eu/data/datasets/erasmus-mobility-statistics-2014-2019-v2?locale=en:
select i.foe, i.pn, i.massimo
from
(
SELECT m.foe, m.pn, max(m.somma) AS massimo
FROM
(
select pn, foe, sum(participants) as somma
from erasmus
WHERE foe <> "? Unknown ?" and participants>0
group by foe, pn
) as m
group by m.foe, m.pn
) as i
where i.massimo=
(
select sum(participants) as somma
from erasmus
WHERE foe <> "? Unknown ?" and participants>0 AND i.foe=foe
group by foe, pn
)
At the end of execution I get this error back:
Error: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row (tag=0) {"key":{"_col0":"Audio-visual techniques and media production","_col1":"AD"},"value":null}
caused by: org.apache.hadoop.hive.ql.exec.UDFArgumentException: Scalar subquery expression returns more than one row.
How can I solve this? Thank you.

Using WITH in MonetDB

I'm trying to execute the next query in MonetDB using "WITH":
with a as (select data_string from colombia.dim_tempo)
select
t.ano_mes
,f.sg_estado
,f.cod_produto
, sum(f.qtd_vendidas) as qtd_vendidas
, count(*) as fact_count
from colombia.fact_retail_market f, colombia.dim_tempo t
where f.cod_anomes = t.data_string
and t.data_string in (a.data_string)
group by
t.ano_mes
,f.sg_estado
,f.cod_produto ;
But always get this message:
What's wrong with the sentence?
The WHERE clause needs to be:
WHERE f.cod_anomes = t.data_string AND
t.data_string IN (SELECT data_string FROM a)
That is, IN needs to be followed by a subquery against the CTE.

What is the syntax problem here using this subquery inside where clause

SELECT p.pnum, p.pname
FROM professor p, class c
WHERE p.pnum = c.pnum AND c.cnum = CS245 AND (SELECT COUNT(*) FROM (SELECT MAX(m.grade), MAX(m.grade) - MIN(m.grade) AS diff
FROM mark m WHERE m.cnum = c.cnum AND m.term = c.term AND m.section = c.section AND diff <= 20)) = 3
Incorrect syntax near ')'. Expecting AS, FOR_PATH, ID, or QUOTED_ID.
Consider the following example:
SELECT COUNT(1)
FROM SYSCAT.TABLES T
WHERE
(
-- SELECT COUNT(1)
-- FROM
-- (
SELECT COUNT(1)
FROM SYSCAT.COLUMNS C
WHERE C.TABSCHEMA=T.TABSCHEMA AND C.TABNAME=T.TABNAME
-- )
) > 50;
The query above works as is. But the problem is, that if you uncomment the commented out lines, you get the following error message: "T.TABNAME" is an undefined name. and least in Db2 for Linux, Unix and Windows.
You can't push external to the sub-select column references too deeply.
So, your query is incorrect.
It's hard to correct it, until you provide the task description with data sample and the result expected.
I can see a potential syntax errors: It seems that CS245 refers to a value c.cnum may take and not a column name. If that is the case, it should be enclosed in single quotes.

ERROR: column mm.geom does not exist in PostgreSQL execution using R

I am trying to run the model in R software which calls functions from GRASS GIS (version 7.0.2) and PostgreSQL (version 9.5) to complete the task. I have created a database in PostgreSQL and created an extension Postgis, then imported required vector layers into the database using Postgis shapefile importer. Every time I try to run using R (run as an administrator), it returns an error like:
Error in fetch(dbSendQuery(con, q, n = -1)) :
error in evaluating the argument 'res' in selecting a method for function 'fetch': Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: column mm.geom does not exist
LINE 5: (st_dump(st_intersection(r.geom, mm.geom))).geom as geom,
^
HINT: Perhaps you meant to reference the column "r.geom".
QUERY:
insert into m_rays
with os as (
select r.ray, st_endpoint(r.geom) as s,
(st_dump(st_intersection(r.geom, mm.geom))).geom as geom,
mm.legend, mm.hgt as hgt, r.totlen
from rays as r,bh_gd_ne_clip as mm
where st_intersects(r.geom, mm.geom)
)
select os.ray, os.geom, os.hgt, l.absorb, l.barrier, os.totlen,
st_length(os.geom) as shape_length, st_distance(os.s, st_endpoint(os.geom)) as near_dist
from os left join lut as l
on os.legend = l.legend
CONTEXT: PL/pgSQL function do_crtn(text,text,text) line 30 at EXECUTE
I have checked over and over again, column geometry does exist in Schema>Public>Views of PostgreSQL. Any advise on how to resolve this error?
add quotes and then use r."geom" instead r.geom

How can I call a db2 function and have it return multiple xml record data?

In SQL, I need to create xml code that looks like this:
<Phone>
<PhoneTypeCode tc="12">Mobile</PhoneTypeCode>
<Area>801</Area>
<DialNumber>9996666</DialNumber>
</Phone>
<Phone>
<PhoneTypeCode tc="2">Business</PhoneTypeCode>
<Area>801</Area>
<DialNumber>1113333</DialNumber>
</Phone>
When I run this sql, I correctly get two rows of data, as I would expect:
select
xmlelement(
Name "Phone",
xmlelement(
name "PhoneTypeCode",
xmlattributes(
trim(p1.phtype) as "tc"
),
trim(p1.desc)
),
xmlelement(name "AreaCode", p1.area),
xmlelement(name "DialNumber", p1.phone)
) as xml
from phone as p1 where p1.entityid = 256285;
These are the two rows of data I get back, exactly as I expected:
<Phone><PhoneTypeCode tc="12">Mobile</PhoneTypeCode><AreaCode>351</AreaCode> <DialNumber>4443333</DialNumber></Phone>
<Phone><PhoneTypeCode tc="2">Business</PhoneTypeCode><AreaCode>351</AreaCode><DialNumber>3911111</DialNumber></Phone>
However, when I try putting this same code in a function and call this function, I get this error:
SQL State: 21000
Vendor Code: -811
Message: [SQL0811] Result of SELECT more than one row. Cause . . . . . : The result table of a SELECT INTO statement, a subquery, or a subselect of a SET statement contains more than one row. The error type is 2. If the error type is 1 then a SELECT INTO statement attempted to return more than one row. If the error type is 2 then a subselect of a basic predicate has produced more than one row. Only one row is allowed. Recovery . . . : Change the selection so that only one result row is returned and then try the request again. The DECLARE CURSOR, OPEN, and FETCH statements must be used to process more than one result row. For a subquery the IN, EXISTS, ANY or ALL predicates can be used to process more than one result row. If one row was expected, there may be data errors, such as duplicate rows, that are causing more than one row to be returned.
**How can I fix this function so that it will return all rows of data as one block of xml code as I expect?
CREATE or replace FUNCTION xml_entity_phones (
#Entity_ID bigint)
RETURNS xml
LANGUAGE SQL
NOT DETERMINISTIC
reads SQL DATA
RETURNS NULL ON NULL INPUT
NO EXTERNAL ACTION
ALLOW PARALLEL
NOT FENCED
begin
return (
select
xmlelement(
Name "Phone",
xmlelement(
name "PhoneTypeCode",
xmlattributes(
trim(p.phtype) as "tc"
),
trim(p.desc)
),
xmlelement(name "AreaCode", p.area),
xmlelement(name "DialNumber", p.phone)
) as xml
from phone p where p.entityid = #entity_id
);
end
;
The procedure that calls this function, is building an xml file that includes different types of phones, which I wanted to build with the above function.
The end goal is to have an xml document (valid or not) that looks like this:
<TXLife>
<TXLifeRequest>
<OLife>
<Person>
<Phone>
<PhoneTypeCode tc="12">Mobile...
<Area...
<DialNumber...
</Phone>
<Phone>
<PhoneTypeCode tc="2">Business...
<Area...
<DialNumber...
</Phone>
...
I was hoping to build the entire phone section xml with a function call like: xml_entity_phones(bigint(e.entityid)).
OK, I changed the function to look like this with xmlagg():
begin
return (
select
xmlagg(
xmlelement(
Name "Phone",
xmlelement(
name "PhoneTypeCode",
xmlattributes(
trim(p.phtype) as "tc"
),
trim(p.desc)
),
xmlelement(name "AreaCode", p.area),
xmlelement(name "DialNumber", p.phone)
)
) as xml
from phone p
where p.entityid = #entity_id
);
end
But now when I call the function with values(xml_entity_phones(256285));, I get ++++++++++++++ as a result. And when I call the procedure that calls this function, I get this error:
SQL State: 22023
Vendor Code: -802
Message: [SQL0802] Data conversion or data mapping error. Cause . . . . . : Error type 10 has occurred 10 -- User-defined function returned a mapping error.
I did notice that when I include an extra element of Phones using xmlagg as suggested in a couple of answers below, that it does return the xmlagg() result successfully. However I can't have that extra element of Phones because it goes against the standard I need to adhere to.
Is there a way to return the xmlagg without the extra layer?
This is where you would use XMLAGG():
begin
return (
select
xmlelement(name "Phones", xmlagg(
xmlelement(
Name "Phone",
xmlelement(
name "PhoneTypeCode",
xmlattributes(
trim(p.phtype) as "tc"
),
trim(p.desc)
),
xmlelement(name "AreaCode", p.area),
xmlelement(name "DialNumber", p.phone)
)
)) as xml
from phone p where p.entityid = #entity_id
);
end
Obviously, I don't have your data but this simple example shows that the approach works:
$ db2 "create or replace function t () returns xml language sql begin \
return (select xmlagg(xmlelement(name \"tab\", tabname )) from syscat.tables \
where tabname like '%AUTH%' and tabschema = 'SYSCAT'); end"
DB20000I The SQL command completed successfully.
$ db2 "values t()"
1
----------------------------------------------------------------------------
<tab>COLAUTH</tab><tab>DBAUTH</tab><tab>INDEXAUTH</tab><tab>LIBRARYAUTH</tab>
<tab>MODULEAUTH</tab><tab>PACKAGEAUTH</tab><tab>PASSTHRUAUTH</tab><tab>ROLEAUTH
</tab><tab>ROUTINEAUTH</tab><tab>SCHEMAAUTH</tab><tab>SEQUENCEAUTH</tab>tab>
SURROGATEAUTHIDS </tab><tab>TABAUTH</tab><tab>TBSPACEAUTH</tab><tab>
VARIABLEAUTH</tab><tab>WORKLOADAUTH</tab><tab>XSROBJECTAUTH</tab>
1 record(s) selected.
When you issue a SQL select, you are retrieving a resultset (in some way a cursor). What you have is not a XML, it is a resultset that has two XML documents, or two rows. A XML document has just one parent, here you have two parents (phone)
You can retrieve a cursor like the one you have via a Stored Procedure.
create procedure x ()
P1:BEGIN
DECLARE cursor1 CURSOR WITH RETURN TO CLIENT FOR
xmlelement(
Name "Phone",
...
xmlelement(name "DialNumber", p1.phone)
) as xml
from phone as p1 where p1.entityid = 256285;
open cursor1;
END P1;