Skip to content

Commit

Permalink
Migrate Cassandra product test to integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Nov 4, 2024
1 parent 2d2756a commit e9e3ab4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ public void testPushdownUuidPartitionKeyPredicate()
}
}

@Test
public void testSelectWithFilterOnPartitioningKey()
{
try (TestCassandraTable table = testTable(
"table_filter_on_partition_key",
ImmutableList.of(generalColumn("id", "int"), partitionColumn("part", "int")),
ImmutableList.of("1, 10", "2, 20"))) {
// predicate on partition column
assertThat(query("SELECT id FROM " + table.getTableName() + " WHERE part > 10"))
.matches("VALUES 2");

// predicate on non-partition column
assertThat(query("SELECT id FROM " + table.getTableName() + " WHERE id = 1"))
.matches("VALUES 1");
assertThat(query("SELECT id FROM " + table.getTableName() + " WHERE id < 2"))
.matches("VALUES 1");
}
}

@Test
public void testPushdownAllTypesPartitionKeyPredicate()
{
Expand Down Expand Up @@ -1671,6 +1690,31 @@ protected void verifyTableNameLengthFailurePermissible(Throwable e)
assertThat(e).hasMessageContaining("Table names shouldn't be more than 48 characters long");
}

@Test
public void testNationJoinNation()
{
assertQuery("SELECT n1.name, n2.regionkey " +
"FROM nation n1 JOIN nation n2 ON n1.nationkey = n2.regionkey " +
"WHERE n1.nationkey = 3",
"VALUES ('CANADA', 3), ('CANADA', 3), ('CANADA', 3), ('CANADA', 3), ('CANADA', 3)");
}

@Test
public void testNationJoinRegion()
{
assertQuery("SELECT c.name, t.name " +
"FROM nation c JOIN tpch.tiny.region t ON c.regionkey = t.regionkey " +
"WHERE c.nationkey = 3",
"VALUES ('CANADA', 'AMERICA')");
}

@Test
public void testProtocolVersion()
{
assertQuery("SELECT native_protocol_version FROM system.local",
"VALUES 4");
}

