cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: automatic way to ensure new sql keyword is added to `bare_label_keywords` list

Open chengxiong-ruan opened this issue 3 years ago • 3 comments

Describe the solution you'd like Adding new keyword could break user queries which use column labels without AS. We added the bare_label_keywords list to allow those keywords to be used as column labels. However, it's easy to forget to add the keyword. We need to an automatic way to validate all newly added keywords are added to this list.

We could auto generate code to validate that, for example we're already doing similar thing when generating this list. The hard part could be how do we know a keyword is newly added? One alternative is to add all keywords (including existing ones) to this list, and the automatic check just need to make sure all keywords are added.

Jira issue: CRDB-17582

chengxiong-ruan avatar Jul 12 '22 19:07 chengxiong-ruan

I don't know which project I should add to this issue...so I just attached my team.

chengxiong-ruan avatar Jul 12 '22 19:07 chengxiong-ruan

Thanks for the issue. What's the impact of forgetting to add the keyword to bare_label_keywords?

rafiss avatar Jul 26 '22 22:07 rafiss

@rafiss adding new keyword without adding to bare_label_keywords could break user query if the query use column label without AS. Before bare_label_keyword was added, any new keyword could break user queries because it was expecting an IDENT token, but if you used a keyword as the column label, the parser would fail to get an IDENT and error out :( I think it could be quite rare... but I encountered one case when I was adding the new keyword INPUT which broke this test.

chengxiong-ruan avatar Jul 27 '22 03:07 chengxiong-ruan

Maybe some kind of test that automatically tries to parse SELECT 1 <keyword> with every (unreserved) keyword would suffice?

michae2 avatar Feb 09 '23 23:02 michae2