Skip to content
Merged
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 @@ -1003,27 +1003,30 @@ public void testUpperCaseNameUnescapedInCassandra()
*/
String uppercaseKeyspaceName = "KEYSPACE_1" + randomNameSuffix().toUpperCase(ENGLISH);
String lowercaseKeyspaceName = uppercaseKeyspaceName.toLowerCase(ENGLISH);
createKeyspace(uppercaseKeyspaceName);

assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(lowercaseKeyspaceName)
.build(), new Duration(1, MINUTES));
try {
createKeyspace(uppercaseKeyspaceName);

session.execute("CREATE TABLE " + uppercaseKeyspaceName + ".TABLE_1 (COLUMN_1 bigint PRIMARY KEY)");
assertContainsEventually(() -> computeActual("SHOW TABLES FROM cassandra." + lowercaseKeyspaceName), resultBuilder(getSession(), createUnboundedVarcharType())
.row("table_1")
.build(), new Duration(1, MINUTES));
assertContains(computeActual("SHOW COLUMNS FROM cassandra." + lowercaseKeyspaceName + ".table_1"), resultBuilder(getSession(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType())
.row("column_1", "bigint", "", "")
.build());
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(lowercaseKeyspaceName)
.build(), new Duration(1, MINUTES));

assertUpdate("INSERT INTO " + lowercaseKeyspaceName + ".table_1 (column_1) VALUES (1)", 1);
session.execute("CREATE TABLE " + uppercaseKeyspaceName + ".TABLE_1 (COLUMN_1 bigint PRIMARY KEY)");
assertContainsEventually(() -> computeActual("SHOW TABLES FROM cassandra." + lowercaseKeyspaceName), resultBuilder(getSession(), createUnboundedVarcharType())
.row("table_1")
.build(), new Duration(1, MINUTES));
assertContains(computeActual("SHOW COLUMNS FROM cassandra." + lowercaseKeyspaceName + ".table_1"), resultBuilder(getSession(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType())
.row("column_1", "bigint", "", "")
.build());

assertThat(computeActual("SELECT column_1 FROM cassandra." + lowercaseKeyspaceName + ".table_1").getRowCount()).isEqualTo(1);
assertUpdate("DROP TABLE cassandra." + lowercaseKeyspaceName + ".table_1");
assertUpdate("INSERT INTO " + lowercaseKeyspaceName + ".table_1 (column_1) VALUES (1)", 1);

// when an identifier is unquoted the lowercase and uppercase spelling may be used interchangeable
dropKeyspace(lowercaseKeyspaceName);
assertThat(computeActual("SELECT column_1 FROM cassandra." + lowercaseKeyspaceName + ".table_1").getRowCount()).isEqualTo(1);
assertUpdate("DROP TABLE cassandra." + lowercaseKeyspaceName + ".table_1");
}
finally {
// when an identifier is unquoted the lowercase and uppercase spelling may be used interchangeable
dropKeyspace(lowercaseKeyspaceName);
}
}

@Test
Expand All @@ -1036,27 +1039,30 @@ public void testUppercaseNameEscaped()
*/
String uppercaseKeyspaceName = "KEYSPACE_2%s".formatted(randomNameSuffix().toUpperCase(ENGLISH));
String quotedUppercaseKeyspaceName = "\"%s\"".formatted(uppercaseKeyspaceName);
createKeyspace(quotedUppercaseKeyspaceName);
String lowerCaseKeyspaceName = uppercaseKeyspaceName.toLowerCase(ENGLISH);
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(lowerCaseKeyspaceName)
.build(), new Duration(1, MINUTES));

