qt4cg / qtspecs

QT4 specifications
https://qt4cg.org/
Other
28 stars 15 forks source link

Lookup operator on arrays of maps #115

Closed michaelhkay closed 6 months ago

michaelhkay commented 2 years ago

I've been converting the XMark data files and queries from XML to JSON.

Here's part of Q20 in its XML form:

 <preferred>
  {count (/site/people/person/profile[@income >= 100000])}
 </preferred>

which becomes this, when we access the JSON form of the data:

 <preferred>
  {count (?people?*?profile[?income >= 100000])}
 </preferred>

It can get worse, for example Q16 has

exists ($a?annotation?description?parlist?*?parlist?*?text?*?emph?*?keyword?*?("§"))

These paths arise because a structured derived from JSON often includes map entries whose values are arrays.

It's very hard to get these paths right, and it's hard to produce good diagnostics when you get them wrong.

I'd like to allow the ?*? "operators" to be replaced with a simple "?". This isn't difficult. Currently the rules for the lookup operator say:

If the context item is an array:
If the [KeySpecifier] is an NCName, the [UnaryLookup](https://www.w3.org/TR/xpath-31/#doc-xpath31-UnaryLookup) operator raises a type error 

All that's needed is to change this to say that if the context item is an array, and the KeySpecifier is an NCName, then the array must be an array of maps and the lookup is applied to these maps.

ChristianGruen commented 2 years ago

Interesting tweak. The majority of the input can be expected to be regular, but I’m trying to understand what we get if we have mixed types:

let $map := map { 1: 1984, 'key': 'value' }
let $seq := ($map, [ $map ])
return $seq?(1, 'key')

Would this give us 1984, map { 1: 1984, 'key': 'value' }, value, value, as result?

michaelhkay commented 2 years ago

I'm open to suggestions on that. I think the best analogy with the current rules would be that the operator gets applied to EVERY item in the array and it's a type error if any of them fails.

ChristianGruen commented 2 years ago

Sounds reasonable. We may additionally need to clarify what happens if arrays are nested:

[ [ [ map { 'x': 'y' } ] ] ]?x   → y?
ChristianGruen commented 7 months ago

I propose to close this issue, now that we have a more general approach with deep lookups.

ndw commented 6 months ago

The CG agreed to close this issue without further action at meeting 073.