deepstream.io icon indicating copy to clipboard operation
deepstream.io copied to clipboard

Record Set JsonPath with numeric parts that are not array indices returned different results on client vs server side

Open honorcode opened this issue 9 years ago • 10 comments

Using localhost (Mac osx) Deepstream.io 2.2.0, Java Client 2.0.8, no plugins

Upon setRecord(recId, "a.b.1", value) the end result of set shows the path created to be: { "a": { "b": { "1": value } } }

Problem: data-sync/getRecord returns this record which does not match and will fail gson.toJson(elem): { "a": { "b": [ null, value ] } }

Example Test: setRecord runtime breakpoint below ->

In UtilJsonPath.java :: setIterateThrough @ line 52 private static JsonElement setIterateThrough(JsonElement element, String path, JsonElement value, boolean delete) ... breakpoint at line 92: updateValue(value, (JsonElement)parent, token, delete); where runtime vars: element = {"tickets":{"ticketTexts":{"1":{}}}} value = "BDD TESTING" token = "1" path = "tickets.ticketTexts.1" parent = "{"1":{}}" delete = false

BUT upon setRecord completing the data-sync'd record and / or subsequent getRecord returns this: {"tickets":{"ticketTexts":[null,"BDD TESTING"]}}

honorcode avatar Apr 16 '17 06:04 honorcode

Btw, much of our data is deeply nested json objs with numerous objects members having numeric fieldnames. These are automated transforms in another ETL application, not possible to refactor easily.

honorcode avatar Apr 16 '17 06:04 honorcode

The numeric fieldnames also help significantly as the number of records scales due to memory usage for each fieldname's length for every obj. Smaller fieldnames = smaller objects = smaller data stores = less bandwidth.

honorcode avatar Apr 16 '17 06:04 honorcode

We also don't want the added padding of nulls in sparse arrays of slotted values.

honorcode avatar Apr 16 '17 06:04 honorcode

this is probably related to the issue #646 I have posted earlier. The fix is also posted. I hope they patch it soon

redlock avatar Apr 16 '17 10:04 redlock

@WolframHempel @yasserf @AlexBHarley FYI the website link for the Contributor License Agreement is broken, so I couldn't do a PR but below is my deepstream.io/master patch with my FIXes for the server-side issues #651 and #646.

honorcode avatar Apr 18 '17 21:04 honorcode

honorcode_deepstream_io_patch_fix_json_path_numeric_obj_member_support.diff (ok - .diff file type not supported so I guess I'll include my two .js files (json-path.js and json-pathSpec.js) as .txt files below.

honorcode avatar Apr 18 '17 21:04 honorcode

Summary: JsonPath _tokenizer and setValue fncs now uses NEW algo to transform json path array items (e.g. arr[3]) into a single 'part' of jsonpath token parts 'arrayProp[#]' members transform to 'arrayProp=#' now instead of 'arrayProp.#' previously see setValue fnc for special handling of array item parsing vs numeric obj member name e.g. 'object.1' parsing. This allows for support of parsing and differentiating object member names that are numeric values from array index numeric values in the JsonPath.

json-path.txt json-pathSpec.txt

honorcode avatar Apr 18 '17 21:04 honorcode

@WolframHempel @yasserf @AlexBHarley Opened related java-client issue found when testing: https://github.com/deepstreamIO/deepstream.io-client-java/issues/84

honorcode avatar Apr 18 '17 22:04 honorcode

unsure of priority for this issue. yasser suggested this could be a client_data vs. server_data issue.

script:

const deepstream = require('deepstream.io-client-js')

const client = deepstream('wss://154.dsh.cloud?apiKey=021c04c5-a631-409d-85d1-1fb71aaa1a17')

client.login({ type: 'open' }, (success, data) => {
  console.log(success, data)
})

const recordName = 'myNewRecord_a'

client.record.getRecord(recordName)

client.record.setData(recordName, 'a.b.1', 'value', (error) => {
  if(error) {
    console.log('error: ', error)
  }
})

setTimeout(() => {
  console.log('getting record:\n  ', client.record.getRecord(recordName).get())
}, 1500)

setTimeout(() => {
  client.close()
}, 2000)

result: Screen Shot 2017-08-03 at 16.51.00.png

mrby avatar Aug 03 '17 14:08 mrby

Closing in favour of https://github.com/deepstreamIO/deepstream.io/issues/1046

yasserf avatar May 03 '20 07:05 yasserf