Kategorien:

Aggregatfunktionen (Kardinalitätsschätzung), Fensterfunktionen (Kardinalitätsschätzung)

HLL_ESTIMATE

Gibt die Kardinalitätsschätzung für den angegebenen HyperLogLog-Status zurück.

Ein von HLL_ACCUMULATE und HLL_COMBINE erzeugter HyperLogLog-Status kann verwendet werden, um mit der HLL_ESTIMATE-Funktion eine Kardinalitätsschätzung zu berechnen.

HLL_ESTIMATE(HLL_ACCUMULATE(…)) ist somit äquivalent zu HLL(…).

Siehe auch:

HLL, HLL_ACCUMULATE, HLL_COMBINE

Syntax

Aggregatfunktion

HLL_ESTIMATE( <state> )

Fensterfunktionen

HLL_ESTIMATE( <state> ) OVER ( [ PARTITION BY <expr> ] )

Informationen zur OVER-Klausel finden Sie unter Syntax und Verwendung von Fensterfunktionen.

Argumente

state

Ein Ausdruck, der Statusinformationen enthält, die durch einen Aufruf von HLL_ACCUMULATE oder HLL_COMBINE generiert wurden.

Nutzungshinweise

Beispiele

This example shows how to use the three related functions HLL_ACCUMULATE, HLL_ESTIMATE, and HLL_COMBINE.

Erstellen Sie eine einfache Tabelle und Daten:

CREATE OR REPLACE SEQUENCE seq92;
CREATE OR REPLACE TABLE sequence_demo (c1 INTEGER DEFAULT seq92.nextval, dummy SMALLINT);
INSERT INTO sequence_demo (dummy) VALUES (0);

INSERT INTO sequence_demo (dummy) SELECT dummy FROM sequence_demo;
INSERT INTO sequence_demo (dummy) SELECT dummy FROM sequence_demo;
INSERT INTO sequence_demo (dummy) SELECT dummy FROM sequence_demo;

Create a table that contains the „state“ that represents the current approximate cardinality information for the table named sequence_demo:

CREATE OR REPLACE TABLE resultstate1 AS (
  SELECT HLL_ACCUMULATE(c1) AS rs1
    FROM sequence_demo);

Now create a second table and add data. (In a more realistic situation, the user could have loaded more data into the first table and divided the data into non-overlapping sets based on the time that the data was loaded.)

CREATE OR REPLACE TABLE test_table2 (c1 INTEGER);
INSERT INTO test_table2 (c1) SELECT c1 + 4 FROM sequence_demo;

Rufen Sie die „Statusinformationen“ nur für die neuen Daten ab.

CREATE OR REPLACE TABLE resultstate2 AS
  (SELECT HLL_ACCUMULATE(c1) AS rs1
     FROM test_table2);

Kombinieren Sie die „Statusinformationen“ für die zwei Mengen von Zeilen:

CREATE OR REPLACE TABLE combined_resultstate (c1) AS
  SELECT HLL_COMBINE(rs1) AS apc1
    FROM (
      SELECT rs1 FROM resultstate1
      UNION ALL
      SELECT rs1 FROM resultstate2
    );

Ermitteln Sie die approximierte Kardinalität der kombinierten Zeilenmenge:

SELECT HLL_ESTIMATE(c1)
  FROM combined_resultstate;
+------------------+
| HLL_ESTIMATE(C1) |
|------------------|
|               12 |
+------------------+