This is an automated email from the ASF dual-hosted git repository. zykkk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new 52c03215ae [docs](function) add query tvf docs (#637) 52c03215ae is described below commit 52c03215ae9951dacbcc83c4184f480773ac45a3 Author: zy-kkk <zhongy...@gmail.com> AuthorDate: Sat May 11 20:00:03 2024 +0800 [docs](function) add query tvf docs (#637) --- docs/lakehouse/database/jdbc.md | 30 +++++- .../sql-functions/table-functions/query.md | 110 +++++++++++++++++++++ .../current/lakehouse/database/jdbc.md | 29 +++++- .../sql-functions/table-functions/query.md | 110 +++++++++++++++++++++ .../version-2.1/lakehouse/database/jdbc.md | 29 +++++- .../sql-functions/table-functions/query.md | 110 +++++++++++++++++++++ sidebars.json | 3 +- .../version-2.1/lakehouse/database/jdbc.md | 30 +++++- .../sql-functions/table-functions/query.md | 110 +++++++++++++++++++++ versioned_sidebars/version-2.1-sidebars.json | 3 +- 10 files changed, 552 insertions(+), 12 deletions(-) diff --git a/docs/lakehouse/database/jdbc.md b/docs/lakehouse/database/jdbc.md index 093de7c71c..bfd85ed4f6 100644 --- a/docs/lakehouse/database/jdbc.md +++ b/docs/lakehouse/database/jdbc.md @@ -364,8 +364,13 @@ DROP CATALOG <catalog_name>; ## SQL Passthrough In versions prior to Doris 2.0.3, users could only perform query operations (SELECT) through the JDBC catalog. + Starting from version Doris 2.0.4, users can perform DDL (Data Definition Language) and DML (Data Manipulation Language) operations on JDBC data sources using the `CALL` command. +Starting from version Doris 2.1.4, users can perform data query operations on JDBC data sources through the `query` table function. + +### Passthrough of DDL and DML + ``` CALL EXECUTE_STMT("catalog_name", "raw_stmt_string"); ``` @@ -383,6 +388,24 @@ CALL EXECUTE_STMT("jdbc_catalog", "delete from db1.tbl1 where k1 = 2"); CALL EXECUTE_STMT("jdbc_catalog", "create table db1.tbl2 (k1 int)"); ``` +### Passthrough query + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +The `query` table function takes two parameters: + +- `catalog`: (required) catalog name, which needs to be filled in according to the name of the catalog. +- `query`: (required) The query statement to be executed. + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + ### Principles and Limitations Through the `CALL EXECUTE_STMT()` command, Doris directly sends the SQL statements written by the user to the JDBC data source associated with the catalog for execution. Therefore, this operation has the following limitations: @@ -390,10 +413,11 @@ Through the `CALL EXECUTE_STMT()` command, Doris directly sends the SQL statemen - The SQL statements must be in the syntax specific to the data source, as Doris does not perform syntax and semantic checks. - It is recommended that table names in SQL statements be fully qualified, i.e., in the `db.tbl` format. If the `db` is not specified, the db name specified in the JDBC catalog JDBC URL will be used. - SQL statements cannot reference tables outside of the JDBC data source, nor can they reference Doris's tables. However, they can reference tables within the JDBC data source that have not been synchronized to the Doris JDBC catalog. -- When executing DML statements, it is not possible to obtain the number of rows inserted, updated, or deleted; success of the command execution can only be confirmed. -- Only users with LOAD permissions on the catalog can execute this command. +- Only users with LOAD permissions on the Catalog can execute the `CALL EXECUTE_STMT()` command. +- Only users with SELECT permissions on Catalog can execute the `query()` table function. +- The supported data types of the data read by the `query` table function are consistent with the data types supported by the queried catalog type. -### Time zone +## Time zone Since the time types of some external data sources have time zone information, but the time types of Doris do not have time zone information, you need to pay attention to the time zone issue when querying the time types of external data sources. diff --git a/docs/sql-manual/sql-functions/table-functions/query.md b/docs/sql-manual/sql-functions/table-functions/query.md new file mode 100644 index 0000000000..86164bf567 --- /dev/null +++ b/docs/sql-manual/sql-functions/table-functions/query.md @@ -0,0 +1,110 @@ +--- +{ + "title": "QUERY", + "language": "en" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## query + +### Name + +query + +### description + +Query table function (table-valued-function, tvf) can be used to transparently transmit query statements directly to a catalog for data query + +:::info note +Supported by Doris version 2.1.4, currently only transparent query jdbc catalog is supported. +You need to create the corresponding catalog in Doris first. +::: + +#### syntax + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +**Parameter Description** + +Each parameter in the query table function tvf is a `"key"="value"` pair. +Related parameters: +- `catalog`: (required) catalog name, which needs to be filled in according to the name of the catalog. +- `query`: (required) The query statement to be executed. + +### Example + +Use the query function to query tables in the jdbc data source + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +Can be used with `desc function` + +```sql +desc function query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +### Keywords + + query, table-valued-function, tvf + +### Best Prac + +Transparent query for tables in jdbc catalog data source + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from test.student"); ++------+---------+ +| id | name | ++------+---------+ +| 1 | alice | +| 2 | bob | +| 3 | jack | ++------+---------+ +select * from query("catalog" = "jdbc", "query" = "select * from test.score"); ++------+---------+ +| id | score | ++------+---------+ +| 1 | 100 | +| 2 | 90 | +| 3 | 80 | ++------+---------+ +``` + +Transparent join query for tables in jdbc catalog data source + +```sql +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"); ++------+---------+---------+ +| id | name | score | ++------+---------+---------+ +| 1 | alice | 100 | +| 2 | bob | 90 | +| 3 | jack | 80 | ++------+---------+---------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/lakehouse/database/jdbc.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/lakehouse/database/jdbc.md index bb0ed4d07d..0666b5d93c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/lakehouse/database/jdbc.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/lakehouse/database/jdbc.md @@ -367,8 +367,13 @@ DROP CATALOG <catalog_name>; ### SQL 透传 在 Doris 2.0.3 之前的版本中,用户只能通过 JDBC Catalog 进行查询操作(SELECT)。 + 在 Doris 2.0.4 版本之后,用户可以通过 `CALL` 命令,对 JDBC 数据源进行 DDL 和 DML 操作。 +在 Doris 2.1.4 版本之后,用户可以通过 `query` 表函数,对 JDBC 数据源进行数据查询操作。 + +### 透传 DDL 和 DML + ``` CALL EXECUTE_STMT("catalog_name", "raw_stmt_string"); ``` @@ -386,6 +391,24 @@ CALL EXECUTE_STMT(jdbc_catalog", "delete from db1.tbl1 where k1 = 2"); CALL EXECUTE_STMT(jdbc_catalog", "create table dbl1.tbl2 (k1 int)"); ``` +### 透传查询 + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +`query` 表函数有两个参数: + +- `catalog`: (必填) catalog名称,需要按照catalog的名称填写。 +- `query`: (必填) 需要执行的查询语句。 + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + #### 原理和限制 通过 `CALL EXECUTE_STMT()` 命令,Doris 会直接将用户编写的 SQL 语句发送给 Catalog 对应的 JDBC 数据源进行执行。因此,这个操作有如下限制: @@ -394,9 +417,11 @@ CALL EXECUTE_STMT(jdbc_catalog", "create table dbl1.tbl2 (k1 int)"); - SQL 语句中引用的表名建议是全限定名,即 `db.tbl` 这种格式。如果未指定 db,则会使用 JDBC Catalog 的 JDBC url 中指定的 db 名称。 - SQL 语句中不可引用 JDBC 数据源之外的库表,也不可以引用 Doris 的库表。但可以引用在 JDBC 数据源内的,但是没有同步到 Doris JDBC Catalog 的库表。 - 执行 DML 语句,无法获取插入、更新或删除的行数,只能获取命令是否执行成功。 -- 只有对 Catalog 有 LOAD 权限的用户,才能执行这个命令。 +- 只有对 Catalog 有 LOAD 权限的用户,才能执行`CALL EXECUTE_STMT()`命令。 +- 只有对 Catalog 有 SELECT 权限的用户,才能执行`query()`表函数。 +- `query` 表函数读取到的的数据,数据类型的支持与所查询的 catalog 类型支持的数据类型一致。 -### 时区 +## 时区 由于某些外部数据源的时间类型是带有时区信息的,而 Doris 的时间类型是不带时区信息的,所以在查询外部数据源的时间类型时,需要注意时区的问题。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/query.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/query.md new file mode 100644 index 0000000000..b48a9cfec5 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/query.md @@ -0,0 +1,110 @@ +--- +{ +"title": "QUERY", +"language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## query + +### Name + +query + +### description + +query 表函数(table-valued-function,tvf),可用于将查询语句直接透传到某个 catalog 进行数据查询 + +:::info note +Doris 2.1.4 版本开始支持,当前仅支持透传查询 jdbc catalog。 +需要先在 Doris 中创建对应的 catalog。 +::: + +#### syntax + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +**参数说明** + +query表函数 tvf中的每一个参数都是一个 `"key"="value"` 对。 +相关参数: +- `catalog`: (必填) catalog名称,需要按照catalog的名称填写。 +- `query`: (必填) 需要执行的查询语句。 + +### Example + +使用 query 函数查询 jdbc 数据源中的表 + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +可以配合`desc function`使用 + +```sql +desc function query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +### Keywords + + query, table-valued-function, tvf + +### Best Prac + +透传查询 jdbc catalog 数据源中的表 + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from test.student"); ++------+---------+ +| id | name | ++------+---------+ +| 1 | alice | +| 2 | bob | +| 3 | jack | ++------+---------+ +select * from query("catalog" = "jdbc", "query" = "select * from test.score"); ++------+---------+ +| id | score | ++------+---------+ +| 1 | 100 | +| 2 | 90 | +| 3 | 80 | ++------+---------+ +``` + +透传关联查询 jdbc catalog 数据源中的表 + +```sql +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"); ++------+---------+---------+ +| id | name | score | ++------+---------+---------+ +| 1 | alice | 100 | +| 2 | bob | 90 | +| 3 | jack | 80 | ++------+---------+---------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/lakehouse/database/jdbc.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/lakehouse/database/jdbc.md index 358da4006e..41fcdcf2f9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/lakehouse/database/jdbc.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/lakehouse/database/jdbc.md @@ -367,8 +367,13 @@ DROP CATALOG <catalog_name>; ### SQL 透传 在 Doris 2.0.3 之前的版本中,用户只能通过 JDBC Catalog 进行查询操作(SELECT)。 + 在 Doris 2.0.4 版本之后,用户可以通过 `CALL` 命令,对 JDBC 数据源进行 DDL 和 DML 操作。 +在 Doris 2.1.4 版本之后,用户可以通过 `query` 表函数,对 JDBC 数据源进行数据查询操作。 + +#### 透传 DDL 和 DML + ``` CALL EXECUTE_STMT("catalog_name", "raw_stmt_string"); ``` @@ -386,6 +391,24 @@ CALL EXECUTE_STMT(jdbc_catalog", "delete from db1.tbl1 where k1 = 2"); CALL EXECUTE_STMT(jdbc_catalog", "create table dbl1.tbl2 (k1 int)"); ``` +#### 透传查询 + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +`query` 表函数有两个参数: + +- `catalog`: (必填) catalog名称,需要按照catalog的名称填写。 +- `query`: (必填) 需要执行的查询语句。 + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + #### 原理和限制 通过 `CALL EXECUTE_STMT()` 命令,Doris 会直接将用户编写的 SQL 语句发送给 Catalog 对应的 JDBC 数据源进行执行。因此,这个操作有如下限制: @@ -394,9 +417,11 @@ CALL EXECUTE_STMT(jdbc_catalog", "create table dbl1.tbl2 (k1 int)"); - SQL 语句中引用的表名建议是全限定名,即 `db.tbl` 这种格式。如果未指定 db,则会使用 JDBC Catalog 的 JDBC url 中指定的 db 名称。 - SQL 语句中不可引用 JDBC 数据源之外的库表,也不可以引用 Doris 的库表。但可以引用在 JDBC 数据源内的,但是没有同步到 Doris JDBC Catalog 的库表。 - 执行 DML 语句,无法获取插入、更新或删除的行数,只能获取命令是否执行成功。 -- 只有对 Catalog 有 LOAD 权限的用户,才能执行这个命令。 +- 只有对 Catalog 有 LOAD 权限的用户,才能执行`CALL EXECUTE_STMT()`命令。 +- 只有对 Catalog 有 SELECT 权限的用户,才能执行`query()`表函数。 +- `query` 表函数读取到的的数据,数据类型的支持与所查询的 catalog 类型支持的数据类型一致。 -### 时区 +## 时区 由于某些外部数据源的时间类型是带有时区信息的,而 Doris 的时间类型是不带时区信息的,所以在查询外部数据源的时间类型时,需要注意时区的问题。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/query.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/query.md new file mode 100644 index 0000000000..b48a9cfec5 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/query.md @@ -0,0 +1,110 @@ +--- +{ +"title": "QUERY", +"language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## query + +### Name + +query + +### description + +query 表函数(table-valued-function,tvf),可用于将查询语句直接透传到某个 catalog 进行数据查询 + +:::info note +Doris 2.1.4 版本开始支持,当前仅支持透传查询 jdbc catalog。 +需要先在 Doris 中创建对应的 catalog。 +::: + +#### syntax + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +**参数说明** + +query表函数 tvf中的每一个参数都是一个 `"key"="value"` 对。 +相关参数: +- `catalog`: (必填) catalog名称,需要按照catalog的名称填写。 +- `query`: (必填) 需要执行的查询语句。 + +### Example + +使用 query 函数查询 jdbc 数据源中的表 + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +可以配合`desc function`使用 + +```sql +desc function query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +### Keywords + + query, table-valued-function, tvf + +### Best Prac + +透传查询 jdbc catalog 数据源中的表 + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from test.student"); ++------+---------+ +| id | name | ++------+---------+ +| 1 | alice | +| 2 | bob | +| 3 | jack | ++------+---------+ +select * from query("catalog" = "jdbc", "query" = "select * from test.score"); ++------+---------+ +| id | score | ++------+---------+ +| 1 | 100 | +| 2 | 90 | +| 3 | 80 | ++------+---------+ +``` + +透传关联查询 jdbc catalog 数据源中的表 + +```sql +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"); ++------+---------+---------+ +| id | name | score | ++------+---------+---------+ +| 1 | alice | 100 | +| 2 | bob | 90 | +| 3 | jack | 80 | ++------+---------+---------+ +``` diff --git a/sidebars.json b/sidebars.json index 2556db625a..6872a2df90 100644 --- a/sidebars.json +++ b/sidebars.json @@ -1028,7 +1028,8 @@ "sql-manual/sql-functions/table-functions/active_queries", "sql-manual/sql-functions/table-functions/jobs", "sql-manual/sql-functions/table-functions/mv_infos", - "sql-manual/sql-functions/table-functions/tasks" + "sql-manual/sql-functions/table-functions/tasks", + "sql-manual/sql-functions/table-functions/query" ] }, { diff --git a/versioned_docs/version-2.1/lakehouse/database/jdbc.md b/versioned_docs/version-2.1/lakehouse/database/jdbc.md index 412e77f28d..73ed381d34 100644 --- a/versioned_docs/version-2.1/lakehouse/database/jdbc.md +++ b/versioned_docs/version-2.1/lakehouse/database/jdbc.md @@ -364,8 +364,13 @@ DROP CATALOG <catalog_name>; ## SQL Passthrough In versions prior to Doris 2.0.3, users could only perform query operations (SELECT) through the JDBC catalog. + Starting from version Doris 2.0.4, users can perform DDL (Data Definition Language) and DML (Data Manipulation Language) operations on JDBC data sources using the `CALL` command. +Starting from version Doris 2.1.4, users can perform data query operations on JDBC data sources through the `query` table function. + +### Passthrough of DDL and DML + ``` CALL EXECUTE_STMT("catalog_name", "raw_stmt_string"); ``` @@ -383,6 +388,24 @@ CALL EXECUTE_STMT("jdbc_catalog", "delete from db1.tbl1 where k1 = 2"); CALL EXECUTE_STMT("jdbc_catalog", "create table db1.tbl2 (k1 int)"); ``` +### Passthrough query + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +The `query` table function takes two parameters: + +- `catalog`: (required) catalog name, which needs to be filled in according to the name of the catalog. +- `query`: (required) The query statement to be executed. + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + ### Principles and Limitations Through the `CALL EXECUTE_STMT()` command, Doris directly sends the SQL statements written by the user to the JDBC data source associated with the catalog for execution. Therefore, this operation has the following limitations: @@ -390,10 +413,11 @@ Through the `CALL EXECUTE_STMT()` command, Doris directly sends the SQL statemen - The SQL statements must be in the syntax specific to the data source, as Doris does not perform syntax and semantic checks. - It is recommended that table names in SQL statements be fully qualified, i.e., in the `db.tbl` format. If the `db` is not specified, the db name specified in the JDBC catalog JDBC URL will be used. - SQL statements cannot reference tables outside of the JDBC data source, nor can they reference Doris's tables. However, they can reference tables within the JDBC data source that have not been synchronized to the Doris JDBC catalog. -- When executing DML statements, it is not possible to obtain the number of rows inserted, updated, or deleted; success of the command execution can only be confirmed. -- Only users with LOAD permissions on the catalog can execute this command. +- Only users with LOAD permissions on the Catalog can execute the `CALL EXECUTE_STMT()` command. +- Only users with SELECT permissions on Catalog can execute the `query()` table function. +- The supported data types of the data read by the `query` table function are consistent with the data types supported by the queried catalog type. -### Time zone +## Time zone Since the time types of some external data sources have time zone information, but the time types of Doris do not have time zone information, you need to pay attention to the time zone issue when querying the time types of external data sources. diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/query.md b/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/query.md new file mode 100644 index 0000000000..1988063339 --- /dev/null +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/query.md @@ -0,0 +1,110 @@ +--- +{ +"title": "QUERY", +"language": "en" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## query + +### Name + +query + +### description + +Query table function (table-valued-function, tvf) can be used to transparently transmit query statements directly to a catalog for data query + +:::info note +Supported by Doris version 2.1.4, currently only transparent query jdbc catalog is supported. +You need to create the corresponding catalog in Doris first. +::: + +#### syntax + +```sql +query( + "catalog" = "catalog_name", + "query" = "select * from db_name.table_name where condition" + ); +``` + +**Parameter Description** + +Each parameter in the query table function tvf is a `"key"="value"` pair. +Related parameters: +- `catalog`: (required) catalog name, which needs to be filled in according to the name of the catalog. +- `query`: (required) The query statement to be executed. + +### Example + +Use the query function to query tables in the jdbc data source + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +Can be used with `desc function` + +```sql +desc function query("catalog" = "jdbc", "query" = "select * from db_name.table_name where condition"); +``` + +### Keywords + + query, table-valued-function, tvf + +### Best Prac + +Transparent query for tables in jdbc catalog data source + +```sql +select * from query("catalog" = "jdbc", "query" = "select * from test.student"); ++------+---------+ +| id | name | ++------+---------+ +| 1 | alice | +| 2 | bob | +| 3 | jack | ++------+---------+ +select * from query("catalog" = "jdbc", "query" = "select * from test.score"); ++------+---------+ +| id | score | ++------+---------+ +| 1 | 100 | +| 2 | 90 | +| 3 | 80 | ++------+---------+ +``` + +Transparent join query for tables in jdbc catalog data source + +```sql +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"); ++------+---------+---------+ +| id | name | score | ++------+---------+---------+ +| 1 | alice | 100 | +| 2 | bob | 90 | +| 3 | jack | 80 | ++------+---------+---------+ +``` diff --git a/versioned_sidebars/version-2.1-sidebars.json b/versioned_sidebars/version-2.1-sidebars.json index 4754b290eb..5684694d03 100644 --- a/versioned_sidebars/version-2.1-sidebars.json +++ b/versioned_sidebars/version-2.1-sidebars.json @@ -1027,7 +1027,8 @@ "sql-manual/sql-functions/table-functions/active_queries", "sql-manual/sql-functions/table-functions/jobs", "sql-manual/sql-functions/table-functions/mv_infos", - "sql-manual/sql-functions/table-functions/tasks" + "sql-manual/sql-functions/table-functions/tasks", + "sql-manual/sql-functions/table-functions/query" ] }, { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org