Redefining record field value in a transform

11 views
Skip to first unread message

Shane Breatnach

unread,
Aug 12, 2010, 12:16:18 PM8/12/10
to Jaql Users
Hi,

I need to redefine a particular record field value as part of a
transform. Normally, this is not an issue. But, the complication is
this: I don't know what fields are specified in the record beforehand.
So I must use the $.* shortcut to get all record fields during the
transform. But doing so in the obvious manner means I get a duplicate
field error. Is there a way to achieve what I need?

My sample query:
$clicks = [
{
"bt#9": 4,
"bt#9:166": 3,
"bt#9:167": 1,
"bt#total": 4,
"key": "chqvbn2w2o-737ac32a",
},
{
"bt#19": 56,
"bt#19:161": 33,
"bt#19:162": 4,
"bt#19:164": 3,
"bt#19:165": 16,
"bt#5": 23,
"bt#5:162": 4,
"bt#5:164": 3,
"bt#5:165": 16,
"bt#9": 3,
"bt#9:166": 2,
"bt#9:167": 1,
"bt#total": 82,
"key": "chqvbplkr0-0ee02305",
},
{
"bt#9": 5,
"bt#9:166": 3,
"bt#9:167": 2,
"bt#total": 5,
"key": "chqvbrye7q-737ac32a",
},
{
"bt#15": 10,
"bt#15:163": 2,
"bt#15:164": 8,
"bt#19": 2,
"bt#19:161": 1,
"bt#19:164": 1,
"bt#9": 10,
"bt#9:166": 9,
"bt#9:167": 1,
"bt#total": 22,
"key": "chqvbuhp2y-fb440f2b",
},
{
"bt#9": 7,
"bt#9:166": 6,
"bt#9:167": 1,
"bt#total": 7,
"key": "chqvbuy7so-4159ce5b",
},
{
"bt#19": 56,
"bt#19:161": 33,
"bt#19:162": 4,
"bt#19:164": 3,
"bt#19:165": 16,
"bt#5": 23,
"bt#5:162": 4,
"bt#5:164": 3,
"bt#5:165": 16,
"bt#9": 4,
"bt#9:166": 2,
"bt#9:167": 2,
"bt#total": 83,
"key": "chqvbw5h2c-0ee02305",
},
{
"bt#9": 3,
"bt#9:166": 2,
"bt#9:167": 1,
"bt#total": 3,
"key": "chqvbw7504-d53a4602",
},
{
"bt#9": 1,
"bt#9:167": 1,
"bt#total": 1,
"key": "chqvbxa6t0-46300797",
},
{
"bt#1": 4,
"bt#19": 1,
"bt#19:166": 1,
"bt#1:166": 4,
"bt#4": 7,
"bt#4:166": 7,
"bt#6": 1,
"bt#6:166": 1,
"bt#9": 4,
"bt#9:166": 3,
"bt#9:167": 1,
"bt#total": 17,
"key": "chqvc0fpt8-a30809a6",
},
{
"bt#4": 133,
"bt#4:166": 133,
"bt#9": 4,
"bt#9:166": 3,
"bt#9:167": 1,
"bt#total": 137,
"key": "chqvc366oi-3eb8ae0a",
},
];

$clicks
-> transform { key: 'new_key' + $.key, $.* };

So, I want to prepend the string "new_key" to every key with all other
pre-existing fields as they were. Is this possible?

Thanks in advance,
Shane

Shane Breatnach

unread,
Aug 13, 2010, 4:08:20 AM8/13/10
to Jaql Users
Managed to find the solution to my own problem. What the documentation
mentions, but doesn't make entirely clear with examples, is that you
can use a function as the expression of a transform. Using the built-
in function remap(), the fix is simple:

$clicks
-> transform remap( $, { key: 'new_key' + $.key } );
Reply all
Reply to author
Forward
0 new messages