session.execute("CREATE TABLE " + quotedUppercaseKeyspaceName + ".\"TABLE_2\" (\"COLUMN_2\" bigint PRIMARY KEY)");
assertContainsEventually(() -> computeActual("SHOW TABLES FROM cassandra." + lowerCaseKeyspaceName), resultBuilder(getSession(), createUnboundedVarcharType())
.row("table_2")
.build(), new Duration(1, MINUTES));
assertContains(computeActual("SHOW COLUMNS FROM cassandra.%s.table_2".formatted(lowerCaseKeyspaceName)), resultBuilder(getSession(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType())
.row("column_2", "bigint", "", "")
.build());
try {
createKeyspace(quotedUppercaseKeyspaceName);
String lowerCaseKeyspaceName = uppercaseKeyspaceName.toLowerCase(ENGLISH);
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(lowerCaseKeyspaceName)
.build(), new Duration(1, MINUTES));

assertUpdate("INSERT INTO " + quotedUppercaseKeyspaceName + ".\"TABLE_2\" (\"COLUMN_2\") VALUES (1)", 1);
session.execute("CREATE TABLE " + quotedUppercaseKeyspaceName + ".\"TABLE_2\" (\"COLUMN_2\" bigint PRIMARY KEY)");
assertContainsEventually(() -> computeActual("SHOW TABLES FROM cassandra." + lowerCaseKeyspaceName), resultBuilder(getSession(), createUnboundedVarcharType())
.row("table_2")
.build(), new Duration(1, MINUTES));
assertContains(computeActual("SHOW COLUMNS FROM cassandra.%s.table_2".formatted(lowerCaseKeyspaceName)), resultBuilder(getSession(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType())
.row("column_2", "bigint", "", "")
.build());

assertThat(computeActual("SELECT column_2 FROM cassandra.%s.table_2".formatted(lowerCaseKeyspaceName)).getRowCount()).isEqualTo(1);
assertUpdate("DROP TABLE cassandra.%s.table_2".formatted(lowerCaseKeyspaceName));
assertUpdate("INSERT INTO " + quotedUppercaseKeyspaceName + ".\"TABLE_2\" (\"COLUMN_2\") VALUES (1)", 1);

// when an identifier is unquoted the lowercase and uppercase spelling may be used interchangeable
dropKeyspace(quotedUppercaseKeyspaceName);
assertThat(computeActual("SELECT column_2 FROM cassandra.%s.table_2".formatted(lowerCaseKeyspaceName)).getRowCount()).isEqualTo(1);
assertUpdate("DROP TABLE cassandra.%s.table_2".formatted(lowerCaseKeyspaceName));
}
finally {
// when an identifier is unquoted the lowercase and uppercase spelling may be used interchangeable
dropKeyspace(quotedUppercaseKeyspaceName);
}
}

@Test
Expand All @@ -1074,24 +1080,27 @@ public void testKeyspaceNameAmbiguity()
String quotedKeyspaceMixedCaseName1 = "\"%s\"".formatted(mixedCaseKeyspaceName1);
String quotedKeyspaceMixedCaseName2 = "\"%s\"".formatted(mixedCaseKeyspaceName2);

createKeyspace(quotedKeyspaceMixedCaseName1);
createKeyspace(quotedKeyspaceMixedCaseName2);

// Although in Trino all the schema and table names are always displayed as lowercase
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(lowercaseKeyspaceName)
.row(lowercaseKeyspaceName)
.build(), new Duration(1, MINUTES));

// There is no way to figure out what the exactly keyspace we want to retrieve tables from
assertQueryFailsEventually(
"SHOW TABLES FROM cassandra.%s".formatted(lowercaseKeyspaceName),
"Error listing tables for catalog cassandra: More than one keyspace has been found for the case insensitive schema name: %s -> \\(%s, %s\\)"
.formatted(lowercaseKeyspaceName, mixedCaseKeyspaceName1, mixedCaseKeyspaceName2),
new Duration(1, MINUTES));

dropKeyspace(quotedKeyspaceMixedCaseName1);
dropKeyspace(quotedKeyspaceMixedCaseName2);
try {
createKeyspace(quotedKeyspaceMixedCaseName1);
createKeyspace(quotedKeyspaceMixedCaseName2);

// Although in Trino all the schema and table names are always displayed as lowercase
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(lowercaseKeyspaceName)
.row(lowercaseKeyspaceName)
.build(), new Duration(1, MINUTES));

// There is no way to figure out what the exactly keyspace we want to retrieve tables from
assertQueryFailsEventually(
"SHOW TABLES FROM cassandra.%s".formatted(lowercaseKeyspaceName),
"Error listing tables for catalog cassandra: More than one keyspace has been found for the case insensitive schema name: %s -> \\(%s, %s\\)"
.formatted(lowercaseKeyspaceName, mixedCaseKeyspaceName1, mixedCaseKeyspaceName2),
new Duration(1, MINUTES));
}
finally {
dropKeyspace(quotedKeyspaceMixedCaseName1);
dropKeyspace(quotedKeyspaceMixedCaseName2);
}
// Wait until the schema becomes invisible to Trino. Otherwise, testSelectInformationSchemaColumns may fail due to ambiguous schema names.
assertEventually(() -> assertThat(computeActual("SHOW SCHEMAS FROM cassandra").getOnlyColumnAsSet())
.doesNotContain(lowercaseKeyspaceName));
Expand Down Expand Up @@ -1349,31 +1358,34 @@ public void testEmptyTimestampClusteringKey()
public void testNestedCollectionType()
{
String keyspaceName = "keyspace_test_nested_collection" + randomNameSuffix();
createKeyspace(keyspaceName);
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(keyspaceName)
.build(), new Duration(1, MINUTES));

session.execute("CREATE TABLE " + keyspaceName + ".table_set (column_5 bigint PRIMARY KEY, nested_collection frozen<set<set<bigint>>>)");
session.execute("CREATE TABLE " + keyspaceName + ".table_list (column_5 bigint PRIMARY KEY, nested_collection frozen<list<list<bigint>>>)");
session.execute("CREATE TABLE " + keyspaceName + ".table_map (column_5 bigint PRIMARY KEY, nested_collection frozen<map<int, map<bigint, bigint>>>)");
try {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we don't need to create a new schema in this test. Can we create a table in the default namespace instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ya instead we will have randomize the tables. I will address that as a followup. can we merge this PR?

createKeyspace(keyspaceName);
assertContainsEventually(() -> computeActual("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType())
.row(keyspaceName)
.build(), new Duration(1, MINUTES));

assertContainsEventually(() -> computeActual("SHOW TABLES FROM cassandra." + keyspaceName), resultBuilder(getSession(), createUnboundedVarcharType())
.row("table_set")
.row("table_list")
.row("table_map")
.build(), new Duration(1, MINUTES));
session.execute("CREATE TABLE " + keyspaceName + ".table_set (column_5 bigint PRIMARY KEY, nested_collection frozen<set<set<bigint>>>)");
session.execute("CREATE TABLE " + keyspaceName + ".table_list (column_5 bigint PRIMARY KEY, nested_collection frozen<list<list<bigint>>>)");
session.execute("CREATE TABLE " + keyspaceName + ".table_map (column_5 bigint PRIMARY KEY, nested_collection frozen<map<int, map<bigint, bigint>>>)");

session.execute("INSERT INTO " + keyspaceName + ".table_set (column_5, nested_collection) VALUES (1, {{1, 2, 3}})");
assertThat(computeActual("SELECT nested_collection FROM cassandra." + keyspaceName + ".table_set").getMaterializedRows().get(0)).isEqualTo(new MaterializedRow(DEFAULT_PRECISION, "[[1,2,3]]"));
assertContainsEventually(() -> computeActual("SHOW TABLES FROM cassandra." + keyspaceName), resultBuilder(getSession(), createUnboundedVarcharType())
.row("table_set")
.row("table_list")
.row("table_map")
.build(), new Duration(1, MINUTES));

session.execute("INSERT INTO " + keyspaceName + ".table_list (column_5, nested_collection) VALUES (1, [[4, 5, 6]])");
assertThat(computeActual("SELECT nested_collection FROM cassandra." + keyspaceName + ".table_list").getMaterializedRows().get(0)).isEqualTo(new MaterializedRow(DEFAULT_PRECISION, "[[4,5,6]]"));
session.execute("INSERT INTO " + keyspaceName + ".table_set (column_5, nested_collection) VALUES (1, {{1, 2, 3}})");
assertThat(computeActual("SELECT nested_collection FROM cassandra." + keyspaceName + ".table_set").getMaterializedRows().get(0)).isEqualTo(new MaterializedRow(DEFAULT_PRECISION, "[[1,2,3]]"));

session.execute("INSERT INTO " + keyspaceName + ".table_map (column_5, nested_collection) VALUES (1, {7:{8:9}})");
assertThat(computeActual("SELECT nested_collection FROM cassandra." + keyspaceName + ".table_map").getMaterializedRows().get(0)).isEqualTo(new MaterializedRow(DEFAULT_PRECISION, "{7:{8:9}}"));
session.execute("INSERT INTO " + keyspaceName + ".table_list (column_5, nested_collection) VALUES (1, [[4, 5, 6]])");
assertThat(computeActual("SELECT nested_collection FROM cassandra." + keyspaceName + ".table_list").getMaterializedRows().get(0)).isEqualTo(new MaterializedRow(DEFAULT_PRECISION, "[[4,5,6]]"));

dropKeyspace(keyspaceName);
session.execute("INSERT INTO " + keyspaceName + ".table_map (column_5, nested_collection) VALUES (1, {7:{8:9}})");
assertThat(computeActual("SELECT nested_collection FROM cassandra." + keyspaceName + ".table_map").getMaterializedRows().get(0)).isEqualTo(new MaterializedRow(DEFAULT_PRECISION, "{7:{8:9}}"));
}
finally {
dropKeyspace(keyspaceName);
}
}

@Test
Expand Down