Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[Feature] Support REPLACE TABLE operation.#4669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| { | ||
| "title": "Replace Table", | ||
| "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. | ||
| --> | ||
| # Replace Table | ||
| In version 0.14, Doris supports atomic replacement of two tables. | ||
| This operation only applies to OLAP tables. | ||
| For partition level replacement operations, please refer to [Temporary Partition Document](./alter-table-temp-partition.md) | ||
| ## Syntax | ||
| ``` | ||
| ALTER TABLE [db.]tbl1 REPLACE WITH tbl2 | ||
| [PROPERTIES('swap' = 'true')]; | ||
| ``` | ||
| Replace table `tbl1` with table `tbl2`. | ||
| If the `swap` parameter is `true`, after replacement, the data in the table named `tbl1` is the data in the original `tbl2` table. The data in the table named `tbl2` is the data in the original table `tbl1`. That is, the data of the two tables are interchanged. | ||
| If the `swap` parameter is `true`, after replacement, the data in the table named `tbl1` is the data in the original `tbl2` table. The table named `tbl2` is dropped. | ||
| ## Principle | ||
| The replacement table function actually turns the following set of operations into an atomic operation. | ||
| Suppose you want to replace table A with table B, and `swap` is `true`, the operation is as follows: | ||
| 1. Rename table B to table A. | ||
| 2. Rename table A to table B. | ||
| If `swap` is `true`, the operation is as follows: | ||
| 1. Drop table A. | ||
| 2. Rename table B to table A. | ||
| ## Notice | ||
| 1. The `swap` parameter defaults to `true`. That is, the replacement table operation is equivalent to the exchange of two table data. | ||
| 2. If the `swap` parameter is set to `false`, the replaced table (table A) will be dropped and cannot be recovered. | ||
| 3. The replacement operation can only occur between two OLAP tables, and the table structure of the two tables is not checked for consistency. | ||
| 4. The replacement operation will not change the original permission settings. Because the permission check is based on the table name. | ||
| ## Best Practices | ||
| 1. Atomic Overwrite Operation | ||
| In some cases, the user wants to be able to rewrite the data of a certain table, but if it is dropped and then imported, there will be a period of time in which the data cannot be viewed. At this time, the user can first use the `CREATE TABLE LIKE` statement to create a new table with the same structure, import the new data into the new table, and replace the old table atomically through the replacement operation to achieve the goal. For partition level atomic overwrite operation, please refer to [Temporary partition document](./alter-table-temp-partition.md) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| { | ||
| "title": "替换表", | ||
| "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. | ||
| --> | ||
| # 替换表 | ||
| 在 0.14 版本中,Doris 支持对两个表进行原子的替换操作。 | ||
| 该操作仅适用于 OLAP 表。 | ||
| 分区级别的替换操作,请参阅 [临时分区文档](./alter-table-temp-partition.md) | ||
| ## 语法说明 | ||
| ``` | ||
| ALTER TABLE [db.]tbl1 REPLACE WITH tbl2 | ||
| [PROPERTIES('swap' = 'true')]; | ||
| ``` | ||
| 将表 tbl1 替换为表 tbl2。 | ||
| 如果 `swap` 参数为 `true`,则替换后,名称为 `tbl1` 表中的数据为原 `tbl2` 表中的数据。而名称为 `tbl2` 表中的数据为原 `tbl1` 表中的数据。即两张表数据发生了互换。 | ||
| 如果 `swap` 参数为 `true`,则替换后,名称为 `tbl1` 表中的数据为原 `tbl2` 表中的数据。而名称为 `tbl2` 表被删除。 | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be false ? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed | ||
| ## 原理 | ||
| 替换表功能,实际上是将以下操作集合变成一个原子操作。 | ||
| 假设要将表 A 替换为表 B,且 `swap` 为 `true`,则操作如下: | ||
| 1. 将表 B 重名为表 A。 | ||
| 2. 将表 A 重名为表 B。 | ||
| 如果 `swap` 为 `true`,则操作如下: | ||
| 1. 删除表 A。 | ||
| 2. 将表 B 重名为表 A。 | ||
| ## 注意事项 | ||
| 1. `swap` 参数默认为 `true`。即替换表操作相当于将两张表数据进行交换。 | ||
| 2. 如果设置 `swap` 参数为 `false`,则被替换的表(表A)将被删除,且无法恢复。 | ||
| 3. 替换操作仅能发生在两张 OLAP 表之间,且不会检查两张表的表结构是否一致。 | ||
| 4. 替换操作不会改变原有的权限设置。因为权限检查以表名称为准。 | ||
| ## 最佳实践 | ||
| 1. 原子的覆盖写操作 | ||
| 某些情况下,用户希望能够重写某张表的数据,但如果采用先删除再导入的方式进行,在中间会有一段时间无法查看数据。这时,用户可以先使用 `CREATE TABLE LIKE` 语句创建一个相同结构的新表,将新的数据导入到新表后,通过替换操作,原子的替换旧表,以达到目的。分区级别的原子覆盖写操作,请参阅 [临时分区文档](./alter-table-temp-partition.md) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed