NullPointerException while compiling the incremental update of a materialized property with a nested negated GROUP

Open
#1,958 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
backend, databases

Research direction

Start in the stored event query compilation path named in the stack trace: CompiledQuery$InnerSelect$QuerySelect.getSQLQuery, getEmptySelect, pushWhere, and GroupSelect.getSQLQuery, reached from DataSession.executeStoredEvent. Reproduce the materialized-property update using the described nested GROUP under NOT and inspect how the outer parameter is handled. Done means the incremental update compiles and any update error names the stored property.

Written by the indexing model from the issue text.

Description

bug
Description

A MATERIALIZED property whose expression contains a nested GROUP under NOT, with an outer parameter used only inside the negated part, can fail on APPLY of unrelated changes with an internal error from the query compiler instead of updating the stored value:

// shape reported on 6.2; the object B picked per A depends on counts that use a doubly negated nested group
unchecked(A a, B b) = NOT (GROUP SUM 1 IF p(X x, C c) AND NOT q(b, lookup(c)));
last(A a) = GROUP LAST B b ORDER b WHERE cnt1(a, b) = cnt2(a, b) MATERIALIZED;   // cnt2 uses unchecked(a, b)
// APPLY of changes to p / q with existing objects:
// java.lang.NullPointerException: Cannot invoke "lsfusion.server.data.type.Type.getCast(String, SQLSyntax, TypeEnvironment)" because "value" is null
//   at CompiledQuery$InnerSelect$QuerySelect.getSQLQuery <- getEmptySelect <- pushWhere <- GroupSelect.getSQLQuery, in DataSession.executeStoredEvent

Reported on 6.2; the code path is the same on master. The error names no property, so the declaration responsible has to be found by bisecting the module. Rewriting the double negation as a comparison of two counts ((OVERRIDE (GROUP SUM 1 IF cond AND checked), 0) = (OVERRIDE (GROUP SUM 1 IF cond), 0)) avoids it.

Reason

A stored property stops updating with an internal error that gives no hint of the cause; the shape ("no unchecked element") is a natural way to write such a condition.

Fix

The incremental update compiles, and an error raised while updating a stored property names that property.

Dominant language
Java
Stars
214
Forks
46
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lsfusion/platform

All issues in lsfusion/platform

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.