Skip to content

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

Closed
terminusdb/terminusdb-dashboard
#316
@alexander-mart

Description

@alexander-mart

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions