Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct decoding for Trino UUID partition key value #10856

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import static io.trino.spi.type.DateTimeEncoding.unpackMillisUtc;
import static io.trino.spi.type.TypeUtils.writeNativeValue;
import static io.trino.spi.type.UuidType.javaUuidToTrinoUuid;
import static io.trino.spi.type.UuidType.trinoUuidToJavaUuid;
import static java.lang.Float.floatToRawIntBits;
import static java.lang.Float.intBitsToFloat;
import static java.lang.Math.toIntExact;
Expand Down Expand Up @@ -561,7 +562,7 @@ public Object getJavaValue(Object trinoNativeValue)
return LocalDate.fromDaysSinceEpoch(((Long) trinoNativeValue).intValue());
case UUID:
case TIMEUUID:
return java.util.UUID.fromString(((Slice) trinoNativeValue).toStringUtf8());
return trinoUuidToJavaUuid((Slice) trinoNativeValue);
case BLOB:
case CUSTOM:
case TUPLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public final class CassandraTestingUtils
public static final String TABLE_ALL_TYPES = "table_all_types";
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 @@ -53,6 +55,8 @@ public static void createTestTables(CassandraSession cassandraSession, String ke
createTableAllTypes(cassandraSession, new SchemaTableName(keyspace, TABLE_ALL_TYPES), date, 9);
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 @@ -237,6 +241,63 @@ public static void createTableAllTypesPartitionKey(CassandraSession session, Sch
insertTestData(session, table, date, 9);
}

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

session.execute("CREATE TABLE " + table + " (col_uuid uuid PRIMARY KEY, col_text text)");

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, " +
Copy link
Contributor Author

@findinpath findinpath Jan 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've skipped (in this initial commit) on purpose adding the typedecimal field to the composed primary key because the test is failing. Apparently in Cassandra 2.2 when comparing 128.0 with 128 there is no match found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you file an issue and leave as code comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #10927 and referenced it in the new test.

" 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,8 @@
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;
import static io.trino.spi.type.BooleanType.BOOLEAN;
Expand Down Expand Up @@ -237,6 +239,40 @@ public void testCharVarcharComparison()
.hasMessage("unsupported type: char(3)");
}

@Test
public void testPushdownUuidPartitionKeyPredicate()
{
assertThat(query(format("SELECT col_text FROM %s.%s WHERE col_uuid = UUID '00000000-0000-0000-0000-000000000001'", KEYSPACE, TABLE_PUSHDOWN_UUID_PARTITION_KEY_PREDICATE)))
.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