1

I've read the definition here https://docs.aws.amazon.com/kinesisanalytics/latest/sqlref/sql-reference-monotonic-expressions-operators.html, however it's still unclear to me. I understand that monotonic means ascending or descending. Does that mean that a monotonic column is ascending, descending, strictly ascending, or strictly descending? Does it have to be unique or can it contain duplicates?

The context of this question is that I tried use an ORDER BY in a WINDOW based on a TIMESTAMP, but I got the error The leading column of an ORDER BY statement must be monotonic (which I thought TIMESTAMPS were).

Example:

WINDOW fifteenSecondWindow as (
    PARTITION BY "peerId" (none unique)
    ORDER BY "emissionTime" (is unique for each partition of peers, but may not be globally unique)
    RANGE INTERVAL '15' SECOND PRECEDING
);
Mmm Donuts
  • 9,551
  • 6
  • 27
  • 49

1 Answers1

2

Monotonic in mathematics means that a each value of a sequence is either strictly greater than or equal to or less than or equal to the preceding value.

The notion of "monotonicity" is that ordering of the "x" values is preserved for the results of the function.

If you relax the equality, then the sequence is either strictly increasing or strictly decreasing.

I would expect this terminology to be standard wherever the term is used. So, duplicates are allowed.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • For my understanding - could you give me an example of a monotonic function that `preserves or reverses the given order` of an ordered set? – Mmm Donuts Nov 18 '19 at 01:23
  • @kris . . . Any monotonically increasing function preserves the order. So x + 2 or 3x-4 are examples. – Gordon Linoff Nov 18 '19 at 01:28
  • Got it, so for example `(-1)^n * 1/2` is bounded and is therefore not monotonic? – Mmm Donuts Nov 18 '19 at 01:34
  • @Kris . . . The sign changes for each increment of `n` . . . so it is quite far from being monotonic. Monotonic is more like the sequence is either increasing or decreasing (although it can be flat). – Gordon Linoff Nov 18 '19 at 01:41
  • That's what I meant! Thanks for the clarification - I overthought this one. – Mmm Donuts Nov 18 '19 at 01:42