Categorias:

Funções de agregação (estimativa de similaridade), funções de janela (estimativa de similaridade)

MINHASH_COMBINE

Combina estados de entrada de MinHash em um único estado de saída de MinHash. Este estado de minhash pode então ser introduzido na função APPROXIMATE_SIMILARITY para estimar a similaridade com outros estados MinHash.

Isto permite o uso de casos em que MINHASH é executado em conjuntos de linhas horizontais da mesma tabela, produzindo um estado MinHash para cada conjunto de linhas. Estes estados podem então ser combinados usando MINHASH_COMBINE, produzindo o mesmo estado de saída que uma única execução de MINHASH em toda a tabela.

Para obter mais informações sobre os estados MinHash, consulte Estimativa da similaridade de dois ou mais conjuntos.

Consulte também:

MINHASH

Sintaxe

Função de agregação

MINHASH_COMBINE( [ DISTINCT ] <state> )

Função de janela

MINHASH_COMBINE( [ DISTINCT ] <state> ) OVER ( [ PARTITION BY <expr> ] )

Para obter detalhes sobre a cláusula OVER, consulte Sintaxe e uso da função de janela.

Argumentos

state

Uma expressão que contém informações de estado MinHash geradas por uma chamada para MINHASH. Os estados MinHash de entrada devem ter matrizes de comprimento igual.

Notas de uso

Exemplos

USE SCHEMA snowflake_sample_data.tpch_sf1;

SELECT MINHASH_COMBINE(mh) FROM
    (
      (SELECT MINHASH(5, c2) mh FROM orders WHERE c2 <= 10000)
        UNION
      (SELECT MINHASH(5, c2) mh FROM orders WHERE c2 > 10000 AND c2 <= 20000)
        UNION
      (SELECT MINHASH(5, C2) mh FROM orders WHERE c2 > 20000)
    );

+-----------------------+
| MINHASH_COMBINE(MH)   |
|-----------------------|
| {                     |
|   "state": [          |
|     628914288006793,  |
|     1071764954434168, |
|     991489123966035,  |
|     2395105834644106, |
|     680224867834949   |
|   ],                  |
|   "type": "minhash",  |
|   "version": 1        |
| }                     |
+-----------------------+

Here is a more extensive example, showing the three related functions MINHASH, MINHASH_COMBINE and APPROXIMATE_SIMILARITY. This example creates 3 tables (ta, tb, and tc), two of which (ta and tb) are similar, and two of which (ta and tc) are completely dissimilar.

Criar e preencher tabelas com valores:

CREATE TABLE ta (i INTEGER);
CREATE TABLE tb (i INTEGER);
CREATE TABLE tc (i INTEGER);

INSERT INTO ta (i) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
INSERT INTO tb (i) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (11);
INSERT INTO tc (i) VALUES (-1), (-20), (-300), (-4000);

Calcular as informações de minhash para o conjunto inicial de dados:

CREATE TABLE minhash_a_1 (mh) AS SELECT MINHASH(100, i) FROM ta;
CREATE TABLE minhash_b (mh) AS SELECT MINHASH(100, i) FROM tb;
CREATE TABLE minhash_c (mh) AS SELECT MINHASH(100, i) FROM tc;

Adicionar mais dados a uma das tabelas:

INSERT INTO ta (i) VALUES (12);

Demonstrate the MINHASH_COMBINE function:

CREATE TABLE minhash_a_2 (mh) AS SELECT MINHASH(100, i) FROM ta WHERE i > 10;

CREATE TABLE minhash_a (mh) AS
  SELECT MINHASH_COMBINE(mh)
    FROM (
      (SELECT mh FROM minhash_a_1)
      UNION ALL
      (SELECT mh FROM minhash_a_2)
    );

This query shows the approximate similarity of the two similar tables (ta and tb):

SELECT APPROXIMATE_SIMILARITY(mh)
  FROM (
    (SELECT mh FROM minhash_a)
    UNION ALL
    (SELECT mh FROM minhash_b)
  );
+-----------------------------+
| APPROXIMATE_SIMILARITY (MH) |
|-----------------------------|
|                        0.75 |
+-----------------------------+

This query shows the approximate similarity of the two very different tables (ta and tc):

SELECT APPROXIMATE_SIMILARITY(mh)
  FROM (
    (SELECT mh FROM minhash_a)
    UNION ALL
    (SELECT mh FROM minhash_c)
  );
+-----------------------------+
| APPROXIMATE_SIMILARITY (MH) |
|-----------------------------|
|                           0 |
+-----------------------------+