Search in sources :

Example 46 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

the class TestSelect method testSelectNation.

@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testSelectNation() {
    String sql = format("SELECT n_nationkey, n_name, n_regionkey, n_comment FROM %s", NATION_TABLE_NAME);
    QueryResult queryResult = onPresto().executeQuery(sql);
    assertThat(queryResult).matches(PRESTO_NATION_RESULT);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 47 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

the class TestSelect method testNationSelfInnerJoin.

@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testNationSelfInnerJoin() {
    String sql = format("SELECT n1.n_name, n2.n_regionkey FROM %s n1 JOIN " + "%s n2 ON n1.n_nationkey = n2.n_regionkey " + "WHERE n1.n_nationkey=3", NATION_TABLE_NAME, NATION_TABLE_NAME);
    QueryResult queryResult = onPresto().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("CANADA", 3), row("CANADA", 3), row("CANADA", 3), row("CANADA", 3), row("CANADA", 3));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 48 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

the class TestSelect method testCreateTableAsSelect.

@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testCreateTableAsSelect() {
    String sql = format("CREATE TABLE %s AS SELECT * FROM %s", CREATE_TABLE_AS_SELECT, NATION_TABLE_NAME);
    onPresto().executeQuery(sql);
    sql = format("SELECT n_nationkey, n_name, n_regionkey, n_comment FROM %s.%s.%s", "master", KEY_SPACE, CTAS_TABLE_NAME);
    QueryResult queryResult = onSqlServer().executeQuery(sql);
    assertThat(queryResult).matches(PRESTO_NATION_RESULT);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 49 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

the class TestSelect method testNationJoinRegion.

@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testNationJoinRegion() {
    String sql = format("SELECT c.n_name, t.name FROM %s c JOIN " + "tpch.tiny.region t ON c.n_regionkey = t.regionkey " + "WHERE c.n_nationkey=3", NATION_TABLE_NAME);
    QueryResult queryResult = onPresto().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("CANADA", "AMERICA"));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 50 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

the class TestHiveCoercion method doTestHiveCoercion.

private void doTestHiveCoercion(HiveTableDefinition tableDefinition) {
    String tableName = mutableTableInstanceOf(tableDefinition).getNameInDatabase();
    String floatToDoubleType = tableName.toLowerCase(Locale.ENGLISH).contains("parquet") ? "DOUBLE" : "REAL";
    query(format("INSERT INTO %s\n" + "VALUES\n" + "  (TINYINT '-1', TINYINT '2', TINYINT '-3', SMALLINT '100', SMALLINT '-101', INTEGER '2323', 12345, REAL '0.5',\n" + "    CAST(ROW ('as is', -1, 100, 2323, 12345) AS ROW(keep VARCHAR, ti2si TINYINT, si2int SMALLINT, int2bi INTEGER, bi2vc BIGINT)),\n" + "    ARRAY [CAST(ROW (2, -101, 12345, 'removed') AS ROW (ti2int TINYINT, si2bi SMALLINT, bi2vc BIGINT, remove VARCHAR))],\n" + "    MAP (ARRAY [TINYINT '2'], ARRAY [CAST(ROW (-3, 2323, REAL '0.5') AS ROW (ti2bi TINYINT, int2bi INTEGER, float2double %s))]),\n" + "    1),\n" + "  (TINYINT '1', TINYINT '-2', NULL, SMALLINT '-100', SMALLINT '101', INTEGER '-2323', -12345, REAL '-1.5',\n" + "    CAST(ROW (NULL, 1, -100, -2323, -12345) AS ROW(keep VARCHAR, ti2si TINYINT, si2int SMALLINT, int2bi INTEGER, bi2vc BIGINT)),\n" + "    ARRAY [CAST(ROW (-2, 101, -12345, NULL) AS ROW (ti2int TINYINT, si2bi SMALLINT, bi2vc BIGINT, remove VARCHAR))],\n" + "    MAP (ARRAY [TINYINT '-2'], ARRAY [CAST(ROW (null, -2323, REAL '-1.5') AS ROW (ti2bi TINYINT, int2bi INTEGER, float2double %s))]),\n" + "    1)", tableName, floatToDoubleType, floatToDoubleType));
    alterTableColumnTypes(tableName);
    assertProperAlteredTableSchema(tableName);
    QueryResult queryResult = query(format("SELECT * FROM %s", tableName));
    assertColumnTypes(queryResult);
    List<Row> expectedRows;
    Connection connection = defaultQueryExecutor().getConnection();
    if (usingPrestoJdbcDriver(connection)) {
        expectedRows = ImmutableList.of(row(-1, 2, -3L, 100, -101L, 2323L, "12345", 0.5, asMap("keep", "as is", "ti2si", (short) -1, "si2int", 100, "int2bi", 2323L, "bi2vc", "12345"), ImmutableList.of(asMap("ti2int", 2, "si2bi", -101L, "bi2vc", "12345")), asMap(2, asMap("ti2bi", -3L, "int2bi", 2323L, "float2double", 0.5, "add", null)), 1), row(1, -2, null, -100, 101L, -2323L, "-12345", -1.5, asMap("keep", null, "ti2si", (short) 1, "si2int", -100, "int2bi", -2323L, "bi2vc", "-12345"), ImmutableList.of(asMap("ti2int", -2, "si2bi", 101L, "bi2vc", "-12345")), ImmutableMap.of(-2, asMap("ti2bi", null, "int2bi", -2323L, "float2double", -1.5, "add", null)), 1));
    } else if (usingTeradataJdbcDriver(connection)) {
        expectedRows = ImmutableList.of(row(-1, 2, -3L, 100, -101L, 2323L, "12345", 0.5, "[\"as is\",-1,100,2323,\"12345\"]", "[[2,-101,\"12345\"]]", "{\"2\":[-3,2323,0.5,null]}", 1), row(1, -2, null, -100, 101L, -2323L, "-12345", -1.5, "[null,1,-100,-2323,\"-12345\"]", "[[-2,101,\"-12345\"]]", "{\"-2\":[null,-2323,-1.5,null]}", 1));
    } else {
        throw new IllegalStateException();
    }
    // test primitive values
    assertThat(queryResult.project(1, 2, 3, 4, 5, 6, 7, 8, 12)).containsOnly(project(expectedRows, 1, 2, 3, 4, 5, 6, 7, 8, 12));
    // test structural values (tempto can't handle map and row)
    assertEqualsIgnoreOrder(queryResult.column(9), column(expectedRows, 9), "row_to_row field is not equal");
    if (usingPrestoJdbcDriver(connection)) {
        assertEqualsIgnoreOrder(extract(queryResult.column(10)), column(expectedRows, 10), "list_to_list field is not equal");
    } else if (usingTeradataJdbcDriver(connection)) {
        assertEqualsIgnoreOrder(queryResult.column(10), column(expectedRows, 10), "list_to_list field is not equal");
    } else {
        throw new IllegalStateException();
    }
    assertEqualsIgnoreOrder(queryResult.column(11), column(expectedRows, 11), "map_to_map field is not equal");
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Connection(java.sql.Connection) Row(io.prestodb.tempto.assertions.QueryAssert.Row)

Aggregations

QueryResult (io.prestodb.tempto.query.QueryResult)122 Test (org.testng.annotations.Test)110 ProductTest (io.prestodb.tempto.ProductTest)108 Requires (io.prestodb.tempto.Requires)38 BigDecimal (java.math.BigDecimal)14 Statement (java.sql.Statement)12 PreparedStatement (java.sql.PreparedStatement)8 Duration (io.airlift.units.Duration)6 Row (io.prestodb.tempto.assertions.QueryAssert.Row)6 List (java.util.List)6 STORAGE_FORMATS (com.facebook.presto.tests.TestGroups.STORAGE_FORMATS)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Row.row (io.prestodb.tempto.assertions.QueryAssert.Row.row)4 QueryAssert.assertThat (io.prestodb.tempto.assertions.QueryAssert.assertThat)4 QueryExecutor.query (io.prestodb.tempto.query.QueryExecutor.query)4 String.format (java.lang.String.format)4 Connection (java.sql.Connection)4 Response (com.facebook.airlift.http.client.Response)2 PrestoConnection (com.facebook.presto.jdbc.PrestoConnection)2 JdbcDriverUtils (com.facebook.presto.tests.utils.JdbcDriverUtils)2