Search in sources :

Example 1 with TableName

use of io.prestodb.tempto.internal.fulfillment.table.TableName in project presto by prestodb.

the class TestInsertIntoCassandraTable method testInsertIntoValuesToCassandraMaterizedView.

@Test(groups = CASSANDRA)
public void testInsertIntoValuesToCassandraMaterizedView() throws Exception {
    TableName table = mutableTablesState().get(CASSANDRA_INSERT_TABLE).getTableName();
    onCasssandra(format("DROP MATERIALIZED VIEW IF EXISTS %s.%s", KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW));
    onCasssandra(format("CREATE MATERIALIZED VIEW %s.%s AS " + "SELECT * FROM %s " + "WHERE b IS NOT NULL " + "PRIMARY KEY (a, b) " + "WITH CLUSTERING ORDER BY (integer DESC)", KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW, table.getNameInDatabase()));
    assertContainsEventually(() -> query(format("SHOW TABLES FROM %s.%s", CONNECTOR_NAME, KEY_SPACE)), query(format("SELECT lower('%s')", CASSANDRA_MATERIALIZED_VIEW)), new Duration(1, MINUTES));
    assertThat(() -> query(format("INSERT INTO %s.%s.%s (a) VALUES (null) ", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW))).failsWithMessage("Inserting into materialized views not yet supported");
    assertThat(() -> query(format("DROP TABLE %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW))).failsWithMessage("Dropping materialized views not yet supported");
    onCasssandra(format("DROP MATERIALIZED VIEW IF EXISTS %s.%s", KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW));
}
Also used : TableName(io.prestodb.tempto.internal.fulfillment.table.TableName) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 2 with TableName

use of io.prestodb.tempto.internal.fulfillment.table.TableName in project presto by prestodb.

the class TestInsertIntoCassandraTable method testInsertIntoValuesToCassandraTableAllSimpleTypes.

@Test(groups = CASSANDRA)
public void testInsertIntoValuesToCassandraTableAllSimpleTypes() {
    TableName table = mutableTablesState().get(CASSANDRA_INSERT_TABLE).getTableName();
    String tableNameInDatabase = String.format("%s.%s", CONNECTOR_NAME, table.getNameInDatabase());
    assertContainsEventually(() -> query(format("SHOW TABLES FROM %s.%s", CONNECTOR_NAME, KEY_SPACE)), query(format("SELECT '%s'", table.getSchemalessNameInDatabase())), new Duration(1, MINUTES));
    QueryResult queryResult = query("SELECT * FROM " + tableNameInDatabase);
    assertThat(queryResult).hasNoRows();
    // TODO Following types are not supported now. We need to change null into the value after fixing it
    // blob, frozen<set<type>>, inet, list<type>, map<type,type>, set<type>, timeuuid, decimal, uuid, varint
    query("INSERT INTO " + tableNameInDatabase + "(a, b, bl, bo, d, do, dt, f, fr, i, ti, si, integer, l, m, s, t, ts, tu, u, v, vari) VALUES (" + "'ascii value', " + "BIGINT '99999', " + "null, " + "true, " + "null, " + "123.456789, " + "DATE '9999-12-31'," + "REAL '123.45678', " + "null, " + "null, " + "TINYINT '-128', " + "SMALLINT '-32768', " + "123, " + "null, " + "null, " + "null, " + "'text value', " + "timestamp '9999-12-31 23:59:59'," + "null, " + "null, " + "'varchar value'," + "null)");
    assertThat(query("SELECT * FROM " + tableNameInDatabase)).containsOnly(row("ascii value", 99999, null, true, null, 123.456789, Date.valueOf("9999-12-31"), 123.45678, null, null, 123, null, null, null, -32768, "text value", -128, Timestamp.valueOf(LocalDateTime.of(9999, 12, 31, 23, 59, 59)), null, null, "varchar value", null));
    // insert null for all datatypes
    query("INSERT INTO " + tableNameInDatabase + "(a, b, bl, bo, d, do, dt, f, fr, i, ti, si, integer, l, m, s, t, ts, tu, u, v, vari) VALUES (" + "'key 1', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null) ");
    assertThat(query(format("SELECT * FROM %s WHERE a = 'key 1'", tableNameInDatabase))).containsOnly(row("key 1", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
    // insert into only a subset of columns
    query(format("INSERT INTO %s (a, bo, integer, t) VALUES ('key 2', false, 999, 'text 2')", tableNameInDatabase));
    assertThat(query(format("SELECT * FROM %s WHERE a = 'key 2'", tableNameInDatabase))).containsOnly(row("key 2", null, null, false, null, null, null, null, null, null, 999, null, null, null, null, "text 2", null, null, null, null, null, null));
    // negative test: failed to insert null to primary key
    assertThat(() -> query(format("INSERT INTO %s (a) VALUES (null) ", tableNameInDatabase))).failsWithMessage("Invalid null value in condition for column a");
}
Also used : TableName(io.prestodb.tempto.internal.fulfillment.table.TableName) QueryResult(io.prestodb.tempto.query.QueryResult) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Aggregations

Duration (io.airlift.units.Duration)2 ProductTest (io.prestodb.tempto.ProductTest)2 TableName (io.prestodb.tempto.internal.fulfillment.table.TableName)2 Test (org.testng.annotations.Test)2 QueryResult (io.prestodb.tempto.query.QueryResult)1