SQL examples(SQL 示例)¶
This page provides hands-on SQL examples for common tasks in Foundry, including reading and writing tabular data and querying ontology object types. Examples can be run from SQL Studio, the embedded SQL console, or external SQL clients connected via Arrow Flight SQL. For full syntax reference, see the SQL dialect documentation.
Tabular data¶
The following examples query and modify datasets and Iceberg tables in data mode, executed by the Furnace engine.
Create and read a dataset¶
-- Create a dataset
CREATE OR REPLACE TABLE `/path/dataset-name` USING parquet AS
SELECT *
FROM `/path/dataset-input`;
-- Query a dataset
SELECT *
FROM `/path/dataset-name`
WHERE column = 'value';
Create and modify an Iceberg table¶
:::callout{theme="neutral"} You must have Iceberg tables enabled in your environment to create Iceberg tables. :::
-- Create an empty Iceberg table
CREATE TABLE `/path/table-name` (
id INT,
name STRING
)
USING iceberg;
-- Insert rows
INSERT INTO `/path/table-name`
VALUES (1, 'apple'), (2, 'pear');
-- Update rows
UPDATE `/path/table-name`
SET name = 'clementine'
WHERE id = 2;
-- Delete rows
DELETE FROM `/path/table-name`
WHERE id = 1;
Ontology object types¶
The following examples query ontology object types in object mode, executed by the Ontology SQL engine. Object types are referenced by their resource identifier (RID).
Query an object type¶
SELECT employeeId, firstName, department
FROM `ri.ontology.main.object-type.<employee-rid>`
WHERE department = 'Engineering';
Query a many-to-many link¶
-- Find all cars driven by a specific person
SELECT c.*
FROM `ri.ontology.main.relation.<relation-rid>` AS linkTable
INNER JOIN `car` AS c
ON c.`carId` = linkTable.`person_vehicles`
WHERE linkTable.`car_drivers` = 'person-123';
For details on link table column conventions and other object-querying patterns, see the Ontology SQL documentation.
Troubleshooting¶
If you see an error such as Output folder is not enabled for Iceberg tables. Please use a different format., you may be trying to write an Iceberg table to an unsupported location. This indicates that Iceberg tables are not enabled for your environment or for the specific project location you are writing to. Modify your code to write to a different data format (for example, USING parquet), or contact Palantir Support to enable Foundry Iceberg tables.
中文翻译¶
SQL 示例¶
本页面提供了在 Foundry 中执行常见任务的实用 SQL 示例,包括读写表格数据以及查询本体对象类型(ontology object types)。这些示例可通过 SQL Studio、嵌入式 SQL 控制台 或通过 Arrow Flight SQL 连接的外部 SQL 客户端运行。完整的语法参考请参见 SQL 方言 文档。
表格数据¶
以下示例在 数据模式 下查询和修改 数据集 及 Iceberg 表,由 Furnace 引擎执行。
创建并读取数据集¶
-- 创建一个数据集
CREATE OR REPLACE TABLE `/path/dataset-name` USING parquet AS
SELECT *
FROM `/path/dataset-input`;
-- 查询一个数据集
SELECT *
FROM `/path/dataset-name`
WHERE column = 'value';
创建并修改 Iceberg 表¶
:::callout{theme="neutral"} 要创建 Iceberg 表,您的环境中必须已启用 Iceberg 表 功能。 :::
-- 创建一个空的 Iceberg 表
CREATE TABLE `/path/table-name` (
id INT,
name STRING
)
USING iceberg;
-- 插入行
INSERT INTO `/path/table-name`
VALUES (1, 'apple'), (2, 'pear');
-- 更新行
UPDATE `/path/table-name`
SET name = 'clementine'
WHERE id = 2;
-- 删除行
DELETE FROM `/path/table-name`
WHERE id = 1;
本体对象类型¶
以下示例在 对象模式 下查询本体对象类型,由 Ontology SQL 引擎执行。对象类型通过其资源标识符(RID)进行引用。
查询对象类型¶
SELECT employeeId, firstName, department
FROM `ri.ontology.main.object-type.<employee-rid>`
WHERE department = 'Engineering';
查询多对多链接¶
-- 查找特定人员驾驶的所有汽车
SELECT c.*
FROM `ri.ontology.main.relation.<relation-rid>` AS linkTable
INNER JOIN `car` AS c
ON c.`carId` = linkTable.`person_vehicles`
WHERE linkTable.`car_drivers` = 'person-123';
有关链接表列命名约定及其他对象查询模式的详细信息,请参见 Ontology SQL 文档。
故障排除¶
如果您看到类似 Output folder is not enabled for Iceberg tables. Please use a different format. 的错误,说明您可能正在尝试将 Iceberg 表写入不受支持的位置。这表明您的环境或您正在写入的特定项目位置未启用 Iceberg 表 功能。请修改您的代码以写入其他数据格式(例如 USING parquet),或联系 Palantir 支持以启用 Foundry Iceberg 表。