0

in allegro-graph database i have created an rdf type Product which has id, barcode, name predicates. Barcode is made as optional. Here in database, there are multiple duplicate records for barcode (which of type string). Now, i want to fetch the records of barcode whose count is greater than 1 and delete them.

Below is my query,

SELECT ?product ?barCode WHERE
{
  ?product rdf:type product:Product .
  optional { ?product product:barcode ?barCode .}
}
group by ?product ?barcode
having(count(?barcode) > 1)

This query has to display the results if the barcode record count is greater than 1. But the result ends up in giving "No Result".

Is there a way to fetch and delete the duplicates? Can anyone help me to write a query for this?

Thank you!

Pallavi
  • 1
  • 2
  • 1
    the logical error is that you also group by `?barcode`. Why would you do this? each group has size 1 then. You just want all products with more than barcode, `SELECT ?product WHERE { ?product rdf:type product:Product . optional { ?product product:barcode ?barcode .} } group by ?product having(count(?barcode) > 1)` – UninformedUser Jul 09 '19 at 09:55
  • 1
    if you want to see all barcodes, then do `group_concat`, i.e. `select ?product (group_concat(?barcode;separator=", ") as ?barcodes) ...` – UninformedUser Jul 09 '19 at 09:58
  • Hi, Thanks for the reply.. I have tried the above query but it's giving me an exception as - "Executing query failed: all selected vars must be aggregates (?product is not)" – Pallavi Jul 09 '19 at 10:11
  • Also, i have to delete the duplicate records which is present in database. I have used "DISTINCT" keyword which just eliminates the duplicates from result set. But doesn't delete the records in database. – Pallavi Jul 09 '19 at 10:14
  • the exception cannot occur with my query. it does `group by ?product`, please copy and paste the query from my comment – UninformedUser Jul 09 '19 at 10:23
  • 1
    Regarding duplicates, I don't know what you mean. RDF is a set of triples, so there are no duplicates by definition. And of course, `DISTINCT` is just use in a `SELECT` query which obviously does not modify the dataset. SPARQL 1.1 Update is the way to go. Anything beyond is Allegrograph specific, so look at https://franz.com/agraph/support/documentation/current/deleting-duplicate-triples.html#Deleting-duplicate-triples-introduction – UninformedUser Jul 09 '19 at 10:25

0 Answers0