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

STDIN does not allow to specify the import format. #41

Closed
shakiyam opened this issue Jan 28, 2021 · 7 comments
Closed

STDIN does not allow to specify the import format. #41

shakiyam opened this issue Jan 28, 2021 · 7 comments

Comments

@shakiyam
Copy link

This is an enhancement request.
The documentation says, "The stdin table loads data from pipe or redirection as a csv data."
I would like to specify the import format for standard input.

$ cat sample.tsv  # TSV File
col1    col2
a       b
aaaaaaaaaa      b
$ od -t x1 sample.tsv
0000000 63 6f 6c 31 09 63 6f 6c 32 0a 61 09 62 0a 61 61
0000020 61 61 61 61 61 61 61 61 09 62 0a
0000033
$ csvq -f FIXED 'SELECT * FROM sample'  # The format to be loaded is automatically determined by the file extension
col1       col2
a          b
aaaaaaaaaa b
$ cat sample.tsv | csvq -i TSV -f FIXED 'SELECT * FROM STDIN'  # For STDIN, the -i option is ignored.
col1    col2
a       b
aaaaaaaaaa      b
$ cat sample.tsv | tr "\t" , | csvq -f FIXED 'SELECT * FROM STDIN'  # STDIN is loaded as a csv data
col1       col2
a          b
aaaaaaaaaa b
$
@mithrandie
Copy link
Owner

mithrandie commented Jan 28, 2021

Maybe it’s a bug. The “i” option can be used for other formats.

As a workaround, for tsv format, the “d” option can be used.

cat sample.tsv | csvq -d “\t” “select *”

I’ll check later. Thank you.

@ondohotola
Copy link

ondohotola commented Jan 28, 2021 via email

@shakiyam
Copy link
Author

Thank you for your comment.
It works as expected for Fixed-Length Format and JSON, so I will use the workaround you gave me for TSV.

$ cat sample.txt
col1        col2
a           b
aaaaaaaaaa  b
$ cat sample.txt | csvq -i FIXED -f CSV 'SELECT * FROM STDIN'  # '-i FIXED' works as expected.
col1,col2
a,b
aaaaaaaaaa,b
$ cat sample.json
[
    {
        "col1": "a",
        "col2": "b"
    },
    {
        "col1": "aaaaaaaaaa",
        "col2": "b"
    }
]
$ cat sample.json | csvq -i JSON -f CSV 'SELECT * FROM STDIN'  # '-i JSON ' also works as expected.
col1,col2
a,b
aaaaaaaaaa,b
$ cat sample.tsv | csvq -i TSV -f CSV 'SELECT * FROM STDIN'  # '-i TSV' is ignored.
col1    col2
a       b
aaaaaaaaaa      b
$ cat sample.tsv | csvq -d '\t' -f CSV 'SELECT * FROM STDIN'  # workaround
col1,col2
a,b
aaaaaaaaaa,b

mithrandie added a commit that referenced this issue Jan 31, 2021
- Fix a bug in the --import-format option. ([Github #41](#41))
@mithrandie
Copy link
Owner

This bug has been fixed and the fix is included in the version 1.13.8.

@mithrandie
Copy link
Owner

@ondohotola Sorry, I overlooked that comment. Can you tell me more about what you were concerned about?

@ondohotola
Copy link

ondohotola commented Jan 31, 2021 via email

@mithrandie
Copy link
Owner

@ondohotola
I see, that's a good solution too.
Thanks for your comment.

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