Skip to content

Instantly share code, notes, and snippets.

@jaor
Last active December 20, 2018 05:03
Show Gist options
  • Save jaor/0cd705c1c9f8f32a80fcde99c39efc3d to your computer and use it in GitHub Desktop.
Save jaor/0cd705c1c9f8f32a80fcde99c39efc3d to your computer and use it in GitHub Desktop.
Mark fields with a prefix as non-preferred
{
"name": "Mark non-preferred",
"kind": "script",
"description": "Given a dataset, mark as non-preferred fields starting with a prefix",
"source_code": "script.whizzml",
"imports":[
],
"inputs":[
{
"name": "dataset-id",
"type": "dataset-id",
"description": "The dataset whose fields we want to mark"
},
{
"name": "prefix",
"type": "string",
"description": "The prefix of the fields' names to mark"
}],
"outputs":[
{
"name": "result",
"type": "dataset-id",
"description": "The input dataset, now with marked fields"
}]
}
(define (mark-fields ds-id prefix)
(let (fields (resource-fields ds-id)
ids (keys fields)
len (count prefix)
flags (for (f (values fields))
{"preferred" (not (= prefix (subs (f "name") 0 len)))}))
(update ds-id {"fields" (make-map ids flags)})))
(define result (mark-fields dataset-id prefix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment