Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Considering the TRUNCATE TABLE statment is useful and widely-used, this FLIP is aimed to support TRUNCATE TABLE  statment in Flink.


Public Interfaces

Briefly list any new interfaces that will be introduced as part of this proposal or any existing interfaces that will be removed or changed. The purpose of this section is to concisely call out the public contract that will come along with this feature.

A public interface is any change to the following:

  • DataStream and DataSet API, including classes related to that, such as StreamExecutionEnvironment
  • Classes marked with the @Public annotation
  • On-disk binary formats, such as checkpoints/savepoints
  • User-facing scripts/command-line tools, i.e. bin/flink, Yarn scripts, Mesos scripts
  • Configuration settings
  • Exposed monitoring information

Proposed Changes

Syntax

We propose add the following syntax for TRUNCATE TABLE statement.

Code Block
languagesql
TRUNCATE TABLE table_name


Public interfaces Changes

We propose add a inerface for TRUNCATE TABLE statment

Code Block
languagejava
/**
 * Enables to delete all existing data in a {@link DynamicTableSink} table using {@code TRUNCATE
 * TABLE} statement.
 *
 * <p>For {@code TRUNCATE TABLE} statement, if the corresponding {@link DynamicTableSink} have
 * implemented this interface, then the method {@link #truncateTable()} will be invoked in execution
 * phase. Otherwise, Flink will throw exception directly.
 */
@PublicEvolving
public interface SupportsTruncate {

    /**
     * Truncate the table by removing all rows.
     *
     * @return true if truncate the table successfully otherwise false
     */
    boolean truncateTable();
}


Proposed Changes

1: Add a parse rule in parserImpls.ftl to match TRUNCATE TABLE  statement and convert it to SqlTruncateTable 

2: Convert  SqlTruncateTable to TruncateTableOperation in SqlToOperationConverter, the TruncateTableOperation will wrap the corresponding DynamicTableSink which implements SupportsTruncate  in SqlToOperationConverter 

3: In method TableEnvironmentImpl#executeInternal , if the operation is  instance of TruncateTableOperation , call method SupportsTruncate#truncateTable  directly to truncate the tableDescribe the new thing you want to do in appropriate detail. This may be fairly extensive and have large subsections of its own. Or it may be a few sentences. Use judgement based on the scope of the change.

Compatibility, Deprecation, and Migration Plan

  • What impact (if any) will there be on existing users? 
  • If we are changing behavior how will we phase out the older behavior? 
  • If we need special migration tools, describe them here.
  • When will we remove the existing behavior?

Test Plan

No any compatibility issue.

Test Plan

It'll be covered by UT & IT.Describe in few sentences how the FLIP will be tested. We are mostly interested in system tests (since unit-tests are specific to implementation details). How will we know that the implementation works as expected? How will we know nothing broke?

Rejected Alternatives

If there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.