Closed duffy-ocraven closed 3 years ago
@duffy-ocraven: Thanks for taking such a close look at the ZNG spec!
I think with the missing text added it would read more like "...a "plus" applied to a string and a non-string is a type mismatch..."
For instance, this works fine, as the first part of the sentence tells us to expect (running zq
commit d35b16a1
at the moment):
$ echo '{"one": "hello", "two": "world"}' | zq -t 'put combined=one+two' -
#0:record[one:string,two:string,combined:string]
0:[hello;world;helloworld;]
However, this gives the incompatible types
error:
$ echo '{"one": "hello", "two": 13}' | zq -t 'put combined=one+two' -
incompatible types
#0:record[one:string,two:float64]
0:[hello;13;]
And it can be repaired by using the cast syntax (described briefly here) to turn the number into a string first:
$ echo '{"one": "hello", "two": 13}' | zq -t 'put combined=one+two:string' -
#0:record[one:string,two:float64,combined:string]
0:[hello;13;hello13;]
I'll put up a PR to see about getting this addressed, as well as to address the missing TOC entry you spotted. Overall, you've come across some things that are still works-in-progress, as evidenced by the "TBD" references in the spec (such as at the top of that section). Indeed, we have an open issue #1408 to find a better home for that section outside of the ZNG spec, which is probably why we left it off the TOC. But the type system & casting/coercion are also due for deeper docs treatment once the dust settles from some other improvements we're doing in the ZQL expressions. In any case, thanks for helping keep us tidy while we iterate!
The very last line of https://github.com/brimsec/zq/blob/master/zng/docs/spec.md which says:
a "plus" operator applied to two strings, implies concatenation, but a "plus" applied to a string and is a type mismatch and casts or conversion functions should be used.
seems to be missing an important term, and does not make grammatical sense.BTW, Appendix B is not in the T-O-C, which has https://github.com/brimsec/zq/blob/master/zng/docs/spec.md#appendix-a-related-links as its last entry.