Skip to content

Commit

Permalink
Test partition key pushdown predicate for all supported types
Browse files Browse the repository at this point in the history
  • Loading branch information
findinpath authored and ebyhr committed Feb 3, 2022
1 parent 4d48bfc commit a57c6c7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public final class CassandraTestingUtils
public static final String TABLE_ALL_TYPES_INSERT = "table_all_types_insert";
public static final String TABLE_ALL_TYPES_PARTITION_KEY = "table_all_types_partition_key";
public static final String TABLE_PUSHDOWN_UUID_PARTITION_KEY_PREDICATE = "table_pushdown_uuid_partition_key_predicate";
public static final String TABLE_PUSHDOWN_ALL_TYPES_PARTITION_KEY_PREDICATE = "table_pushdown_all_types_partition_key_predicate";
public static final String TABLE_TUPLE_TYPE = "table_tuple_type";
public static final String TABLE_USER_DEFINED_TYPE = "table_user_defined_type";
public static final String TABLE_CLUSTERING_KEYS = "table_clustering_keys";
Expand All @@ -55,6 +56,7 @@ public static void createTestTables(CassandraSession cassandraSession, String ke
createTableAllTypes(cassandraSession, new SchemaTableName(keyspace, TABLE_ALL_TYPES_INSERT), date, 0);
createTableAllTypesPartitionKey(cassandraSession, new SchemaTableName(keyspace, TABLE_ALL_TYPES_PARTITION_KEY), date);
createTablePushdownUuidPartitionKey(cassandraSession, new SchemaTableName(keyspace, TABLE_PUSHDOWN_UUID_PARTITION_KEY_PREDICATE));
createTablePushdownAllTypesPartitionKey(cassandraSession, new SchemaTableName(keyspace, TABLE_PUSHDOWN_ALL_TYPES_PARTITION_KEY_PREDICATE), date);
createTableTupleType(cassandraSession, new SchemaTableName(keyspace, TABLE_TUPLE_TYPE));
createTableUserDefinedType(cassandraSession, new SchemaTableName(keyspace, TABLE_USER_DEFINED_TYPE));
createTableClusteringKeys(cassandraSession, new SchemaTableName(keyspace, TABLE_CLUSTERING_KEYS), 9);
Expand Down Expand Up @@ -248,6 +250,54 @@ public static void createTablePushdownUuidPartitionKey(CassandraSession session,
session.execute("INSERT INTO " + table + "(col_uuid, col_text) VALUES (00000000-0000-0000-0000-000000000001, 'Trino')");
}

public static void createTablePushdownAllTypesPartitionKey(CassandraSession session, SchemaTableName table, Date date)
{
session.execute("DROP TABLE IF EXISTS " + table);

session.execute("CREATE TABLE " + table + " (" +
" key text, " +
" typeuuid uuid, " +
" typetinyint tinyint, " +
" typesmallint smallint, " +
" typeinteger int, " +
" typelong bigint, " +
" typebytes blob, " +
" typedate date, " +
" typetimestamp timestamp, " +
" typeansi ascii, " +
" typeboolean boolean, " +
" typedecimal decimal, " +
" typedouble double, " +
" typefloat float, " +
" typeinet inet, " +
" typevarchar varchar, " +
" typevarint varint, " +
" typetimeuuid timeuuid, " +
" typelist frozen <list<text>>, " +
" typemap frozen <map<int, bigint>>, " +
" typeset frozen <set<boolean>>, " +
" PRIMARY KEY ((" +
" key, " +
" typeuuid, " +
" typetinyint, " +
" typesmallint, " +
" typeinteger, " +
" typelong, " +
" typedate, " +
" typetimestamp, " +
" typeansi, " +
" typeboolean, " +
" typedouble, " +
" typefloat, " +
" typeinet, " +
" typevarchar, " +
" typetimeuuid" +
" ))" +
")");

insertTestData(session, table, date, 9);
}

public static void createTableTupleType(CassandraSession session, SchemaTableName table)
{
session.execute("DROP TABLE IF EXISTS " + table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static io.trino.plugin.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS_LARGE;
import static io.trino.plugin.cassandra.CassandraTestingUtils.TABLE_DELETE_DATA;
import static io.trino.plugin.cassandra.CassandraTestingUtils.TABLE_MULTI_PARTITION_CLUSTERING_KEYS;
import static io.trino.plugin.cassandra.CassandraTestingUtils.TABLE_PUSHDOWN_ALL_TYPES_PARTITION_KEY_PREDICATE;
import static io.trino.plugin.cassandra.CassandraTestingUtils.TABLE_PUSHDOWN_UUID_PARTITION_KEY_PREDICATE;
import static io.trino.plugin.cassandra.CassandraTestingUtils.createTestTables;
import static io.trino.spi.type.BigintType.BIGINT;
Expand Down Expand Up @@ -245,6 +246,33 @@ public void testPushdownUuidPartitionKeyPredicate()
.matches("VALUES CAST('Trino' AS varchar)");
}

@Test
public void testPushdownAllTypesPartitionKeyPredicate()
{
// TODO partition key predicate pushdown for decimal types does not work https://github.com/trinodb/trino/issues/10927
String sql = "SELECT *" +
" FROM " + TABLE_PUSHDOWN_ALL_TYPES_PARTITION_KEY_PREDICATE +
" WHERE key = 'key 7'" +
" AND typeuuid = UUID '00000000-0000-0000-0000-000000000007'" +
" AND typetinyint = 7" +
" AND typesmallint = 7" +
" AND typeinteger = 7" +
" AND typelong = 1007" +
" AND typedate = DATE '1970-01-01'" +
" AND typetimestamp = TIMESTAMP '1970-01-01 03:04:05Z'" +
" AND typeansi = 'ansi 7'" +
" AND typeboolean = false" +
" AND typedouble = 16384.0" +
" AND typefloat = REAL '2097152.0'" +
" AND typeinet = '127.0.0.1'" +
" AND typevarchar = 'varchar 7'" +
" AND typetimeuuid = UUID 'd2177dd0-eaa2-11de-a572-001b779c76e7'" +
"";
MaterializedResult result = execute(sql);

assertEquals(result.getRowCount(), 1);
}

@Test
public void testPartitionKeyPredicate()
{
Expand Down

0 comments on commit a57c6c7

Please sign in to comment.