query

Name

query

description

query 表函数(table-valued-function,tvf),可用于将查询语句直接透传到某个 catalog 进行数据查询

QUERY - 图1note

Doris 2.1.3 版本开始支持,当前仅支持透传查询 jdbc catalog。 需要先在 Doris 中创建对应的 catalog。

syntax

  1. query(
  2. "catalog" = "catalog_name",
  3. "query" = "select * from db_name.table_name where condition"
  4. );

参数说明

query表函数 tvf中的每一个参数都是一个 "key"="value" 对。 相关参数:

  • catalog: (必填) catalog名称,需要按照catalog的名称填写。
  • query: (必填) 需要执行的查询语句。

Example

使用 query 函数查询 jdbc 数据源中的表

  1. select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition");

可以配合desc function使用

  1. desc function query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition");

Keywords

  1. query, table-valued-function, tvf

Best Prac

透传查询 jdbc catalog 数据源中的表

  1. select * from query("catalog" = "jdbc", "query" = "select * from test.student");
  2. +------+---------+
  3. | id | name |
  4. +------+---------+
  5. | 1 | alice |
  6. | 2 | bob |
  7. | 3 | jack |
  8. +------+---------+
  9. select * from query("catalog" = "jdbc", "query" = "select * from test.score");
  10. +------+---------+
  11. | id | score |
  12. +------+---------+
  13. | 1 | 100 |
  14. | 2 | 90 |
  15. | 3 | 80 |
  16. +------+---------+

透传关联查询 jdbc catalog 数据源中的表

  1. select * 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");
  2. +------+---------+---------+
  3. | id | name | score |
  4. +------+---------+---------+
  5. | 1 | alice | 100 |
  6. | 2 | bob | 90 |
  7. | 3 | jack | 80 |
  8. +------+---------+---------+