Search in sources :

Example 1 with TableName

use of io.trino.tempto.internal.fulfillment.table.TableName in project trino by trinodb.

the class TestInsertIntoCassandraTable method testInsertIntoValuesToCassandraTableAllSimpleTypes.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testInsertIntoValuesToCassandraTableAllSimpleTypes() {
    TableName table = mutableTablesState().get(CASSANDRA_INSERT_TABLE).getTableName();
    String tableNameInDatabase = format("%s.%s", CONNECTOR_NAME, table.getNameInDatabase());
    assertContainsEventually(() -> onTrino().executeQuery(format("SHOW TABLES FROM %s.%s", CONNECTOR_NAME, KEY_SPACE)), onTrino().executeQuery(format("SELECT '%s'", table.getSchemalessNameInDatabase())), new Duration(1, MINUTES));
    QueryResult queryResult = onTrino().executeQuery("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>, decimal, varint
    onTrino().executeQuery("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:59Z'," + "uuid '50554d6e-29bb-11e5-b345-feff819cdc9f', " + "uuid '12151fd2-7586-11e9-8f9e-2a86e4085a59', " + "'varchar value'," + "null)");
    assertThat(onTrino().executeQuery("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.from(OffsetDateTime.of(9999, 12, 31, 23, 59, 59, 0, ZoneOffset.UTC).toInstant()), "50554d6e-29bb-11e5-b345-feff819cdc9f", "12151fd2-7586-11e9-8f9e-2a86e4085a59", "varchar value", null));
    // insert null for all datatypes
    onTrino().executeQuery("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(onTrino().executeQuery(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
    onTrino().executeQuery(format("INSERT INTO %s (a, bo, integer, t) VALUES ('key 2', false, 999, 'text 2')", tableNameInDatabase));
    assertThat(onTrino().executeQuery(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
    assertQueryFailure(() -> onTrino().executeQuery(format("INSERT INTO %s (a) VALUES (null) ", tableNameInDatabase))).hasMessageContaining("Invalid null value in condition for column a");
}
Also used : TableName(io.trino.tempto.internal.fulfillment.table.TableName) QueryResult(io.trino.tempto.query.QueryResult) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 2 with TableName

use of io.trino.tempto.internal.fulfillment.table.TableName in project trino by trinodb.

the class TestInsertIntoCassandraTable method testInsertIntoValuesToCassandraMaterizedView.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testInsertIntoValuesToCassandraMaterizedView() {
    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(() -> onTrino().executeQuery(format("SHOW TABLES FROM %s.%s", CONNECTOR_NAME, KEY_SPACE)), onTrino().executeQuery(format("SELECT lower('%s')", CASSANDRA_MATERIALIZED_VIEW)), new Duration(1, MINUTES));
    assertQueryFailure(() -> onTrino().executeQuery(format("INSERT INTO %s.%s.%s (a) VALUES (null) ", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW))).hasMessageContaining("Inserting into materialized views not yet supported");
    assertQueryFailure(() -> onTrino().executeQuery(format("DROP TABLE %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW))).hasMessageContaining("Dropping materialized views not yet supported");
    onCasssandra(format("DROP MATERIALIZED VIEW IF EXISTS %s.%s", KEY_SPACE, CASSANDRA_MATERIALIZED_VIEW));
}
Also used : TableName(io.trino.tempto.internal.fulfillment.table.TableName) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Aggregations

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