Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Adding a vars map to a groupBy query changes the shape of the results #500

Closed
Jackamus29 opened this issue Jun 8, 2023 · 4 comments
Assignees
Labels
bug Something isn't working as expected v2 Fluree

Comments

@Jackamus29
Copy link

Jackamus29 commented Jun 8, 2023

Tweaking a groupBy query to include a vars map changes the shape of the results from an object with the groupBy values as keys to an array of two-tuples where the first element is the groupBy value.

Without vars map

{
	"selectDistinct": [
		"?studentName",
		"?studentId"
	],
	"where": [
		["?profile", "profile/name", "?studentName"],
		["?profile", "profile/student_id", "?studentId"],
		["?assertion", "assertion/recipient", "?profile"],
        ["?assertion", "assertion/source", "?source"],
        ["?source", "profile/name", "?sourceName"]
	],
	"opts": {
		"compact": true,
        "groupBy": "?sourceName"
	}
}

=>

{
  "Institution A": [
    [
      "Lenny",
      "leonard2"
    ],
    [
      "Freddy",
      "fred25"
    ]
  ],
  "Institution B": [
    [
      "Freddy",
      "fred25"
    ]
  ]
}

With vars map

{
	"selectDistinct": [
		"?studentName",
		"?studentId"
	],
	"where": [
		["?profile", "profile/name", "?studentName"],
		["?profile", "profile/student_id", "?studentId"],
		["?assertion", "assertion/recipient", "?profile"],
        ["?assertion", "assertion/source", "?source"],
        ["?source", "profile/name", "?sourceName"]
	],
	"vars": {
		"?achievementType": ["Degree"]
	},
	"opts": {
		"compact": true,
        "groupBy": "?sourceName"
	}
}

=>

[
  [
    "Institution A",
    [
      [
        "Lenny",
        "leonard2"
      ],
      [
        "Freddy",
        "fred25"
      ]
    ]
  ],
  [
    "Institution B",
    [
      [
        "Freddy",
        "fred25"
      ]
    ]
  ]
]
@Jackamus29
Copy link
Author

Note, this may be related to #499

@Jackamus29
Copy link
Author

Jackamus29 commented Jun 8, 2023

Another oddity about this query is that if you add additional items to the vars map, it seems to duplicate the results.

vars map with a binding of length 1

{
	"selectDistinct": [
		"?studentName",
		"?studentId"
	],
	"where": [
		["?profile", "profile/name", "?studentName"],
		["?profile", "profile/student_id", "?studentId"],
		["?assertion", "assertion/recipient", "?profile"],
        ["?assertion", "assertion/source", "?source"],
        ["?source", "profile/name", "?sourceName"]
	],
	"vars": {
		"?achievementType": ["Degree"]
	},
	"opts": {
		"compact": true,
        "groupBy": "?sourceName"
	}
}

=

[
 [
   "Institution A",
   [
     [
       "Lenny",
       "leonard2"
     ],
     [
       "Freddy",
       "fred25"
     ]
   ]
 ],
 [
   "Institution B",
   [
     [
       "Freddy",
       "fred25"
     ]
   ]
 ]
]

vars map with an item of length 2

{
   "selectDistinct": [
   	"?studentName",
   	"?studentId"
   ],
   "where": [
   	["?profile", "profile/name", "?studentName"],
   	["?profile", "profile/student_id", "?studentId"],
   	["?assertion", "assertion/recipient", "?profile"],
       ["?assertion", "assertion/source", "?source"],
       ["?source", "profile/name", "?sourceName"]
   ],
   "vars": {
   	"?achievementType": ["Degree", "Test"]
   },
   "opts": {
   	"compact": true,
       "groupBy": "?sourceName"
   }
}

=>

[
 [
   "Institution A",
   [
     [
       "Lenny",
       "leonard2"
     ],
     [
       "Freddy",
       "fred25"
     ]
   ]
 ],
 [
   "Institution B",
   [
     [
       "Freddy",
       "fred25"
     ]
   ]
 ],
 [
   "Institution A",
   [
     [
       "Lenny",
       "leonard2"
     ],
     [
       "Freddy",
       "fred25"
     ]
   ]
 ],
 [
   "Institution B",
   [
     [
       "Freddy",
       "fred25"
     ]
   ]
 ]
]

@aaj3f aaj3f added bug Something isn't working as expected v2 Fluree labels Jun 12, 2023
@zonotope zonotope self-assigned this Jun 12, 2023
@aaj3f
Copy link
Contributor

aaj3f commented Jun 13, 2023

@zonotope @Jackamus29 not to tack on here, but I'm also seeing an odd NullPointerException with vars that can be reproduced here:

Transaction 1

[{
    "_id": "_predicate",
    "type": "string",
    "name": "_user/awards",
    "multi": true
}]

Transaction 2

[{
    "_id": "_user",
    "username": "jack",
    "awards": ["HS Degree", "College Degree"]
},
{
    "_id": "_user",
    "username": "kate",
    "awards": ["HS Degree", "College Degree", "Grad School Degree"]
}]

Query without vars

{
  "selectDistinct": [
      "?user",
      "?username",
      "?award",
      "(count ?award)"
      ],
  "where": [
      ["?user", "_user/awards", "?award"],
      ["?user", "_user/username", "?username"]
      ]
}

// =>

[
  [
    87960930223082,
    "kate",
    "College Degree",
    5
  ],
  [
    87960930223082,
    "kate",
    "Grad School Degree",
    5
  ],
  [
    87960930223082,
    "kate",
    "HS Degree",
    5
  ],
  [
    87960930223081,
    "jack",
    "College Degree",
    5
  ],
  [
    87960930223081,
    "jack",
    "HS Degree",
    5
  ]
]

Query with vars [broken; NullPointerException]

{
  "selectDistinct": [
      "?user",
      "?username",
      "?award",
      "(count ?award)"
      ],
  "where": [
      ["?user", "_user/awards", "?award"],
      ["?user", "_user/username", "?username"]
      ],
   "vars": {
      "?award": ["HS Degree"]
    }
}

// =>

2023-06-13 11:46:17,344 ERROR fluree.db.server - Uncaught exception on "async-dispatch-7" - java.lang.NullPointerException: null\n

@bplatz
Copy link
Contributor

bplatz commented Oct 31, 2024

That was marked as done in #514

@bplatz bplatz closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected v2 Fluree
Projects
None yet
Development

No branches or pull requests

4 participants