Skip to content

Bug in extractStateIntervals #232

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

Closed
tnixon opened this issue Jul 19, 2022 · 0 comments · Fixed by #234
Closed

Bug in extractStateIntervals #232

tnixon opened this issue Jul 19, 2022 · 0 comments · Fixed by #234
Assignees
Labels
bug Something isn't working

Comments

@tnixon
Copy link
Contributor

tnixon commented Jul 19, 2022

It turns out that there's a bug in extractStateIntervals such that comparisons are not applied across all metrics, but only until the first one evaluates as "true".

Example:

event_ts user device x y z
2015-02-24T13:30:49.232+0000 b s3_2 -0.96725750 0.03830722 9.14585
2015-02-24T13:30:49.242+0000 b s3_2 -0.93852705 -0.22026655 8.81066

When compared with the ">=" operator the records above come out as belonging to the same "state", which implies that the operator should be true for each pair of metrics in current >= previous, so:

  • -0.93852705 >= -0.96725750 (true - the first is a "smaller" negative number, so greater than the second)
  • -0.22026655 >= 0.03830722 (false)
  • 8.81066 >= 9.14585 (false)

It appears that the problem stems from comparing values in an array, like so:

select
  array(-0.93852705, -0.22026655, 8.81066) >= 
  array(-0.96725750,  0.03830722, 9.14585)

It appears that the SQL engine compares the elements in the array until it finds a true value, then it short-cut returns true for the entire comparison. It appears that this is a lexicographical comparison, in which the first non-same element will determine the results. For more detailed comparison, try this:

select
  (a >= b),
  zipped,
  transform(zipped, x -> x["a"] >= x["b"] ),
  forall( zipped, x -> x["a"] >= x["b"] )
from
  ( select
      a,
      b,
      arrays_zip(a, b) as zipped
    from
      ( select
          array(-0.93852705, -0.22026655, 8.81066) as a, 
          array(-0.96725750,  0.03830722, 9.14585) as b ) )

We need to compare all metrics with the given comparison operation independently, and then return the conjunction (logical AND) of the results.

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
2 participants