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

Can't force "q" to interpret the file as single-row table #69

Closed
vi opened this issue Oct 26, 2014 · 6 comments
Closed

Can't force "q" to interpret the file as single-row table #69

vi opened this issue Oct 26, 2014 · 6 comments

Comments

@vi
Copy link

vi commented Oct 26, 2014

Scenario:

q -d'' --mode=strict -c 1 'SELECT * FROM a LIMIT 1,1'

Expected:

The first line of the file, possibly trimmed unless -k

Actual:

Delimiter must be one character only

@bitti
Copy link

bitti commented Oct 26, 2014

That doesn't seem to be unusual for a unix tool. Why not use -d$'\n'if you want to make sure that the whole line is used as a column? The only thing is that there is no option to suppress the resulting Warning: column count is one - did you provide the correct delimiter? but even that can be achieved with a 2>/dev/null redirection.

@harelba
Copy link
Owner

harelba commented Oct 26, 2014

Actually, relaxed mode, which is the default mode, is more suitable for this use case.

In relaxed mode, if you provide a column count using -c, then any remaining data after the last column becomes part of the last column.

So to do it you just need to run q with -c 1. See the example below:

harel@harel-laptop2:~/dev/github/q/bin$ cat one-liner-file 
a b c d e f g h i j k l m n
harel@harel-laptop2:~/dev/github/q/bin$ q -c 1 "select c1 from one-liner-file" 
Warning: column count is one - did you provide the correct delimiter?
a b c d e f g h i j k l m n
harel@harel-laptop2:~/dev/github/q/bin$ 

Just for completeness - Using strict mode will actually show an error if the column count is not identical to the column count provided/detected.

As for the warning message - Warnings/errors are always printed to stderr, allowing 2>/dev/null as is the standard in many linux tools. Maybe I'll add some quiet mode in the future, but this is low priority.

Harel

@vi
Copy link
Author

vi commented Oct 26, 2014

I think Warning: column count is one - did you provide the correct delimiter? should not be shown if user explicitly specifies -c1.

@harelba
Copy link
Owner

harelba commented Oct 26, 2014

Definitely true @vi. I'll fix.

@harelba
Copy link
Owner

harelba commented Oct 26, 2014

Added warning suppression when the user provides a specific column count of 1 to the master branch.

Will be released as part of the coming 1.5.0 version.

Harel

@harelba
Copy link
Owner

harelba commented Dec 13, 2014

Warning suppression when providing a specific column count is part of the newly released 1.5.0 version.

Providing a -c 1 -m relaxed (-m relaxed is the default behavior) would treat the entire row as one column. If you really like to eliminate the output delimiter, you can do that through the SQL itself.

Here is an example for comma separated lines:

q -d ',' "select replace(c1,',','') from myfile" -c 1

In order to eliminate tab separated lines, you need to use the more elaborate sqlite syntax for writing a tab (X'09' needs to be used in order to signify a tab literal):

q -t "select replace(c1,X'09','') from -" -c 1

@harelba harelba closed this as completed Dec 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants