Skip to content
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

CTAS doesn't set KEY metadata correctly if key column from left-side of join not included in SELECT #2365

Closed
rmoff opened this issue Jan 17, 2019 · 1 comment
Labels
bug join-functions Issues involving joins

Comments

@rmoff
Copy link
Contributor

rmoff commented Jan 17, 2019

Create a table (two versions; one retaining existing VALUE_FORMAT of JSON, one changing to Avro) by joining two existing tables:

CREATE TABLE employee_t \
            (key       VARCHAR, \
            name       VARCHAR, \
            watch_flag VARCHAR) \
      WITH (KAFKA_TOPIC ='employees', \
            VALUE_FORMAT ='JSON', \
            KEY='key');

CREATE TABLE computer_t \
            (comp_id INT, \
            empkey   VARCHAR, \
            macaddr  VARCHAR) \
      WITH (KAFKA_TOPIC='computers', \
            VALUE_FORMAT='JSON', \
            KEY='empkey');

CREATE TABLE include_right_key AS \
SELECT e.key     AS EMP_ID,   \
             e.NAME    AS EMP_NAME, \
             e.key     AS EMP_KEY,  \
             c.macaddr AS MACADDR   \
      FROM computer_t c \
            INNER JOIN employee_t e \
            ON c.empkey = e.key ;

CREATE TABLE include_left_key AS \
SELECT c.empkey     AS EMP_ID,   \
             e.NAME    AS EMP_NAME, \
             e.key     AS EMP_KEY,  \
             c.macaddr AS MACADDR   \
      FROM computer_t c \
            INNER JOIN employee_t e \
            ON c.empkey = e.key ;

Inspect the key on the two source tables:

ksql> DESCRIBE EXTENDED COMPUTER_T;

Name                 : COMPUTER_T
Type                 : TABLE
Key field            : EMPKEY
[...]

ksql> DESCRIBE EXTENDED EMPLOYEE_T;

Name                 : EMPLOYEE_T
Type                 : TABLE
Key field            : KEY
[...]

Inspect the key on the created table.

  • Works, if the join key column from the left-side of the join is included:

    ksql> DESCRIBE EXTENDED include_left_key;
    
    Name                 : INCLUDE_LEFT_KEY
    Type                 : TABLE
    Key field            : EMP_ID
    [...]
    
  • Key not present, if only the join key column from the right-side of the join is included:

    ksql> DESCRIBE EXTENDED include_right_key;
    
    Name                 : INCLUDE_RIGHT_KEY
    Type                 : TABLE
    Key field            :
    [...]
    
@rmoff rmoff added bug join-functions Issues involving joins labels Jan 17, 2019
@big-andy-coates
Copy link
Contributor

Closing as a duplicate of #2741

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug join-functions Issues involving joins
Projects
None yet
Development

No branches or pull requests

2 participants