QUERY
更新时间:2025-10-16
描述
query 表函数(table-valued-function,tvf),可用于将查询语句直接透传到某个 catalog 进行数据查询
PALO 2.1.3 版本开始支持,当前仅支持透传查询 jdbc catalog。 需要先在 PALO 中创建对应的 catalog。
语法
SQL
1QUERY(
2 "catalog" = "<catalog>",
3 "query" = "<query_sql>"
4 );
必填参数
query 表函数 tvf 中的每一个参数都是一个 "key"="value"
对
字段 | 描述 |
---|---|
catalog |
catalog 名称,需要按照 catalog 的名称填写 |
query |
需要执行的查询语句 |
举例
可以配合desc function
使用
SQL
1desc function query("catalog" = "jdbc", "query" = "select * from test.student");
Text
1+-------+------+------+-------+---------+-------+
2| Field | Type | Null | Key | Default | Extra |
3+-------+------+------+-------+---------+-------+
4| id | int | Yes | true | NULL | |
5| name | text | Yes | false | NULL | NONE |
6+-------+------+------+-------+---------+-------+
透传查询 jdbc catalog 数据源中的表
SQL
1select * from query("catalog" = "jdbc", "query" = "select * from test.student");
Text
1+------+---------+
2| id | name |
3+------+---------+
4| 1 | alice |
5| 2 | bob |
6| 3 | jack |
7+------+---------+
SQL
1select * from query("catalog" = "jdbc", "query" = "select * from test.score");
Text
1+------+---------+
2| id | score |
3+------+---------+
4| 1 | 100 |
5| 2 | 90 |
6| 3 | 80 |
7+------+---------+
透传关联查询 jdbc catalog 数据源中的表
SQL
1select * from query("catalog" = "jdbc", "query" = "select a.id, a.name, b.score from test.student a join test.score b on a.id = b.id");
Plain Text
1+------+---------+---------+
2| id | name | score |
3+------+---------+---------+
4| 1 | alice | 100 |
5| 2 | bob | 90 |
6| 3 | jack | 80 |
7+------+---------+---------+