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

Document how to use quoted column names and column aliases #1212

Closed
big-andy-coates opened this issue Apr 26, 2018 · 5 comments
Closed

Document how to use quoted column names and column aliases #1212

big-andy-coates opened this issue Apr 26, 2018 · 5 comments

Comments

@big-andy-coates
Copy link
Contributor

big-andy-coates commented Apr 26, 2018

Users may have data where field names contain reserved words, e.g. group. Currently, there is no documentation on how to work with this data with KSQL. Statements such as CREATE STREAM foo (field1 varchar, group varchar ) WITH (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON'); fail with an error due to the group column.

I think the work around is to use the backtick character to escape the keyword:

CREATE STREAM foo (field1 varchar, `group` column) WITH (Blah)

And then the user will need to also escape the column name where ever used, e.g.

SELECT `group` FROM foo LIMIT 5;

However, there is no documentation around column aliasing and how to use with keywords. We should fix this.

@big-andy-coates
Copy link
Contributor Author

Looking at #1212, there may be bugs in this area!

@big-andy-coates big-andy-coates changed the title Document how to use data that contains field names that are reserved words. Document how to use column aliases Apr 26, 2018
@big-andy-coates big-andy-coates changed the title Document how to use column aliases Document how to use quoted column names and column aliases Apr 27, 2018
@rmoff
Copy link
Contributor

rmoff commented Jun 18, 2018

Same issue here, for properties: https://stackoverflow.com/questions/50906566/cannot-create-stream-with-ksql/50907284#50907284

ksql> CREATE STREAM fakeData22 (Id VARCHAR, category VARCHAR, timeStamp VARCHAR, deviceID INTEGER, properties MAP<VARCHAR, VARCHAR>) WITH (KAFKA_TOPIC='fake-data-19', VALUE_FORMAT='JSON');

line 1:94: extraneous input 'properties' expecting {'ADD', 'APPROXIMATE', 'AT', 'CONFIDENCE', 'NO', 'SUBSTRING', 'POSITION', 'TINYINT', 'SMALLINT', 'INTEGER', 'DATE', 'TIME', 'TIMESTAMP', 'INTERVAL', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'ZONE', 'OVER', 'PARTITION', 'RANGE', 'ROWS', 'PRECEDING', 'FOLLOWING', 'CURRENT', 'ROW', 'VIEW', 'REPLACE', 'GRANT', 'REVOKE', 'PRIVILEGES', 'PUBLIC', 'OPTION', 'EXPLAIN', 'ANALYZE', 'FORMAT', 'TYPE', 'TEXT', 'GRAPHVIZ', 'LOGICAL', 'DISTRIBUTED', 'TRY', 'SHOW', 'TABLES', 'SCHEMAS', 'CATALOGS', 'COLUMNS', 'COLUMN', 'USE', 'PARTITIONS', 'FUNCTIONS', 'TO', 'SYSTEM', 'BERNOULLI', 'POISSONIZED', 'TABLESAMPLE', 'RESCALED', 'ARRAY', 'MAP', 'SET', 'RESET', 'SESSION', 'DATA', 'START', 'TRANSACTION', 'COMMIT', 'ROLLBACK', 'WORK', 'ISOLATION', 'LEVEL', 'SERIALIZABLE', 'REPEATABLE', 'COMMITTED', 'UNCOMMITTED', 'READ', 'WRITE', 'ONLY', 'CALL', 'NFD', 'NFC', 'NFKD', 'NFKC', 'IF', 'NULLIF', 'COALESCE', IDENTIFIER, DIGIT_IDENTIFIER, QUOTED_IDENTIFIER, BACKQUOTED_IDENTIFIER}
Caused by: line 1:94: extraneous input 'properties' expecting {'ADD', 'APPROXIMATE', 'AT', 'CONFIDENCE', 'NO', 'SUBSTRING', 'POSITION', 'TINYINT', 'SMALLINT', 'INTEGER', 'DATE', 'TIME', 'TIMESTAMP', 'INTERVAL', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'ZONE', 'OVER', 'PARTITION', 'RANGE', 'ROWS', 'PRECEDING', 'FOLLOWING', 'CURRENT', 'ROW', 'VIEW', 'REPLACE', 'GRANT', 'REVOKE', 'PRIVILEGES', 'PUBLIC', 'OPTION', 'EXPLAIN', 'ANALYZE', 'FORMAT', 'TYPE', 'TEXT', 'GRAPHVIZ', 'LOGICAL', 'DISTRIBUTED', 'TRY', 'SHOW', 'TABLES', 'SCHEMAS', 'CATALOGS', 'COLUMNS', 'COLUMN', 'USE', 'PARTITIONS', 'FUNCTIONS', 'TO', 'SYSTEM', 'BERNOULLI', 'POISSONIZED', 'TABLESAMPLE', 'RESCALED', 'ARRAY', 'MAP', 'SET', 'RESET', 'SESSION', 'DATA', 'START', 'TRANSACTION', 'COMMIT', 'ROLLBACK', 'WORK', 'ISOLATION', 'LEVEL', 'SERIALIZABLE', 'REPEATABLE', 'COMMITTED', 'UNCOMMITTED', 'READ', 'WRITE', 'ONLY', 'CALL', 'NFD', 'NFC', 'NFKD', 'NFKC', 'IF', 'NULLIF', 'COALESCE', IDENTIFIER, DIGIT_IDENTIFIER, QUOTED_IDENTIFIER, BACKQUOTED_IDENTIFIER}

@rmoff
Copy link
Contributor

rmoff commented Jun 21, 2018

The backtick approach doesn't work for me - whilst KSQL accepts the CREATE STREAM statement, it doesn't actually pick up the desired column.

ksql> print 'reserved_test2' from beginning;
Format:JSON
{"ROWTIME":1529579689725,"ROWKEY":"null","group":"foo","properties":"bar"}
{"ROWTIME":1529579853969,"ROWKEY":"null","group":"foo","groupfoo":"bar"}
^CTopic printing ceased
ksql> CREATE STREAM reservedtest20 ("group" VARCHAR, groupfoo VARCHAR, "groupfoo" varchar) WITH (KAFKA_TOPIC='reserved_test2', VALUE_FORMAT='JSON');

 Message
----------------
 Stream created
----------------
ksql> SELECT * FROM reservedtest20;
1529579689725 | null | null | null | null
1529579853969 | null | null | bar | null
^CQuery terminated
ksql> CREATE STREAM reservedtest201 (GROUP VARCHAR, "group" VARCHAR, groupfoo VARCHAR, "groupfoo" varchar) WITH (KAFKA_TOPIC='reserved_test2', VALUE_FORMAT='JSON');
line 1:32: extraneous input 'GROUP' expecting {'ADD', 'APPROXIMATE', 'AT', 'CONFIDENCE', 'NO', 'SUBSTRING', 'POSITION', 'TINYINT', 'SMALLINT', 'INTEGER', 'DATE', 'TIME', 'TIMESTAMP', 'INTERVAL', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'ZONE', 'OVER', 'PARTITION', 'RANGE', 'ROWS', 'PRECEDING', 'FOLLOWING', 'CURRENT', 'ROW', 'STRUCT', 'VIEW', 'REPLACE', 'GRANT', 'REVOKE', 'PRIVILEGES', 'PUBLIC', 'OPTION', 'EXPLAIN', 'ANALYZE', 'FORMAT', 'TYPE', 'TEXT', 'GRAPHVIZ', 'LOGICAL', 'DISTRIBUTED', 'TRY', 'SHOW', 'TABLES', 'SCHEMAS', 'CATALOGS', 'COLUMNS', 'COLUMN', 'USE', 'PARTITIONS', 'FUNCTIONS', 'TO', 'SYSTEM', 'BERNOULLI', 'POISSONIZED', 'TABLESAMPLE', 'RESCALED', 'ARRAY', 'MAP', 'SET', 'RESET', 'SESSION', 'DATA', 'START', 'TRANSACTION', 'COMMIT', 'ROLLBACK', 'WORK', 'ISOLATION', 'LEVEL', 'SERIALIZABLE', 'REPEATABLE', 'COMMITTED', 'UNCOMMITTED', 'READ', 'WRITE', 'ONLY', 'CALL', 'NFD', 'NFC', 'NFKD', 'NFKC', 'IF', 'NULLIF', 'COALESCE', IDENTIFIER, DIGIT_IDENTIFIER, QUOTED_IDENTIFIER, BACKQUOTED_IDENTIFIER}
ksql>

@rmoff
Copy link
Contributor

rmoff commented Jun 21, 2018

Related : #677

@rmoff
Copy link
Contributor

rmoff commented Jun 21, 2018

Closing as there's nothing to document yet, until #677 is fixed

@rmoff rmoff closed this as completed Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants