Search in sources :

Example 81 with QueryResult

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

the class CreateTableAsSelect method testCreateTableAsSelect.

@Requires(ImmutableNationTable.class)
@Test(groups = { JDBC, MYSQL })
public void testCreateTableAsSelect() {
    QueryResult queryResult = query(format("CREATE TABLE mysql.%s AS SELECT * FROM nation", TABLE_NAME));
    assertThat(queryResult).containsOnly(row(25));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Requires(io.prestodb.tempto.Requires) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 82 with QueryResult

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

the class TestCsv method assertSelect.

private static void assertSelect(String query, String tableName) {
    QueryResult expected = query(format(query, "tpch." + TPCH_SCHEMA + ".lineitem"));
    List<Row> expectedRows = expected.rows().stream().map((columns) -> row(columns.toArray())).collect(toImmutableList());
    QueryResult actual = query(format(query, tableName));
    List<Row> actualRows = actual.rows().stream().map((columns) -> row(columns.toArray())).collect(toImmutableList());
    assertThat(actual).hasColumns(expected.getColumnTypes()).containsOnly(expectedRows);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) List(java.util.List) QueryExecutor.query(io.prestodb.tempto.query.QueryExecutor.query) Row(io.prestodb.tempto.assertions.QueryAssert.Row) QueryAssert.assertThat(io.prestodb.tempto.assertions.QueryAssert.assertThat) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) STORAGE_FORMATS(com.facebook.presto.tests.TestGroups.STORAGE_FORMATS) Test(org.testng.annotations.Test) Row.row(io.prestodb.tempto.assertions.QueryAssert.Row.row) ProductTest(io.prestodb.tempto.ProductTest) String.format(java.lang.String.format) QueryResult(io.prestodb.tempto.query.QueryResult) Row(io.prestodb.tempto.assertions.QueryAssert.Row)

Example 83 with QueryResult

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

the class TestHiveCoercion method testHiveCoercionAvro.

@Requires(AvroRequirements.class)
@Test(groups = { HIVE_COERCION, JDBC })
public void testHiveCoercionAvro() {
    String tableName = mutableTableInstanceOf(HIVE_COERCION_AVRO).getNameInDatabase();
    onHive().executeQuery(format("INSERT INTO TABLE %s " + "PARTITION (id=1) " + "VALUES" + "(2323, 0.5)," + "(-2323, -1.5)", tableName));
    onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN int_to_bigint int_to_bigint bigint", tableName));
    onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN float_to_double float_to_double double", tableName));
    assertThat(query("SHOW COLUMNS FROM " + tableName).project(1, 2)).containsExactly(row("int_to_bigint", "bigint"), row("float_to_double", "double"), row("id", "bigint"));
    QueryResult queryResult = query("SELECT * FROM " + tableName);
    assertThat(queryResult).hasColumns(BIGINT, DOUBLE, BIGINT);
    assertThat(queryResult).containsOnly(row(2323L, 0.5, 1), row(-2323L, -1.5, 1));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Requires(io.prestodb.tempto.Requires) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 84 with QueryResult

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

the class TestHivePartitionsTable method testShowPartitionsFromHiveTable.

@Test(groups = { HIVE_PARTITIONING })
public void testShowPartitionsFromHiveTable() {
    String tableNameInDatabase = tablesState.get(PARTITIONED_TABLE).getNameInDatabase();
    String partitionsTable = "\"" + tableNameInDatabase + "$partitions\"";
    QueryResult partitionListResult;
    partitionListResult = query("SELECT * FROM " + partitionsTable);
    assertThat(partitionListResult).containsExactly(row(1), row(2));
    assertColumnNames(partitionListResult, "part_col");
    partitionListResult = query(format("SELECT * FROM %s WHERE part_col = 1", partitionsTable));
    assertThat(partitionListResult).containsExactly(row(1));
    assertColumnNames(partitionListResult, "part_col");
    assertThat(() -> query(format("SELECT * FROM %s WHERE no_such_column = 1", partitionsTable))).failsWithMessage("Column 'no_such_column' cannot be resolved");
    assertThat(() -> query(format("SELECT * FROM %s WHERE col = 1", partitionsTable))).failsWithMessage("Column 'col' cannot be resolved");
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 85 with QueryResult

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

the class TestHivePartitionsTable method testShowPartitionsFromHiveTableWithTooManyPartitions.

@Test(groups = { HIVE_PARTITIONING })
public void testShowPartitionsFromHiveTableWithTooManyPartitions() {
    String tableName = tablesState.get(PARTITIONED_TABLE_WITH_VARIABLE_PARTITIONS).getNameInDatabase();
    String partitionsTable = "\"" + tableName + "$partitions\"";
    createPartitions(tableName, TOO_MANY_PARTITIONS);
    // Verify we created enough partitions for the test to be meaningful
    assertThatThrownBy(() -> query("SELECT * FROM " + tableName)).hasMessageMatching(".*: Query over table '\\S+' can potentially read more than \\d+ partitions");
    QueryResult partitionListResult;
    partitionListResult = query(format("SELECT * FROM %s WHERE part_col < 7", partitionsTable));
    assertThat(partitionListResult).containsExactly(row(0), row(1), row(2), row(3), row(4), row(5), row(6));
    assertColumnNames(partitionListResult, "part_col");
    partitionListResult = query(format("SELECT * FROM %s WHERE part_col < -10", partitionsTable));
    assertThat(partitionListResult).hasNoRows();
    partitionListResult = query(format("SELECT * FROM %s ORDER BY part_col LIMIT 7", partitionsTable));
    assertThat(partitionListResult).containsExactly(row(0), row(1), row(2), row(3), row(4), row(5), row(6));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

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