Search in sources :

Example 1 with QueryAssert

use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.

the class SqlDataTypeTest method verifySelect.

private void verifySelect(QueryRunner queryRunner, Session session, TestTable testTable) {
    // Closing QueryAssertions would close the QueryRunner
    @SuppressWarnings("resource") QueryAssertions queryAssertions = new QueryAssertions(queryRunner);
    QueryAssert assertion = assertThat(queryAssertions.query(session, "SELECT * FROM " + testTable.getName()));
    MaterializedResult expected = queryRunner.execute(session, testCases.stream().map(TestCase::getExpectedLiteral).collect(joining(",", "VALUES ROW(", ")")));
    // Verify types if specified
    for (int column = 0; column < testCases.size(); column++) {
        TestCase testCase = testCases.get(column);
        if (testCase.getExpectedType().isPresent()) {
            Type expectedType = testCase.getExpectedType().get();
            assertion.outputHasType(column, expectedType);
            assertThat(expected.getTypes()).as(format("Expected literal type at column %d (check consistency of expected type and expected literal)", column + 1)).element(column).isEqualTo(expectedType);
        }
    }
    assertion.matches(expected);
}
Also used : Type(io.trino.spi.type.Type) QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) QueryAssertions(io.trino.sql.query.QueryAssertions) MaterializedResult(io.trino.testing.MaterializedResult)

Example 2 with QueryAssert

use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.

the class BaseQueryAssertionsTest method testTimeWithTimeZoneQueryResult.

/**
 * Tests query runner with results of various precisions, and query assert.
 */
@Test
public void testTimeWithTimeZoneQueryResult() {
    assertThat(query("SELECT TIME '01:23:45.123 +05:07'")).matches("SELECT TIME '01:23:45.123 +05:07'");
    assertThat(query("SELECT TIME '01:23:45.123456 +05:07'")).matches("SELECT TIME '01:23:45.123456 +05:07'");
    assertThat(query("SELECT TIME '01:23:45.123456789 +05:07'")).matches("SELECT TIME '01:23:45.123456789 +05:07'");
    assertThat(query("SELECT TIME '01:23:45.123456789012 +05:07'")).matches("SELECT TIME '01:23:45.123456789012 +05:07'");
    QueryAssert queryAssert = assertThat(query("SELECT TIME '01:23:45.123456789012 +05:07'"));
    // different second fraction
    assertThatThrownBy(() -> queryAssert.matches("SELECT TIME '01:23:45.123456789013 +05:07'")).hasMessageContaining("Expecting:\n" + "  <(01:23:45.123456789012+05:07)>\n" + "to contain exactly in any order:\n" + "  <[(01:23:45.123456789013+05:07)]>");
    // different zone
    assertThatThrownBy(() -> queryAssert.matches("SELECT TIME '01:23:45.123456789012 +05:42'")).hasMessageContaining("Expecting:\n" + "  <(01:23:45.123456789012+05:07)>\n" + "to contain exactly in any order:\n" + "  <[(01:23:45.123456789012+05:42)]>");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Example 3 with QueryAssert

use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.

the class BaseQueryAssertionsTest method testTimestampQueryResult.

/**
 * Tests query runner with results of various precisions, and query assert.
 */
@Test
public void testTimestampQueryResult() {
    assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123'");
    assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456'");
    assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789'");
    assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012'")).matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012'");
    QueryAssert queryAssert = assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012'"));
    assertThatThrownBy(() -> queryAssert.matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789013'")).hasMessageContaining("Expecting:\n" + "  <(2017-01-02 09:12:34.123456789012)>\n" + "to contain exactly in any order:\n" + "  <[(2017-01-02 09:12:34.123456789013)]>");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Example 4 with QueryAssert

use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.

the class BaseQueryAssertionsTest method testTimeQueryResult.

/**
 * Tests query runner with results of various precisions, and query assert.
 */
@Test
public void testTimeQueryResult() {
    assertThat(query("SELECT TIME '01:23:45.123'")).matches("SELECT TIME '01:23:45.123'");
    assertThat(query("SELECT TIME '01:23:45.123456'")).matches("SELECT TIME '01:23:45.123456'");
    assertThat(query("SELECT TIME '01:23:45.123456789'")).matches("SELECT TIME '01:23:45.123456789'");
    assertThat(query("SELECT TIME '01:23:45.123456789012'")).matches("SELECT TIME '01:23:45.123456789012'");
    QueryAssert queryAssert = assertThat(query("SELECT TIME '01:23:45.123456789012'"));
    assertThatThrownBy(() -> queryAssert.matches("SELECT TIME '01:23:45.123456789013'")).hasMessageContaining("Expecting:\n" + "  <(01:23:45.123456789012)>\n" + "to contain exactly in any order:\n" + "  <[(01:23:45.123456789013)]>");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Example 5 with QueryAssert

use of io.trino.sql.query.QueryAssertions.QueryAssert in project trino by trinodb.

the class BaseQueryAssertionsTest method testVarbinaryResult.

@Test
public void testVarbinaryResult() {
    assertThat(query("SELECT X'001234'")).matches("VALUES X'001234'");
    QueryAssert queryAssert = assertThat(query("SELECT X'001234'"));
    assertThatThrownBy(() -> queryAssert.matches("VALUES X'001299'")).hasMessageMatching("" + // when using local query runner
    "(?s).*" + "(\\Q" + "Expecting:\n" + "  <(00 12 34)>\n" + "to contain exactly in any order:\n" + "  <[(00 12 99)]>\n" + "elements not found:\n" + "  <(00 12 99)>" + "\\E|\\Q" + // when using distributed query runner
    "Expecting:\n" + "  <([0, 18, 52])>\n" + "to contain exactly in any order:\n" + "  <[([0, 18, -103])]>" + "\\E).*");
}
Also used : QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) Test(org.testng.annotations.Test)

Aggregations

QueryAssert (io.trino.sql.query.QueryAssertions.QueryAssert)9 Test (org.testng.annotations.Test)8 Type (io.trino.spi.type.Type)1 QueryAssertions (io.trino.sql.query.QueryAssertions)1 LocalQueryRunner (io.trino.testing.LocalQueryRunner)1 MaterializedResult (io.trino.testing.MaterializedResult)1