-
Notifications
You must be signed in to change notification settings - Fork 74
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 (#146)
Related to #99 Currently field names containing a space, period, or escaped quote, 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>"]`. This 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 Co-authored-by: Will Chandler <[email protected]>
- Loading branch information
1 parent
f1c7da9
commit a513dcb
Showing
3 changed files
with
40 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"], nested.["user.name"] | ||
""" | ||
input = """ | ||
{"start time": "today", "grpc.method": "Foo", "nested": {"user.name": "user1"}} | ||
{"start time": "today", "grpc.method": "Bar", "nested": {"user.name": "user1"}} | ||
""" | ||
output = """ | ||
["grpc.method"] ["start time"] nested.["user.name"] _count | ||
--------------------------------------------------------------------------------------- | ||
Bar today user1 1 | ||
Foo today user1 1 | ||
""" |