Skip to content

SERVER ERROR: Not well formed WOQL JSON-LD #2156

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

Open
alexander-mart opened this issue Apr 4, 2025 · 11 comments · May be fixed by terminusdb/terminusdb-dashboard#316
Open

SERVER ERROR: Not well formed WOQL JSON-LD #2156

alexander-mart opened this issue Apr 4, 2025 · 11 comments · May be fixed by terminusdb/terminusdb-dashboard#316
Labels
bug Something isn't working

Comments

@alexander-mart
Copy link
Contributor

alexander-mart commented Apr 4, 2025

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

Query from documentation about math operators with js-style variables binding:

let v = Vars("result1", "result2");
and(
    evaluate(times(2,3), v.result1),
    evaluate(times(v.result1,3), v.result2)
)

❌ Return:

SERVER ERROR: Not well formed WOQL JSON-LD

Request payload from devtools:

{
    "query": {
        "@type": "Limit",
        "limit": 10,
        "query": {
            "query": {
                "@type": "Limit",
                "limit": 10,
                "query": {
                    "@type": "And",
                    "and": [
                        {
                            "@type": "Eval",
                            "expression": {
                                "@type": "Times",
                                "left": {
                                    "@type": "ArithmeticValue",
                                    "data": {
                                        "@type": "xsd:decimal",
                                        "@value": 2
                                    }
                                },
                                "right": {
                                    "@type": "ArithmeticValue",
                                    "data": {
                                        "@type": "xsd:decimal",
                                        "@value": 3
                                    }
                                }
                            },
                            "result": {
                                "@type": "ArithmeticValue",
                                "variable": "result1"
                            }
                        },
                        {
                            "@type": "Eval",
                            "expression": {
                                "@type": "Times",
                                "left": {
                                    "@type": "Value",
                                    "variable": "result1"
                                },
                                "right": {
                                    "@type": "ArithmeticValue",
                                    "data": {
                                        "@type": "xsd:decimal",
                                        "@value": 3
                                    }
                                }
                            },
                            "result": {
                                "@type": "ArithmeticValue",
                                "variable": "result2"
                            }
                        }
                    ]
                }
            }
        }
    }
}

Response from devtools:

{
    "@type": "api:WoqlErrorResponse",
    "api:error": {
        "@type": "vio:WOQLSyntaxError",
        "vio:path": [
            "and",
            1,
            "query"
        ],
        "vio:query": {
            "@type": "Eval",
            "expression": {
                "@type": "Times",
                "left": {
                    "@type": "Value",
                    "variable": "result1"
                },
                "right": {
                    "@type": "ArithmeticValue",
                    "data": {
                        "@type": "xsd:decimal",
                        "@value": 3
                    }
                }
            },
            "result": {
                "@type": "ArithmeticValue",
                "variable": "result2"
            }
        }
    },
    "api:message": "Not well formed WOQL JSON-LD",
    "api:status": "api:failure"
}

But similar query without js-style variables bindings:

and(
  evaluate(times(2,3), "v:result1"),
  evaluate(times("v:result1",3), "v:result2")
)

✅ Return correct result:

[
  {
    "result1": {
      "@type": "xsd:decimal",
      "@value": 6
    },
    "result2": {
      "@type": "xsd:decimal",
      "@value": 18
    }
  }
]

Request payload from devtools:

{
    "query": {
        "@type": "Count",
        "count": {
            "@type": "Value",
            "variable": "Count"
        },
        "query": {
            "@type": "And",
            "and": [
                {
                    "@type": "Eval",
                    "expression": {
                        "@type": "Times",
                        "left": {
                            "@type": "ArithmeticValue",
                            "data": {
                                "@type": "xsd:decimal",
                                "@value": 2
                            }
                        },
                        "right": {
                            "@type": "ArithmeticValue",
                            "data": {
                                "@type": "xsd:decimal",
                                "@value": 3
                            }
                        }
                    },
                    "result": {
                        "@type": "ArithmeticValue",
                        "variable": "result1"
                    }
                },
                {
                    "@type": "Eval",
                    "expression": {
                        "@type": "Times",
                        "left": {
                            "@type": "ArithmeticValue",
                            "variable": "result1"
                        },
                        "right": {
                            "@type": "ArithmeticValue",
                            "data": {
                                "@type": "xsd:decimal",
                                "@value": 3
                            }
                        }
                    },
                    "result": {
                        "@type": "ArithmeticValue",
                        "variable": "result2"
                    }
                }
            ]
        }
    }
}

Difference between non-working (-) and working (+) request

{
    "query": {
-        "@type": "Limit",
-        "limit": 10,
+        "@type": "Count",
+        "count": {
+            "@type": "Value",
+            "variable": "Count"
+        },
        "query": {
            "@type": "And",
            "and": [
                {
                    "@type": "Eval",
                    "expression": {
                        "@type": "Times",
                        "left": {
                            "@type": "ArithmeticValue",
                            "data": {
                                "@type": "xsd:decimal",
                                "@value": 2
                            }
                        },
                        "right": {
                            "@type": "ArithmeticValue",
                            "data": {
                                "@type": "xsd:decimal",
                                "@value": 3
                            }
                        }
                    },
                    "result": {
                        "@type": "ArithmeticValue",
                        "variable": "result1"
                    }
                },
                {
                    "@type": "Eval",
                    "expression": {
                        "@type": "Times",
                        "left": {
-                            "@type": "Value",
+                            "@type": "ArithmeticValue",
                            "variable": "result1"
                        },
                        "right": {
                            "@type": "ArithmeticValue",
                            "data": {
                                "@type": "xsd:decimal",
                                "@value": 3
                            }
                        }
                    },
                    "result": {
                        "@type": "ArithmeticValue",
                        "variable": "result2"
                    }
                }
            ]
        }
    }
}

