Multi-Model Data in SAP HANA: JSON, Spatial and Graph Explained
Most databases pick a lane: relational, document, graph, geospatial. Your data, unfortunately, doesn't. A logistics app needs delivery addresses (relational), route geometries (spatial), driver check-ins as JSON blobs (document), and a network of warehouses and routes (graph) — often in the same application.
The traditional answer is polyglot persistence: four databases, four drivers, four operational headaches, and application code stitching it all together. HANA's answer is different: one database, multiple engines, and SQL that reaches all of them.
One database, several engines
HANA is a multi-model database. Alongside the familiar relational (columnar and row) engines, it ships with:
Document store — schemaless JSON collections. You store JSON documents as-is, query into their structure with SQL, and index the fields you filter on. No shredding documents into relational tables, no object-relational mapping gymnastics.
Spatial engine — native geometry and geography types with spatial predicates: distance, intersection, containment. "Find all warehouses within 50 km of this point" is a single query, not a post-processing loop in application code.
Graph engine — nodes and edges with built-in traversal: shortest path, neighborhood expansion, pattern matching. Supply-chain networks, bill-of-material explosions, fraud rings — anything where the connections matter as much as the entities.
The point isn't that each engine exists — it's that they coexist. A single query can join a relational customer table to a JSON order document to a spatial warehouse lookup. Try doing that across four separate databases without crying.
Key takeaway: multi-model means one database serving relational, document, spatial, and graph workloads together — so cross-model queries stay inside the database instead of being stitched together in application code.
When to use each model
Document store fits semi-structured data that resists a fixed schema: IoT telemetry with varying fields per device type, user preferences, audit payloads, API request logs. If your relational design is sprouting "custom_field_1 … custom_field_47" columns, that's a document-shaped problem.
-- Querying into a JSON document collection
SELECT doc.checkin_id,
doc.driver ->> '$.name' AS driver_name
FROM DRIVER_CHECKINS AS doc
WHERE doc.payload ->> '$.status' = 'DELAYED';
Spatial fits anything with a location question: delivery zones, asset tracking, store catchment analysis, route planning. HANA understands both planar geometry and real earth geography, so distance calculations come out in actual meters, not degrees of wishful thinking.
Graph fits connected data where traversal is the workload: BOM explosions ("all components under this assembly, recursively"), organizational hierarchies, network impact analysis, recommendation paths. Recursive SQL can do some of this, but the graph engine's traversal algorithms are built for it and dramatically faster at depth.
The practical payoff
Consider a delivery-tracking scenario. Orders live in relational tables. Driver devices send JSON check-ins with GPS coordinates (document + spatial). Warehouses, hubs, and routes form a network (graph). One operational question — "which delayed shipments are heading to warehouses affected by the storm zone?" — touches all four models.
In a multi-model HANA setup, that's one query with joins across models. In a polyglot setup, it's four database round-trips, application-side joins, and consistency headaches. The operational savings compound too: one backup strategy, one HA setup, one security model, one team that knows the system.
That's the real argument for multi-model. Not a feature checklist — fewer moving parts.
Modeling tips for the document store
Flexible schema doesn't mean no schema thinking. A few habits keep JSON collections fast: index the fields you filter on (HANA supports indexes into document structure), keep documents reasonably sized (a 5 MB document per row will hurt), and decide up front which fields are queryable versus opaque payload. The most common mistake is treating the document store as a dumping ground — schemaless storage still rewards deliberate design.
Versioning deserves thought too. When the producing system adds fields, old documents won't have them — write queries defensively (WHERE doc.payload ->> '$.newField' returns null for old docs, which is usually what you want, but verify).
Graph in practice: a traversal example
Graphs in HANA are typically modeled as vertex and edge tables. A supply-chain example: warehouses and plants as vertices, transport lanes as edges with a cost attribute. The classic question — cheapest path from plant to customer region — is a shortest-path traversal:
-- Shortest path over a weighted graph workspace
SELECT * FROM GRAPH_TABLE ( SUPPLY_NETWORK
MATCH SHORTEST_PATH ( :start_vertex TO :end_vertex )
COLUMNS ( vertex_id, edge_cost )
);
Writing this as recursive SQL is possible and painful; the graph engine's traversal operators handle cycles, depth limits, and weighted costs natively. If your "hierarchy" queries are getting deeper than three levels of recursion, that's the signal to model it as a graph.
Spatial indexing and real queries
Spatial queries live or die by the spatial index. Without one, "warehouses within 50 km" becomes a full scan computing distances for every row. HANA builds spatial indexes automatically for geometry columns in most cases, but verify on large tables — and remember that mixing coordinate systems (WGS84 vs. planar) in one query is a classic source of silently wrong results. Keep a consistent SRID across your spatial columns and say so in your data dictionary.
Key takeaway: reach for document, spatial, or graph models when the data's shape demands it — and keep it all in HANA so cross-model questions stay as single queries, not multi-database plumbing.Read more →