Hi Till,
Regarding the comment on the PR[1]:
The fact that libjn:accumulate(({ "a": { "c": "d" } }, { "a": { "c": "d" }
})) returns {"a":{"c":"d"}} because since the specification for
libjn:accumulate was not clear, I thought that it would behave similar to
libjn:intersect and hence added a check to remove duplicate values for the
same key when accumulating into an array. So one { "c": "d" } is removed
because it's a duplicate value.
You can test with an entry like libjn:accumulate(({ "a": { "c": "d" } }, {
"a": { "e": "f" } })) which would return {"a":[{"c":"d"},{"e":"f"}]}. I
have also added this test case to the PR[1].
[1] https://github.com/apache/vxquery/pull/126
Thank you.
Yours sincerely,
Riyafa
On 28 July 2016 at 08:49, Riyafa Abdul Hameed <[email protected]>
wrote:
> Hi,
>
> I have updated the PR[1] to fit the specification on creating an array.
>
> [1] https://github.com/apache/vxquery/pull/126
>
> Thank you.
>
> Yours sincerely,
> Riyafa
>
> On 27 July 2016 at 21:11, Riyafa Abdul Hameed <[email protected]>
> wrote:
>
>> Hi Till,
>>
>> That's helpful. Thank you.
>>
>> Yours sincerely,
>> Riyafa
>>
>> On 27 July 2016 at 21:03, Till Westmann <[email protected]> wrote:
>>
>>> Hi Riyafa,
>>>
>>> the description is a spec is indeed a little terse :)
>>>
>>> Examples are:
>>>
>>> accumulate(({ "a": "b" }, { "c": "d" })) returns { "a": "b", "c": "d" }
>>>
>>> accumulate(({ "a": "b" }, { "a": "d" })) returns { "a": [ "b", "d" ] }
>>>
>>> In the second example there is a collision for the key "a" and instead of
>>> raising an error, the function will create an array that contain all the
>>> values for the key "a" in the source objects and use that as the value
>>> for "a" in the result object.
>>>
>>> Does this make sense?
>>>
>>> Cheers,
>>> Till
>>>
>>>
>>> On 27 Jul 2016, at 4:46, Riyafa Abdul Hameed wrote:
>>>
>>> Hi,
>>>>
>>>> I have attempted to implement libjn:accumulate[1]. This implementation
>>>> is
>>>> based on the part of the specification[2] which states that the
>>>> function be
>>>> implemented as follows:
>>>>
>>>> declare function libjn:accumulate($sequence as item()*) as object()
>>>> {
>>>> {|
>>>> for $key in $sequence() return { $key : $sequence($key) }
>>>> |}
>>>> };
>>>>
>>>> Since this method uses the dynamic constructor for objects this will
>>>> throw
>>>> an error upon pair collision.
>>>> But the specification also says :
>>>> "This function dynamically builds an object, like jn:object, except
>>>> that it
>>>> does not throw an error upon pair collision. Instead, it accumulates
>>>> them
>>>> into an array."
>>>>
>>>> I am not sure I understand this because this conflicts with the previous
>>>> (declare function) method specified and my implementation is based on
>>>> the
>>>> declare function method. What is the use of accumulating them into an
>>>> array? Further no examples are provided on this.
>>>>
>>>> [1] https://github.com/apache/vxquery/pull/126
>>>> [2]
>>>>
>>>> http://jsoniq.org/docs/JSONiqExtensionToXQuery/html-single/index.html#idm139680684849856
>>>>
>>>> Thank you.
>>>>
>>>> Yours sincerely,
>>>> Riyafa
>>>> --
>>>> Riyafa Abdul Hameed
>>>> Undergraduate, University of Moratuwa
>>>>
>>>> Email: [email protected]
>>>> Website: https://riyafa.wordpress.com/ <http://riyafa.wordpress.com/>
>>>> <http://facebook.com/riyafa.ahf> <http://lk.linkedin.com/in/riyafa>
>>>> <http://twitter.com/Riyafa1>
>>>>
>>>
>>
>>
>> --
>> Riyafa Abdul Hameed
>> Undergraduate, University of Moratuwa
>>
>> Email: [email protected]
>> Website: https://riyafa.wordpress.com/ <http://riyafa.wordpress.com/>
>> <http://facebook.com/riyafa.ahf> <http://lk.linkedin.com/in/riyafa>
>> <http://twitter.com/Riyafa1>
>>
>
>
>
> --
> Riyafa Abdul Hameed
> Undergraduate, University of Moratuwa
>
> Email: [email protected]
> Website: https://riyafa.wordpress.com/ <http://riyafa.wordpress.com/>
> <http://facebook.com/riyafa.ahf> <http://lk.linkedin.com/in/riyafa>
> <http://twitter.com/Riyafa1>
>
--
Riyafa Abdul Hameed
Undergraduate, University of Moratuwa
Email: [email protected]
Website: https://riyafa.wordpress.com/ <http://riyafa.wordpress.com/>
<http://facebook.com/riyafa.ahf> <http://lk.linkedin.com/in/riyafa>
<http://twitter.com/Riyafa1>