Expected behavior

  1. Return correct result:
[
  {
    "result1": {
      "@type": "xsd:decimal",
      "@value": 6
    },
    "result2": {
      "@type": "xsd:decimal",
      "@value": 18
    }
  }
]
  1. Or fix the documentation

Screenshots
...

Info (please complete the following information):

  • terminus-server from docker-compose: terminusdb/terminusdb-server:v11.1.14

Additional context

@alexander-mart alexander-mart added the bug Something isn't working label Apr 4, 2025
@dfrnt-hoijnet
Copy link

I was quickly checking it, could you provide the similar output for the working example too for the similar query without js-style variables bindings (I.e. v:var notation)? It would help troubleshoot so that we can see the diff and see what needs to be done?

@dfrnt-hoijnet
Copy link

I suspect this should be moved to the javascript client but let's confirm first!

@alexander-mart
Copy link
Contributor Author

similar output for the working example too for the similar query without js-style variables bindings (I.e. v:var notation)

@hoijnet I updated the issue

@dfrnt-hoijnet
Copy link

Thanks a lot, also for the diff. Should be possible to fix in the client and roll with the next release of it I hope!

@alexander-mart
Copy link
Contributor Author

alexander-mart commented Apr 23, 2025

It's also working:

let v = Vars("result1", "result2");
and(
    evaluate(times(2,3), v.result1),
    evaluate(times("v:result1",3), v.result2)
)

But not this:

let v = Vars("result1", "result2");
and(
    evaluate(times(2,3), v.result1),
    evaluate(times(v.result1,3), v.result2)
)

And this is problem with every math operation:

let v = Vars("result1", "result2");
and(
    evaluate(minus(2,3), v.result1),
    evaluate(minus(v.result1,3), v.result2)
)

@hoijnet
Copy link
Collaborator

hoijnet commented Apr 23, 2025

It's also working...

I did a first pass at checking it and there seems to be more to it than the example code, for which there is a clue in your diff.

This works:

let v = Vars("result1", "result2");
WOQL.limit(10).and(
    WOQL.evaluate(WOQL.times(2,3), v.result1),
    WOQL.evaluate(WOQL.times(v.result1,3), v.result2)
  );

This also works:

let v = Vars("result1", "result2");
WOQL.limit(10).limit(10).and(
    WOQL.evaluate(WOQL.times(2,3), v.result1),
    WOQL.evaluate(WOQL.times(v.result1,3), v.result2)
  );

This works:

let v = Vars("result1", "result2");
WOQL.count("v:Count").and(
    WOQL.evaluate(WOQL.times(2,3), v.result1),
    WOQL.evaluate(WOQL.times(v.result1,3), v.result2)
  );

This also works:

let v = Vars("result1", "result2", "Count");
WOQL.count("v:Count").and(
    WOQL.evaluate(WOQL.times(2,3), v.result1),
    WOQL.evaluate(WOQL.times(v.result1,3), v.result2)
  );

This also works (as shown):

WOQL.and(
    WOQL.evaluate(WOQL.times(2,3), v.result1),
    WOQL.evaluate(WOQL.times(v.result1,3), v.result2)
  );

Count you confirm that it is together with limit(10) that it is not working for you?

I have not been able to reproduce the issue getting "Value" with the example provided.

The example provided does not correspond 1:1 with the WOQL output as there are multiple instances of Limit and Count that are not part of the original WOQL query. I'm unsure about why Value pops up instead of ArithmeticValue as I don't have an immediate explanation in the javascript code.

Can you also confirm that you are using the latest client to rule out that potential issue.

alexander-mart added a commit to alexander-mart/terminusdb-client-js that referenced this issue Apr 23, 2025
@alexander-mart
Copy link
Contributor Author

@hoijnet I added a PR to fix this completely. In the PR description I attach a test with proof that it works.
terminusdb/terminusdb-dashboard#316

@hoijnet
Copy link
Collaborator

hoijnet commented Apr 26, 2025

@alexander-mart , please check if you get the same behaviour with eval() as you get with evaluate()?

I believe evaluate() should be deprecated and there should be only one, and well-functioning arithmetic evaluation, are you of the same view?

@alexander-mart
Copy link
Contributor Author

alexander-mart commented Apr 26, 2025

With v.10.0.31 of js client (that used in v11.1.14 terminusdb-server) we have the same error with eva() and evaluate()

With v.10.0.33 of js client there is no errors, and this PR terminusdb-dashboard/pull/316 should fix this for terminusdb/terminusdb-server:v11.1.14

@hoijnet
Copy link
Collaborator

hoijnet commented Apr 27, 2025

Ok, that sounds promising!

I assume this issue refers to the dashboard component and that we should rebuild it with the latest client then?

@alexander-mart
Copy link
Contributor Author

this issue refers to the dashboard component and that we should rebuild it with the latest client then?

Yes it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants