luoyuxia commented on code in PR #23046: URL: https://github.com/apache/flink/pull/23046#discussion_r1283069159
########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} Review Comment: nit: ```suggestion <span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only is supported in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} ``` ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. Review Comment: ```suggestion interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` a table which has not implemented the related interface. ``` ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); Review Comment: ```suggestion tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await() ``` ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Python" >}} +```python +env_settings = EnvironmentSettings.in_batch_mode() +table_env = TableEnvironment.create(env_settings) + +# register a table named "Orders" +table_env.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +# insert values +table_env.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").wait(); +table_env.executeSql("SELECT * FROM Orders").print(); +# +--------------------------------+--------------------------------+-------------+ +# | user | product | amount | +# +--------------------------------+--------------------------------+-------------+ +# | Lili | Apple | 1 | +# | Jessica | Banana | 2 | +# | Mr.White | Chicken | 3 | +# +--------------------------------+--------------------------------+-------------+ +# 3 rows in set +# truncate the table "Orders" +table_env.executeSql("TRUNCATE TABLE Orders").wait(); Review Comment: dito ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Python" >}} +```python +env_settings = EnvironmentSettings.in_batch_mode() +table_env = TableEnvironment.create(env_settings) + +# register a table named "Orders" +table_env.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +# insert values +table_env.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").wait(); +table_env.executeSql("SELECT * FROM Orders").print(); +# +--------------------------------+--------------------------------+-------------+ +# | user | product | amount | +# +--------------------------------+--------------------------------+-------------+ +# | Lili | Apple | 1 | +# | Jessica | Banana | 2 | +# | Mr.White | Chicken | 3 | +# +--------------------------------+--------------------------------+-------------+ +# 3 rows in set +# truncate the table "Orders" +table_env.executeSql("TRUNCATE TABLE Orders").wait(); +table_env.executeSql("SELECT * FROM Orders").print(); Review Comment: dito ########## docs/content.zh/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,181 @@ +--- +title: "TRUNCATE 语句" +weight: 8 +type: docs +aliases: +- /zh/dev/table/sql/truncate.html +--- +<!-- +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. +--> + +<a name="truncate-statements"></a> + +# TRUNCATE 语句 + +TRUNCATE 语句用于删除表中的全部数据,但不会删除表本身。 + +<span class="label label-danger">注意</span> 目前, `TRUNCATE` 语句仅支持批模式, 并且要求目标表实现了 {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} 接口。 +如果在一个没有实现该接口的表上执行 `TRUNCATE`,则会抛异常。 Review Comment: ```suggestion 如果在一个没有实现该接口的表上执行 `TRUNCATE` 语句,则会抛异常。 ``` ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); Review Comment: dito ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Python" >}} +```python +env_settings = EnvironmentSettings.in_batch_mode() +table_env = TableEnvironment.create(env_settings) + +# register a table named "Orders" +table_env.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +# insert values +table_env.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").wait(); +table_env.executeSql("SELECT * FROM Orders").print(); Review Comment: dito ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); Review Comment: dito ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Python" >}} +```python +env_settings = EnvironmentSettings.in_batch_mode() +table_env = TableEnvironment.create(env_settings) + +# register a table named "Orders" +table_env.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); Review Comment: ```suggestion table_env.execute_sql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)") ``` ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); Review Comment: ```suggestion tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)") ``` ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Python" >}} +```python +env_settings = EnvironmentSettings.in_batch_mode() +table_env = TableEnvironment.create(env_settings) + +# register a table named "Orders" +table_env.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +# insert values +table_env.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").wait(); Review Comment: dito ########## docs/content/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,175 @@ +--- +title: "TRUNCATE Statements" +weight: 8 +type: docs +aliases: +- /dev/table/sql/truncate.html +--- +<!-- +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. +--> + +# TRUNCATE Statements + +TRUNCATE statements are used to delete all rows from a table without dropping the table itself. + +<span class="label label-danger">Attention</span> Currently, `TRUNCATE` statement only supports in batch mode, and it requires the target table connector implements the {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} +interface to support the row-level delete. An exception will be thrown if trying to `TRUNCATE` the table which has not implements the related interface. + + +## Run a TRUNCATE statement + +{{< tabs "truncate" >}} +{{< tab "Java" >}} +TRUNCATE statement can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` method will throw an exception when there is any error for the operation. + +The following examples show how to run a TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Scala" >}} + +TRUNCATE statements can be executed with the `executeSql()` method of the `TableEnvironment`. The `executeSql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. +{{< /tab >}} +{{< tab "Python" >}} + +TRUNCATE statements can be executed with the `execute_sql()` method of the `TableEnvironment`. The `execute_sql()` will throw an exception when there is any error for the operation. + +The following examples show how to run a single TRUNCATE statement in `TableEnvironment`. + +{{< /tab >}} +{{< tab "SQL CLI" >}} + +TRUNCATE statement can be executed in [SQL CLI]({{< ref "docs/dev/table/sqlClient" >}}). + +The following examples show how to run a TRUNCATE statement in SQL CLI. + +{{< /tab >}} +{{< /tabs >}} + +{{< tabs "a5de1760-e363-4b8d-9d6f-0bacb35b9dcf" >}} +{{< tab "Java" >}} +```java +EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); +TableEnvironment tEnv = TableEnvironment.create(settings); + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); + +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set + +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// Empty set +``` +{{< /tab >}} +{{< tab "Scala" >}} +```scala +val env = StreamExecutionEnvironment.getExecutionEnvironment() +val settings = EnvironmentSettings.newInstance().inBatchMode().build() +val tEnv = StreamTableEnvironment.create(env, settings) + +// register a table named "Orders" +tEnv.executeSql("CREATE TABLE Orders (`user` STRING, product STRING, amount INT) WITH (...)"); +// insert values +tEnv.executeSql("INSERT INTO Orders VALUES ('Lili', 'Apple', 1), ('Jessica', 'Banana', 2), ('Mr.White', 'Chicken', 3)").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); +// +--------------------------------+--------------------------------+-------------+ +// | user | product | amount | +// +--------------------------------+--------------------------------+-------------+ +// | Lili | Apple | 1 | +// | Jessica | Banana | 2 | +// | Mr.White | Chicken | 3 | +// +--------------------------------+--------------------------------+-------------+ +// 3 rows in set +// truncate the table "Orders" +tEnv.executeSql("TRUNCATE TABLE Orders").await(); +tEnv.executeSql("SELECT * FROM Orders").print(); Review Comment: dito ########## docs/content.zh/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,181 @@ +--- +title: "TRUNCATE 语句" +weight: 8 +type: docs +aliases: +- /zh/dev/table/sql/truncate.html +--- +<!-- +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. +--> + +<a name="truncate-statements"></a> + +# TRUNCATE 语句 Review Comment: The comments in en doc is also suitable for the zh doc. ########## docs/content.zh/docs/dev/table/sql/truncate.md: ########## @@ -0,0 +1,181 @@ +--- +title: "TRUNCATE 语句" +weight: 8 +type: docs +aliases: +- /zh/dev/table/sql/truncate.html +--- +<!-- +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. +--> + +<a name="truncate-statements"></a> + +# TRUNCATE 语句 + +TRUNCATE 语句用于删除表中的全部数据,但不会删除表本身。 + +<span class="label label-danger">注意</span> 目前, `TRUNCATE` 语句仅支持批模式, 并且要求目标表实现了 {{< gh_link file="flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/sink/abilities/SupportsTruncate.java" name="SupportsTruncate" >}} 接口。 +如果在一个没有实现该接口的表上执行 `TRUNCATE`,则会抛异常。 Review Comment: ```suggestion 如果在一个没有实现该接口的表上执行 `TRUNCATE` 语句,则会抛异常。 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
