Search in sources :

Example 56 with QueryResult

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

the class TestSelect method testSelectClusteringMaterializedView.

@Test(groups = CASSANDRA)
public void testSelectClusteringMaterializedView() {
    String mvName = "clustering_mv";
    onCassandra(format("DROP MATERIALIZED VIEW IF EXISTS %s.%s", KEY_SPACE, mvName));
    onCassandra(format("CREATE MATERIALIZED VIEW %s.%s AS " + "SELECT * FROM %s.%s " + "WHERE s_nationkey IS NOT NULL " + "PRIMARY KEY (s_nationkey, s_suppkey) " + "WITH CLUSTERING ORDER BY (s_nationkey DESC)", KEY_SPACE, mvName, KEY_SPACE, CASSANDRA_SUPPLIER.getName()));
    assertContainsEventually(() -> query(format("SHOW TABLES FROM %s.%s", CONNECTOR_NAME, KEY_SPACE)), query(format("SELECT '%s'", mvName)), new Duration(1, MINUTES));
    // Materialized view may not return all results during the creation
    assertContainsEventually(() -> query(format("SELECT status_replicated FROM %s.system.built_views WHERE view_name = '%s'", CONNECTOR_NAME, mvName)), query("SELECT true"), new Duration(1, MINUTES));
    QueryResult aggregateQueryResult = onPresto().executeQuery(format("SELECT MAX(s_nationkey), SUM(s_suppkey), AVG(s_acctbal) " + "FROM %s.%s.%s WHERE s_suppkey BETWEEN 1 AND 10 ", CONNECTOR_NAME, KEY_SPACE, mvName));
    assertThat(aggregateQueryResult).containsOnly(row(24, 55, 4334.653));
    QueryResult orderedResult = onPresto().executeQuery(format("SELECT s_nationkey, s_suppkey, s_acctbal " + "FROM %s.%s.%s WHERE s_nationkey = 1 LIMIT 1", CONNECTOR_NAME, KEY_SPACE, mvName));
    assertThat(orderedResult).containsOnly(row(1, 3, 4192.4));
    onCassandra(format("DROP MATERIALIZED VIEW IF EXISTS %s.%s", KEY_SPACE, mvName));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 57 with QueryResult

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

the class TestSelect method testSelectNation.

@Test(groups = CASSANDRA)
public void testSelectNation() {
    String sql = format("SELECT n_nationkey, n_name, n_regionkey, n_comment FROM %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_NATION.getName());
    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 58 with QueryResult

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

the class TestSelectMultiColumnKey method testSelectWithEqualityFilterOnPrimaryAndClusteringKeys.

@Test(groups = CASSANDRA)
public void testSelectWithEqualityFilterOnPrimaryAndClusteringKeys() {
    String sql = format("SELECT value FROM %s.%s.%s WHERE user_id = 'Alice' and key = 'a1' and updated_at = TIMESTAMP '2015-01-01 01:01:01'", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MULTI_COLUMN_KEY.getName());
    QueryResult queryResult = onPresto().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("Test value 1"));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 59 with QueryResult

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

the class TestSelectMultiColumnKey method testSelectWithMixedFilterOnPrimaryAndClusteringKeys.

@Test(groups = CASSANDRA)
public void testSelectWithMixedFilterOnPrimaryAndClusteringKeys() {
    String sql = format("SELECT value FROM %s.%s.%s WHERE user_id = 'Alice' and key < 'b' and updated_at >= TIMESTAMP '2015-01-01 01:01:01'", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MULTI_COLUMN_KEY.getName());
    QueryResult queryResult = onPresto().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("Test value 1"));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 60 with QueryResult

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

the class TestSelectMultiColumnKey method testSelectWithEqualityFilterOnClusteringKey.

@Test(groups = CASSANDRA)
public void testSelectWithEqualityFilterOnClusteringKey() {
    String sql = format("SELECT value FROM %s.%s.%s WHERE key = 'a1'", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MULTI_COLUMN_KEY.getName());
    QueryResult queryResult = onPresto().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("Test value 1"));
}
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