Very simple question – does dgraph support bitwise operators? Something like
@filter(gt(val(predicate & 8), 0))
The above, obviously, does not work, hence the question.
Very simple question – does dgraph support bitwise operators? Something like
@filter(gt(val(predicate & 8), 0))
The above, obviously, does not work, hence the question.
Thanks Michel! But I’m referring to bitwise operators (&, |) rather than logic operands (&&, ||). It’s probably not necessary anyway.
In fact, maybe you can suggest something better: it’s an old problem of storing a value for days of week. Back in the day we did this using bitwise operators. Monday = 1, Tuesday = 2, Wednesday = 4 etc. so a value for “Monday, Tuesday and Friday” would be 1 + 2 + 16 = 19.
Then in a search, you could have ‘daysOfWeek & 12 > 0’ in the ‘WHERE’ clause to see if days of Week included Wednesday or Thursday, for example.
You might tell me I should just have it stored in a node with each day of the week being a boolean, but there are advantages to having the days of week value be stored in a single variable rather than an edge to a whole new node.
To keep things as a single variable I can use a string (“MonTueFri”), then do a regex search on that string in the searches. Is that a stupid solution?
You could do the regexp solution. You could also just use OR operators, to say eq(dayofweek, "mon") || eq(dayofweek, "tue") || ...
, etc.
Dgraph also has math operators, which support a pow
function. You could try that to raise the days of week by 2, i.e. 2^dayofweek, and then check if the final output is as you expect it to be, by using an ==
operator in math again.
https://docs.dgraph.io/query-language/#math-on-value-variables
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.