[feature](http) get create table stmt for a given query (#11979)

This API can help user to get all create table statement of a given SQL.
So that it will be easier to run the case in other Doris cluster.
See document for details
This commit is contained in:
Mingyu Chen
2022-08-25 15:02:05 +08:00
committed by GitHub
parent 003fdf2b36
commit aec24d4da1
15 changed files with 446 additions and 98 deletions

View File

@ -0,0 +1,108 @@
---
{
"title": "Query Schema Action",
"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 Schema Action
## Request
```
POST /api/query_schema/<ns_name>/<db_name>
```
## Description
The Query Schema Action can return the table creation statement for the given SQL-related table. Can be used to test some query scenarios locally.
The API was released in version 1.2.
## Path parameters
* `<db_name>`
Specify the database name. This database will be considered as the default database for the current session, and will be used if the table name in SQL does not qualify the database name.
## Query parameters
None
## Request body
```
text/plain
sql
```
* "sql" field is the SQL string.
## Response
* Return value
```
CREATE TABLE `tbl1` (
`k1` int(11) NULL,
`k2` int(11) NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"disable_auto_compaction" = "false"
);
CREATE TABLE `tbl2` (
`k1` int(11) NULL,
`k2` int(11) NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"disable_auto_compaction" = "false"
);
```
## Example
1. Write the SQL in local file 1.sql
```
select tbl1.k2 from tbl1 join tbl2 on tbl1.k1 = tbl2.k1;
```
2. Use curl to get the table creation statement.
```
curl -X POST -H 'Content-Type: text/plain' -uroot: http://127.0.0.1:8030/api/query_schema/internal/db1 -d@1.sql
```

View File

@ -939,7 +939,8 @@
"admin-manual/http-actions/fe/show-proc-action",
"admin-manual/http-actions/fe/check-decommission-action",
"admin-manual/http-actions/fe/health-action",
"admin-manual/http-actions/fe/check-storage-type-action"
"admin-manual/http-actions/fe/check-storage-type-action",
"admin-manual/http-actions/fe/query-schema-action"
]
},
"admin-manual/http-actions/restore-tablet",

View File

@ -0,0 +1,107 @@
---
{
"title": "Query Schema Action",
"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 Schema Action
## Request
```
POST /api/query_schema/<ns_name>/<db_name>
```
## Description
Query Schema Action 可以返回给定的 SQL 有关的表的建表语句。可以用于本地测试一些查询场景。
该 API 在 1.2 版本中发布。
## Path parameters
* `<db_name>`
指定数据库名称。该数据库会被视为当前session的默认数据库,如果在 SQL 中的表名没有限定数据库名称的话,则使用该数据库。
## Query parameters
## Request body
```
text/plain
sql
```
* sql 字段为具体的 SQL
## Response
* 返回结果集
```
CREATE TABLE `tbl1` (
`k1` int(11) NULL,
`k2` int(11) NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"disable_auto_compaction" = "false"
);
CREATE TABLE `tbl2` (
`k1` int(11) NULL,
`k2` int(11) NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"disable_auto_compaction" = "false"
);
```
## Example
1. 在本地文件 1.sql 中写入 SQL
```
select tbl1.k2 from tbl1 join tbl2 on tbl1.k1 = tbl2.k1;
```
2. 使用 curl 命令获取建表语句
```
curl -X POST -H 'Content-Type: text/plain' -uroot: http://127.0.0.1:8030/api/query_schema/internal/db1 -d@1.sql
```