Skip to content

fix: Renames from_csv to from_text (#286) - #1514

Merged
aljazerzen merged 1 commit into
PRQL:mainfrom
snth:from_text
Jan 19, 2023
Merged

aljazerzen merged 1 commit into
PRQL:mainfrom
snth:from_text

Conversation

@snth

@snth snth commented Jan 15, 2023

Copy link
Copy Markdown
Member

I'd like to add a format parameter as well but that can probably come later.

This should probably also get a mention in the docs and the changelog. I could take a stab at those in maybe 9 hours time.

I also haven't run any tests as my env is not set up. Will making this a PR automatically trigger a CI run?

@max-sixty

Copy link
Copy Markdown
Member

Were we also going to have a named-arg for csv?

We could merge this, have csv be the default, and then add in a named arg if we ever add json?

@max-sixty

Copy link
Copy Markdown
Member

I won't put this in the release notes yet given the open question, we can do 0.4.1 in a few days

@aljazerzen

Copy link
Copy Markdown
Member

This function is for parsing string literals - I'm not sure why anyone would prefer writing json instead of csv here...

@snth

snth commented Jan 16, 2023

Copy link
Copy Markdown
Member Author

Not writing, but pasting. I was thinking that you might get some JSON data back from some API and you might quickly just want to run a query over it. It would be convenient if you could just paste it (maybe even in the playground) and then test your query, rather than having to save the data to a file and then run it against that.

@aljazerzen

Copy link
Copy Markdown
Member

I see.

Do you think this signature is ok:

from_text csv:"a,b,c\n1,2,3\n4,5,6"
from_text json:'[{"a": 1, "b": 2, "c": 3, }, {"a": 4, "b": 5, "c": 6 }]'
from_text json:'{ "columns": ["a", "b", "c"], "data": [[1, 2, 3], [4, 5, 6]] }'

@snth

snth commented Jan 16, 2023

Copy link
Copy Markdown
Member Author

Interesting. In #286 we discussed having the signature as

from_text format:csv "a,b,c\n1,2,3\n4,5,6"
from_text format:json '[{"a": 1, "b": 2, "c": 3, }, {"a": 4, "b": 5, "c": 6 }]'

but your new suggestion is shorter.

Having different formats as different named parameters almost makes it a kind of enum and might make autodiscovery simpler and improve errors.

I think I might quite like that. Let me think on it a bit.

Any pros and cons for either approach that you could see on the code side?

@max-sixty

Copy link
Copy Markdown
Member

Interesting! I was also thinking about it like from_text format:csv.

I'm not strongly opposed to the csv: approach. It's less consistent with the language, though we're at an early stage to start weighing that highly.

For example, we have join [foo, bar] side:left, not join left:[foo, bar]

I'm +0.5 for the format: approach, but as ever happy to be see it go either way, and the do-er decides...

@snth

snth commented Jan 18, 2023

Copy link
Copy Markdown
Member Author

Recent thought on this: to make the API uniform across from_text and from_file, the format:csv will be better since the data won't come as a string.

Therefore I'm now +1 on format:.

@aljazerzen

Copy link
Copy Markdown
Member

It seems that we have a consensus and this can be merged.

@aljazerzen
aljazerzen merged commit c66befc into PRQL:main Jan 19, 2023
@snth
snth deleted the from_text branch August 15, 2023 15:04
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

Successfully merging this pull request may close these issues.

3 participants