question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling column names directly?

See original GitHub issue

Typically, a csv file will have a header row (e.g. carat,cut,color,clarity,depth,table,price,x,y,z for the diamonds data set from ggplot2).

Is there a chance of adding an option to perform RBQL queries directly with the columns (e.g. carat) instead of having to reference them by their index (e.g. a1)?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mechatronercommented, Nov 8, 2019

So, I wrote the code to support a.good_alphanumeric_column_name and a["arbitrary column name!"] notation, it’s available in the master branch. Took me almost 150 commits [sigh] Soon I will start deploying it to the apps. And I would really appreciated any feedback, guys! Please, let me know what you think.

PS I rewrote JS implementation: replaced all callbacks with async/await so it should be much easier to read now.

1reaction
mechatronercommented, Jun 30, 2019

Yep, I think that a.name, a.age, b.name, etc notations are the way to go. But there is no need to do replaceAll, because it is unreliable even with “a.” and “b.” prefixes. Original user query should be altered as little as possible. One case where it will definetely fail are string literals: should we replace a.name inside string literals? In case of SQL keywords (“SELECT”, “WHERE”, etc) the answer is no, and RBQL isolates string literals before it starts searching for the keywords. But in case of a.name the answer is not so obvious. Here is an absolutely artificial and contrived example, but it will fail with replaceAll:

SELECT `a.name = ${a.name}`

The output would be a1 = Andy instead of a.name = Andy. I agree that such situation would probably never happen in practice, but my general position still holds: original query should be altered as little as possible. This is also important for exceptions/errors that contain failed query expression, if the query was significantly altered it wouldn’t be recognizable by the user, and it would be harder to correct that error.

So to implement this “a.name” etc notations I suggest to initialize special “a” and “b” objects (if either “a.” or “b.” were detected somewhere in the query). This should be relatively easy to do - almost the same code that currently initializes a1, a2, b1 etc variables. “a” and “b” can also support square bracket access like a[“person name”]. Those who think that this is super ugly and non-SQLish can pretend that this feature doesn’t exist and only columns without whitespaces/special characters are supported. I don’t have 100% guarantee that this approach would work, but I currently don’t see why it wouldn’t, and the only way to be sure is to try and implement this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write SQL queries with spaces in column names
In SQL Server, we can specify the column name with space in square bracket or parenthesis. Let us understand the concept with some...
Read more >
data.table: why is it not always possible to pass column names ...
Being able to pass column names directly is an attractive feature of data.table. But dispensing with quotes around a column name, ...
Read more >
Strategies for Handling Long Column Names
If you have source tables with long column names, alternative strategies are available for handling the long column names so that the corresponding...
Read more >
Managing changing column names in Power Query #10
In today's video, I will show how to manage column headers that changes names so your power bi file does not break when...
Read more >
How to search for column names in SQL Server - Solution center
There are many solutions on the internet for this and most of the suggestions are different scripts joining sys.table with sys.columns that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found