-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a06b507
commit f4cc1fb
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
core/trino-main/src/test/java/io/trino/sql/query/TestSetDigestFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.sql.query; | ||
|
||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestSetDigestFunctions | ||
{ | ||
private QueryAssertions assertions; | ||
|
||
@BeforeClass | ||
public void init() | ||
{ | ||
assertions = new QueryAssertions(); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public void teardown() | ||
{ | ||
assertions.close(); | ||
assertions = null; | ||
} | ||
|
||
@Test | ||
public void testCardinality() | ||
{ | ||
assertThat(assertions.query( | ||
"SELECT cardinality(make_set_digest(value)) " + | ||
"FROM (VALUES 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5) T(value)")) | ||
.matches("VALUES CAST(5 AS BIGINT)"); | ||
} | ||
|
||
@Test | ||
public void testExactIntersectionCardinality() | ||
{ | ||
assertThat(assertions.query( | ||
"SELECT intersection_cardinality(make_set_digest(v1), make_set_digest(v2)) " + | ||
"FROM (VALUES (1, 1), (NULL, 2), (2, 3), (3, 4)) T(v1, v2)")) | ||
.matches("VALUES CAST(3 AS BIGINT)"); | ||
} | ||
|
||
@Test | ||
public void testJaccardIndex() | ||
{ | ||
assertThat(assertions.query( | ||
"SELECT jaccard_index(make_set_digest(v1), make_set_digest(v2)) " + | ||
"FROM (VALUES (1, 1), (NULL,2), (2, 3), (NULL, 4)) T(v1, v2)")) | ||
.matches("VALUES CAST(0.5 AS DOUBLE)"); | ||
} | ||
|
||
@Test | ||
public void hashCounts() | ||
{ | ||
assertThat(assertions.query( | ||
"SELECT hash_counts(make_set_digest(value)) " + | ||
"FROM (VALUES 1, 1, 1, 2, 2) T(value)")) | ||
.matches("VALUES map(cast(ARRAY[19144387141682250, -2447670524089286488] AS array(bigint)), cast(ARRAY[3, 2] AS array(smallint)))"); | ||
} | ||
} |