OpenMetadata
OpenMetadata copied to clipboard
RDF: RdfTagUpdater builds invalid SPARQL for tag FQNs with special characters and writes non-canonical tag triples to the default graph
Summary
Removing a tag or glossary term from an entity with RDF enabled logs org.apache.jena.query.QueryParseException: Encountered " "<" "< "" at line 1, column 125 from RdfTagUpdater.removeTagInline. The PATCH itself succeeds because the exception is caught and logged, but the RDF sync is wrong in more ways than the parse error.
Sentry: https://collate-3b.sentry.io/issues/7735060699/
Stack (trimmed)
org.apache.jena.query.QueryParseException: Encountered " "<" "< "" at line 1, column 125.
at org.apache.jena.update.UpdateFactory.create(UpdateFactory.java:49)
at o.o.service.rdf.storage.JenaFusekiStorage.executeSparqlUpdate(JenaFusekiStorage.java:1490)
at o.o.service.rdf.rebuild.RebuildingRdfStorage.executeSparqlUpdate(RebuildingRdfStorage.java:115)
at o.o.service.rdf.RdfRepository.executeSparqlUpdate(RdfRepository.java:3864)
at o.o.service.rdf.RdfTagUpdater.removeTagInline(RdfTagUpdater.java:225)
at o.o.service.rdf.RdfTagUpdater.removeTag(RdfTagUpdater.java:195)
at o.o.service.jdbi3.EntityRepository$EntityUpdater.lambda$applyTagsDeleteInFlushAndDeferRdf$14(EntityRepository.java:9532)
...
at o.o.service.resources.databases.TableResource.patch(TableResource.java:597)
Root cause
- Invalid IRI.
RdfTagUpdaterbuilds SPARQL withString.formatand puts the tag FQN into an IRI without encoding it:baseUri + "tag/" + tagFQN.replace(".", "/"). A tag FQN with a space,",<,>,{,},|,^,`or\(quoted FQN parts likePII."Sensitive Data", for example) makes the IRI invalid, and Jena falls back to reading<as the less-than operator. Column 125 is exactly where the tag IRI starts when the target is the hash-basedentity/table/<fqn.hashCode()>URI. - Wrong URIs.
RdfPropertyMapper.resolveTagResourcewritesentity/tag/{uuid}/entity/glossaryTerm/{uuid}for tags andentity/{type}/{uuid}/entity/column/{urlEncodedFqn}for targets.RdfTagUpdaterusestag/<fqn path>andentity/<guessed type>/<fqn.hashCode()>, so even a query that parses never deletes the canonical triple. - Wrong graph. Entity triples are stored in the named graph
https://open-metadata.org/graph/knowledge.RdfTagUpdaterrunsINSERT DATAandDELETE WHEREagainst the default graph. Fuseki runs withtdb2:unionDefaultGraph true, so these orphan triples show up in queries that have noGRAPHclause (tag co-occurrence, communities, recommendations, inference rules) as duplicate or synthetic tag nodes. - Duplicate work.
postUpdate/postCreatealready callRdfUpdater.updateEntity, andJenaFusekiStorage.storeEntityreconcilesom:hasTag/om:hasGlossaryTerm(both are inTRANSLATOR_MANAGED_DIRECT_PREDICATES) for the entity and its columns with the canonical URIs. On the PATCH, PUT, create and import paths,RdfTagUpdater's writes add nothing correct.
Proposed fix
- Stop issuing hand-built SPARQL from
RdfTagUpdater. The entity snapshot write (RdfUpdater.updateEntity) should be the only thing that writes tag triples. - For tag-mutation paths with no snapshot write after them (bulk add/remove tags or glossary terms to assets, the
TaskWorkflowHandlerfallback / TierUpdate / tag-suggestion paths), callRdfUpdater.updateEntityfor the owning entity. - Clean up orphan default-graph triples already written: an RDF rebuild, or a verified one-off cleanup.
- Tests: an IT that adds and removes a tag whose FQN has a space/quote, checks the triple is gone in the union graph, and checks no synthetic
tag/…or hash-based subjects exist; an IT for the bulk add-to-assets RDF sync.
Affected code (OSS main)
openmetadata-service/src/main/java/org/openmetadata/service/rdf/RdfTagUpdater.javaopenmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java(applyTags*,applyTagsDelete*,*InFlushAndDeferRdf,applyTagsBatchWithRdf)jdbi3/TagRepository.java,jdbi3/GlossaryTermRepository.java(bulk asset ops),tasks/TaskWorkflowHandler.java