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

BIND with more general binary operations #399

Merged
merged 3 commits into from May 12, 2021

Conversation

hannahbast
Copy link
Member

Now allows the four basic arithmetic binary operations: + - * /

TODO 1: Since the - is not recognized by a SYMBOL, the minus is currently
realized via | (like a minus but vertical). I hope that Johannes finds a
better way.

I tried it out on a few example queries and it worked.

TODO 2: If one of the two operands is a constant -- from a previous BIND,
like in BIND(100 AS ?hundred) BIND(100 * ?x AS ?y) -- the operations don't
work as expected and I am not sure why. Maybe Johannes can help.

Now allows the four basic arithmetic binary operations:  + - * /

TODO: Since the - is not recognized by a SYMBOL, the minus is currently
realized via | (like a minus but vertical). I hope that Johannes finds a
better way.

I tried it out on a few example queries and it worked.

TODO: If one of the two operands is a constant (from a previous BIND,
like BIND(100 AS ?hundred), the operations don't work as expected and I
am not sure why. Maybe Johannes can help.
@hannahbast hannahbast requested a review from joka921 May 11, 2021 00:05
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave you the hint how to make the - work as expected, you can change this if you want.

In general: I am currently working on

  • a proper type system
  • a proper SparqlParser
  • proper expression evaluation.

This will also include this case, but until this is ready,
thank you very much for this valueable Improvement.

if (_lexer.current().raw != "+") {
binaryOperator = _lexer.current().raw;
// TODO: The minus `-` is not a SYMBOL, how do I accept it here as an
// alternative? Taking | for now as a silly workaround.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SparqlLexer.cpp , line 60:

const std::string SparqlLexer::SYMBOL =
    "([\\.\\{\\}\\(\\)\\=\\*,;:<>!\\|/\\^\\?\\*\\+])";

Here you can add the - (maybe as \\- vor safety) into the regex, then the ordinary syntax should work.

1. Symbol for minus is now - and not | (added to SYMBOL RE in lexer)
2. binaryOperator stored as char (and converted to string for cache key)
3. Fixed inconspicious bug from old code:

&input(i, colIdx)  should be  &input(i, columns[colIdx])
@hannahbast hannahbast merged commit d656d6e into master May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants