forked from rcoh/angle-grinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lang] Add escape syntax for field names
Related to rcoh#99 Currently field names containing a space or period, e.g. `date received` or `grpc.method`, cannot be parsed. This could be worked around using `jq` or similar tools to rewrite the field name, but that's a pain. This commit adds an escaped field name syntax of `["<FIELD>"]` which is based on the Object Identifier-Index syntax[0] used by `jq`, so it should be somewhat familiar to many people who parse JSON on the command line. The more obvious option of delimiting with just quotes, e.g. "date received", creates an ambiguity between string literals and escaped field names. For example, does `where foo == "date received"` mean field `foo` matches field `date received`, or field `foo` matches the string "date received"? Example query: ``` * | json | where ["grpc.method"] == "Foo" | count by ["date received"] ``` [0] https://stedolan.github.io/jq/manual/#ObjectIdentifier-Index:.foo,.foo.bar
- Loading branch information
Will Chandler
committed
Jul 23, 2021
1 parent
e00d6ab
commit f6f1bd6
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
query = """ | ||
* | json | count by ["grpc.method"], ["start time"] | ||
""" | ||
input = """ | ||
{"start time": "today", "grpc.method": "Foo"} | ||
{"start time": "today", "grpc.method": "Bar"} | ||
""" | ||
output = """ | ||
["grpc.method"] ["start time"] _count | ||
----------------------------------------------------------- | ||
Bar today 1 | ||
Foo today 1 | ||
""" |