-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zyp: Translate special treatments to jq-based MokshaTransformation again
A few operations can be performed more efficiently on the whole collection at once when using Moksha/jq. - Flattening nested lists - Pruning lists of objects - Converting to objects, lists, and strings To support those operations, a jq support library was added, including a few helper functions written in jqlang itself. The helper functions are: - to_array - to_object - is_array_of_objects - del_array_of_objects - prune_array_of_objects - prune_null
- Loading branch information
Showing
10 changed files
with
307 additions
and
59 deletions.
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
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,40 @@ | ||
# Support functions for Zyp Transformations | ||
# https://commons-codec.readthedocs.io/zyp/ | ||
|
||
def to_array: | ||
# Convert element to array if it isn't an array already. | ||
if . | type == "array" then | ||
. | ||
else | ||
[.] | ||
end; | ||
|
||
def to_object(options): | ||
# Wrap element into object with given key if it isn't an object already. | ||
if . | type == "object" then | ||
. | ||
else | ||
{(options.key): .} | ||
end; | ||
|
||
def is_array_of_objects: | ||
# Check if element is an array containing objects. | ||
if (. | type == "array") and (.[0] | type == "object") then | ||
true | ||
else | ||
false | ||
end; | ||
|
||
def del_array_of_objects: | ||
# If element is an array containing objects, delete it. | ||
if is_array_of_objects then | ||
del(.) | ||
end; | ||
|
||
def prune_array_of_objects: | ||
# Recursively drop arrays of objects. | ||
walk(del_array_of_objects); | ||
|
||
def prune_null: | ||
# Recursively delete `null` values. | ||
walk(values); |
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
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
Oops, something went wrong.