private void assertSelect(String tableName)
{
String sql = "SELECT " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@ public final class CassandraTpchTableDefinitions
{
private CassandraTpchTableDefinitions() {}

public static final ImmutableList<JDBCType> NATION_TYPES = ImmutableList.of(BIGINT, VARCHAR, BIGINT, VARCHAR);

// TpchTable.NATION does provide data in order: nationkey, name, regionkey, comment. Unfortunately Cassandra reorders columns,
// so schema will be: nationkey, comment, name, regionkey (primary key first - nationkey, then alphabetical order: comment, name, regionkey)
// reordering is solved by providing mapping list
public static final CassandraTableDefinition CASSANDRA_NATION = CassandraTableDefinition.cassandraBuilder("nation")
.withDatabase(CONNECTOR_NAME)
.withSchema(KEY_SPACE)
.setCreateTableDDLTemplate("CREATE TABLE %NAME%(" +
" n_nationkey BIGINT," +
" n_name VARCHAR," +
" n_regionkey BIGINT," +
" n_comment VARCHAR," +
" primary key(n_nationkey))")
.setDataSource(new CassandraTpchDataSource(TpchTable.NATION, ImmutableList.of(0, 2, 3, 1), NATION_TYPES, 1.0))
.build();

public static final ImmutableList<JDBCType> SUPPLIER_TYPES = ImmutableList.of(BIGINT, VARCHAR, VARCHAR, BIGINT, VARCHAR, DOUBLE, VARCHAR);
public static final CassandraTableDefinition CASSANDRA_SUPPLIER = CassandraTableDefinition.cassandraBuilder("supplier")
.withDatabase(CONNECTOR_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,18 @@
import io.trino.tempto.query.QueryResult;
import org.testng.annotations.Test;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.function.Consumer;

import static io.trino.tempto.Requirements.compose;
import static io.trino.tempto.assertions.QueryAssert.Row.row;
import static io.trino.tempto.fulfillment.table.TableRequirements.immutableTable;
import static io.trino.tests.product.TestGroups.CASSANDRA;
import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS;
import static io.trino.tests.product.TpchTableResults.TRINO_NATION_RESULT;
import static io.trino.tests.product.cassandra.CassandraTpchTableDefinitions.CASSANDRA_NATION;
import static io.trino.tests.product.cassandra.CassandraTpchTableDefinitions.CASSANDRA_SUPPLIER;
import static io.trino.tests.product.cassandra.TestConstants.CONNECTOR_NAME;
import static io.trino.tests.product.cassandra.TestConstants.KEY_SPACE;
import static io.trino.tests.product.utils.QueryAssertions.assertContainsEventually;
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -54,79 +48,7 @@ public class TestSelect
public Requirement getRequirements(Configuration configuration)
{
this.configuration = configuration;
return compose(
immutableTable(CASSANDRA_NATION),
immutableTable(CASSANDRA_SUPPLIER));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
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 = onTrino()
.executeQuery(sql);

assertThat(queryResult).matches(TRINO_NATION_RESULT);
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectWithEqualityFilterOnPartitioningKey()
{
String sql = format(
"SELECT n_nationkey FROM %s.%s.%s WHERE n_nationkey = 0",
CONNECTOR_NAME,
KEY_SPACE,
CASSANDRA_NATION.getName());
QueryResult queryResult = onTrino()
.executeQuery(sql);

assertThat(queryResult).containsOnly(row(0));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectWithFilterOnPartitioningKey()
{
String sql = format(
"SELECT n_nationkey FROM %s.%s.%s WHERE n_nationkey > 23",
CONNECTOR_NAME,
KEY_SPACE,
CASSANDRA_NATION.getName());
QueryResult queryResult = onTrino()
.executeQuery(sql);

assertThat(queryResult).containsOnly(row(24));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectWithEqualityFilterOnNonPartitioningKey()
{
String sql = format(
"SELECT n_name FROM %s.%s.%s WHERE n_name = 'UNITED STATES'",
CONNECTOR_NAME,
KEY_SPACE,
CASSANDRA_NATION.getName());
QueryResult queryResult = onTrino()
.executeQuery(sql);

assertThat(queryResult).containsOnly(row("UNITED STATES"));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectWithNonEqualityFilterOnNonPartitioningKey()
{
String sql = format(
"SELECT n_name FROM %s.%s.%s WHERE n_name < 'B'",
CONNECTOR_NAME,
KEY_SPACE,
CASSANDRA_NATION.getName());
QueryResult queryResult = onTrino()
.executeQuery(sql);

assertThat(queryResult).containsOnly(row("ALGERIA"), row("ARGENTINA"));
return immutableTable(CASSANDRA_SUPPLIER);
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
Expand Down Expand Up @@ -157,43 +79,6 @@ public void testSelectWithMorePartitioningKeysThanLimitNonPK()
assertThat(queryResult).containsOnly(row(10));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testNationJoinNation()
{
String tableName = format("%s.%s.%s", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_NATION.getName());
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",
tableName,
tableName);
QueryResult queryResult = onTrino()
.executeQuery(sql);

assertThat(queryResult).containsOnly(
row("CANADA", 3),
row("CANADA", 3),
row("CANADA", 3),
row("CANADA", 3),
row("CANADA", 3));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testNationJoinRegion()
{
String sql = format(
"SELECT c.n_name, t.name FROM %s.%s.%s c JOIN " +
"tpch.tiny.region t ON c.n_regionkey = t.regionkey " +
"WHERE c.n_nationkey=3",
CONNECTOR_NAME,
KEY_SPACE,
CASSANDRA_NATION.getName());
QueryResult queryResult = onTrino()
.executeQuery(sql);

assertThat(queryResult).containsOnly(row("CANADA", "AMERICA"));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectClusteringMaterializedView()
{
Expand Down Expand Up @@ -235,38 +120,6 @@ public void testSelectClusteringMaterializedView()
onCassandra(format("DROP MATERIALIZED VIEW IF EXISTS %s.%s", KEY_SPACE, mvName));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testProtocolVersion()
{
QueryResult queryResult = onTrino()
.executeQuery(format("SELECT native_protocol_version FROM %s.system.local", CONNECTOR_NAME));
assertThat(queryResult).containsOnly(row("4"));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectTupleType()
{
String tableName = "select_tuple_table";
onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));

onCassandra(format("CREATE TABLE %s.%s (key int, value frozen<tuple<int, text, float>>, PRIMARY KEY (key))",
KEY_SPACE, tableName));

onCassandra(format("INSERT INTO %s.%s (key, value) VALUES(1, (1, 'text-1', 1.11))", KEY_SPACE, tableName));

QueryResult queryResult = onTrino().executeQuery(
format("SELECT * FROM %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, tableName));
assertThat(queryResult).hasRowsCount(1);
assertThat(queryResult.row(0).get(0)).isEqualTo(1);
assertThat(queryResult.row(0).get(1)).isEqualTo(Row.builder()
.addUnnamedField(1)
.addUnnamedField("text-1")
.addUnnamedField(1.11f)
.build());

onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectTupleTypeInPrimaryKey()
{
Expand All @@ -293,113 +146,6 @@ public void testSelectTupleTypeInPrimaryKey()
onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectUserDefinedType()
{
String udtName = "type_user_defined";
String tableName = "user_defined_type_table";

onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
onCassandra(format("DROP TYPE IF EXISTS %s.%s", KEY_SPACE, udtName));

onCassandra(format("" +
"CREATE TYPE %s.%s (" +
"t text, " +
"u uuid, " +
"integer int, " +
"b bigint, " +
"bl blob, " +
"ts timestamp, " +
"a ascii, " +
"bo boolean, " +
"d decimal, " +
"do double, " +
"f float, " +
"i inet, " +
"v varchar, " +
"vari varint, " +
"tu timeuuid, " +
"l frozen <list<text>>, " +
"m frozen <map<varchar, bigint>>, " +
"s frozen <set<boolean>> " +
")", KEY_SPACE, udtName));

onCassandra(format("" +
"CREATE TABLE %s.%s (" +
"key text PRIMARY KEY, " +
"typeudt frozen <%s>, " +
")", KEY_SPACE, tableName, udtName));

onCassandra(format("" +
"INSERT INTO %s.%s (key, typeudt) VALUES (" +
"'key'," +
"{ " +
"t: 'text', " +
"u: 01234567-0123-0123-0123-0123456789ab, " +
"integer: -2147483648, " +
"b: -9223372036854775808," +
"bl: 0x3031323334, " +
"ts: '1970-01-01 13:30:00.000', " +
"a: 'ansi', " +
"bo: true, " +
"d: 99999999999999997748809823456034029568, " +
"do: 4.9407e-324, " +
"f: 1.4013e-45, " +
"i: '0.0.0.0', " +
"v: 'varchar', " +
"vari: -9223372036854775808, " +
"tu: d2177dd0-eaa2-11de-a572-001b779c76e3, " +
"l: ['list'], " +
"m: {'map': 1}, " +
"s: {true} " +
"}" +
")", KEY_SPACE, tableName));

QueryResult queryResult = onTrino().executeQuery(format("" +
"SELECT " +
"typeudt.t, " +
"typeudt.u, " +
"typeudt.integer, " +
"typeudt.b, " +
"typeudt.bl, " +
"typeudt.ts, " +
"typeudt.a, " +
"typeudt.bo, " +
"typeudt.d, " +
"typeudt.do, " +
"typeudt.f, " +
"typeudt.i, " +
"typeudt.v, " +
"typeudt.vari, " +
"typeudt.tu, " +
"typeudt.l, " +
"typeudt.m, " +
"typeudt.s " +
"FROM %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, tableName));
assertThat(queryResult).containsOnly(row(
"text",
"01234567-0123-0123-0123-0123456789ab",
-2147483648,
-9223372036854775808L,
"01234".getBytes(UTF_8),
Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 13, 30)),
"ansi",
true,
99999999999999997748809823456034029568D,
4.9407e-324,
1.4E-45f,
"0.0.0.0",
"varchar",
"-9223372036854775808",
"d2177dd0-eaa2-11de-a572-001b779c76e3",
"[\"list\"]",
"{\"map\":1}",
"[true]"));

onCassandra(format("DROP TABLE %s.%s", KEY_SPACE, tableName));
onCassandra(format("DROP TYPE %s.%s", KEY_SPACE, udtName));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testSelectUserDefinedTypeInPrimaryKey()
{
Expand Down

0 comments on commit e9e3ab4

Please sign in to comment.