Versions Compared

Key

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

This page is meant as a template for writing a FLIP. To create a FLIP choose Tools->Copy on this page and modify with your content and replace the heading with the next FLIP number and a description of your issue. Replace anything in italics with your own description.

Status

Current state[One of "Under Discussion", "Accepted", "Rejected"]

...

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

Often users need to adjust Describe the problems you are trying to solve.

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.

...

  • Binary log format

  • The network protocol and api behavior

  • Any class in the public packages under clientsConfiguration, especially client configuration

    • org/apache/kafka/common/serialization

    • org/apache/kafka/common

    • org/apache/kafka/common/errors

    • org/apache/kafka/clients/producer

    • org/apache/kafka/clients/consumer (eventually, once stable)

  • Monitoring

  • Command line tools and arguments

  • Anything else that will likely break existing users in some way when they upgrade

Proposed Changes

I suggest introducing a LIKE clause with a following syntax:

Code Block
languagesql
CREATE [ TEMPORARY ] TABLE [ IF NOT EXISTS ] table_name ( [
  {   column
    | table_constraint
    | LIKE parent_table [ like_options ] }
    [, ... ]
] )

where like_options are:

  { INCLUDING | EXCLUDING } ALL
| [{ 
     { INCLUDING | EXCLUDING } { CONSTRAINTS }
   | { INCLUDING | EXCLUDING | OVERWRITING } { GENERATED | OPTIONS } }
   [, ...]
  ]


Example:

Code Block
languagesql
CREATE [TEMPORARY] TABLE base_table (
    id BIGINT,
    name STRING,
    tstmp TIMESTAMP,
	PRIMARY KEY(id)
) WITH (
    ‘connector.type’: ‘kafka’
)

CREATE [TEMPORARY] TABLE derived_table (
    LIKE base_table,
    WATERMARK FOR tstmp AS tsmp - INTERVAL '5' SECOND
)

...

Additionally I suggest supporting different INCLUDING/EXCLUDING strategies:

For the 

  • INCLUDING OPTIONS (default -> fail on duplicate keys)
  • EXCLUDING OPTIONS
  • OVERWRITING OPTIONS (any explicit options/columns overwrite options/columns from base source, overwriting happens in the order the LIKE clauses were declared)

The supported combinations would be:


INCLUDINGEXCLUDINGOVERWRITING
ALL(tick)(tick)(error)
CONSTRAINTS(tick)(tick)(error)
GENERATED(tick)(tick)(tick)
OPTIONS(tick)(tick)(tick)

The reason why I suggest not to support OVERWRITING CONSTRAINTS is that usually it's rather hard to overwrite only some of the constraints. If the constraint(primary key, unique key) from the base table does not apply to the derived table, in my opinion it is safer to exclude all constraints and redefine them.  We could revisit that in the future, if we see a need to support also OVERWRITING for constraints.

Default options:

    INCLUDING ALL = INCLUDING CONSTRAINTS

                                                   INCLUDING GENERATED

                                       INCLUDING OPTIONS

It is different from the SQL standard. Nevertheless I think it is worth the change as the primary use case for the clause will be slight adjustments to the original schema rather than rewriting the table completely.

...

Code Block
languagesql
CREATE [TEMPORARY] TABLE base_table_1 (
    id BIGINT,
    name STRING,
	PRIMARY KEY(id)
) WITH (
    ‘connector’: ‘kafka’,
    ‘connector.starting-offset’: ‘12345’,
    ‘format’: ‘json’
)

CREATE [TEMPORARY] TABLE base_table_2 (
    tstmp TIMESTAMP,
	PRIMARY KEY(tstmp)
) WITH (
    ‘connector’: ‘filesystem’,
    ‘format’: ‘csv’,
    ‘format.delimiter’: ‘\t’   
)

CREATE [TEMPORARY] TABLE derived_table (
    LIKE base_table_1 (
		OVERWRITING SOURCE_OPTIONS),
    LIKE base_table_2 (
		EXCLUDING SOURCE_OPTIONS, 
		EXCLUDING CONSTRAINTS),
    WATERMARK FOR tstmp AS tsmp - INTERVAL '5' SECOND
) WITH (
    ‘connector.starting-offset’: ‘0’
)

The derived_table will be equivalent to:

Code Block
languagesql
CREATE [TEMPORARY] TABLE derived_table (
    id BIGINT,
    name STRING,
	tstmp TIMESTAMP,
    WATERMARK FOR tstmp AS tsmp - INTERVAL '5' SECOND,
    PRIMARY KEY(id)
) WITH (
    ‘connector’: ‘kafka’,
    ‘connector.starting-offset’: ‘0’,
    ‘format’: ‘json’
)

...