Ontology SQL is in the beta phase of development and some features may not be available on your environment. Functionality may change during active development. Contact Palantir support to request access to Beta features.
Ontology SQL is Foundry's SQL query engine for ontology objects, purpose-built to bring familiar SQL semantics to your ontology data. Ontology SQL lets you run SQL queries directly against object types, many-to-many links, and interfaces. With Ontology SQL, you can query ontology objects using standard Spark SQL syntax, executing directly against object storage. Ontology SQL is built on Foundry's SQL infrastructure, providing a single SELECT statement interface that supports variables, standard SQL functions, and seamless integration with your existing ontology modeling.
Ontology SQL provides a unified SQL experience for querying ontology objects, sharing the same SQL dialect and front-end experience as Foundry's other SQL offerings while operating with its own specialized backend.
You can interact with Ontology SQL in the object mode SQL console. Once in the console, you will be able to query your object types using standard SQL syntax. For a complete reference of available operations, refer to the SQL dialect documentation.
Ontology SQL queries reference object types using their resource identifiers (RIDs). The basic syntax follows this pattern:
Copied!1SELECT * FROM `ri.ontology.main.object-type.<object-type-rid>`;
For example, a query for all properties from an Employee object type would be written as follows:
Copied!1SELECT * FROM `ri.ontology.main.object-type.00000000-0000-0000-0000-000000000000`;
A query for many-to-many links can be written as shown below:
Copied!1SELECT * FROM `ri.ontology.main.relation.<relation-rid>`;
All object properties are referenced in queries using their API names, not their display names. The columns available in your query correspond directly to the property API names defined in your ontology. You can find property API names in Ontology Manager.
For example, if an Employee object has properties with API names employeeId, firstName, and, department, you would write a query as follows:
Copied!1 2SELECT employeeId, firstName, department FROM ri.ontology.main.object-type.<employee-rid>;
One-to-one and one-to-many link types do not need to be defined in Ontology Manager to be used in Ontology SQL. You can use SQL to join objects however you wish. Performance will be identical whether or not the join uses a link defined in Ontology Manager.
Many-to-many links require join tables and must be defined in Ontology Manager. To use them in your SQL joins, you must select the link type in the SQL query.
When querying many-to-many link tables, column names follow a specific convention to avoid ambiguity.
Each foreign key column is named using the pattern below:
<objectTypeApiName>_<relationApiName>
Consider a many-to-many relationship between Person and Car objects.
The Ontology setup is as follows:
Person (API name: person)
personIdPerson side: vehiclesCar (API name: car)
carIdCar side: driversri.ontology.main.relation.0Below is an example query to find all cars driven by a specific person:
Copied!1 2 3 4 5SELECT c.* FROM `ri.ontology.main.relation.0` AS linkTable INNER JOIN `car` AS c ON c.`carId` = linkTable.`person_vehicles` WHERE linkTable.`car_drivers` = 'person-123';
And an example query to find all people who drive a specific car:
Copied!1 2 3 4 5SELECT p.* FROM `ri.ontology.main.relation.0` AS linkTable INNER JOIN `person` AS p ON p.`personId` = linkTable.`car_drivers` WHERE linkTable.`person_vehicles` = 'car-456';
Always use table aliases when working with many-to-many links. Without aliases, column names can become difficult to read and maintain. Compare the following examples:
With aliases (recommended):
Copied!1 2 3 4SELECT c.* FROM `ri.ontology.main.relation.0` AS linkTable INNER JOIN car AS c ON c.carId = linkTable.person_vehicles WHERE linkTable.car_drivers = 'person-123';
Copied!1 2 3 4SELECT car.* FROM `ri.ontology.main.relation.0` INNER JOIN car ON car.carId = `ri.ontology.main.relation.0`.person_vehicles WHERE `ri.ontology.main.relation.0`.car_drivers = 'person-123';
Ontology SQL supports variables through the DECLARE statement:
Copied!1 2 3 4 5DECLARE @minSalary DOUBLE = 75000.0, @department STRING = 'Engineering'; SELECT employeeId, salary FROM ri.ontology.main.object-type.<employee-rid> WHERE salary > @minSalary AND department = @department;
DECLARE statement must be the first statement in your query, and can only be used once. Reference the example above for how to declare multiple variables.SET statements are not allowed.Some keywords, such as user and result, are reserved. It is best practice to wrap column names in backticks to avoid conflicts as shown below:
Copied!1SELECT `user`, `result` FROM ri.ontology.main.object-type.<object-rid>;
When applying functions or transformations to columns in WHERE clauses, or when using computed columns for filtering, the query engine cannot leverage indices. This severely limits query performance and the scale of computation.
Avoid the following patterns that prevent index usage:
Copied!1 2 3 4 5 6 7 8 9-- Filtering on a computed column SELECT employeeId, salary, bonus FROM employee WHERE salary + bonus > 100000; -- Filtering on a function result SELECT employeeId, hireDate FROM employee WHERE YEAR(hireDate) = 2023;
Prefer the following patterns to allow index usage:
Copied!1 2 3 4 5 6 7 8 9-- Filter on the original column directly SELECT employeeId, salary, bonus FROM employee WHERE salary > 100000 - bonus; -- Use date range comparison instead of extracting year SELECT employeeId, hireDate FROM employee WHERE hireDate >= '2023-01-01' AND hireDate < '2024-01-01';
The same principle applies to aggregations. Filtering over columns that were transformed by any part of the query (for example, colA + colB AS newColumn) means the engine cannot use indices to efficiently locate matching rows, resulting in slower performance.
Do not select large columns like vectors (embeddings) from queries when not needed. These columns can significantly increase query execution time and memory usage without providing value if they are not required for your analysis.
SELECT queries only: Ontology SQL exclusively supports read operations. No data modification (INSERT, UPDATE, DELETE) or schema definition (CREATE, ALTER, DROP) operations are available.SELECT statement: Only one SELECT statement is allowed per query, with the exception of the DECLARE statement for variables.OFFSET is supported as long as OFFSET + LIMIT is less than or equal to 10,000. For example, OFFSET 1000 LIMIT 1000 works, but OFFSET 9000 LIMIT 2000 does not. If interacting with Ontology SQL using applications, those respective applications may enforce stricter limits.NotEnoughSparkResources error.| Feature | Support status |
|---|---|
| Object types | Supported; object type must be defined in Ontology Manager |
| Many-to-many links | Supported; link type must be defined in Ontology Manager |
| Interfaces | Not supported |
| One-to-one and one-to-many links | Supported; can be used directly in Ontology SQL as defining the link type in Ontology Manager is not required |
| Branching | Not supported |
| Scenarios | Not supported |
| Write operations | Not supported |