-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add test to verify failure for renaming to long table name #13289
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
Changes from all commits
837b275
4d74e11
7167eac
029b2a7
6665e10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,6 @@ | |
| import java.util.Optional; | ||
| import java.util.OptionalInt; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
| import java.util.regex.Matcher; | ||
|
|
@@ -130,6 +129,7 @@ | |
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertNotEquals; | ||
| import static org.testng.Assert.assertNull; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| public abstract class BaseIcebergConnectorTest | ||
| extends BaseConnectorTest | ||
|
|
@@ -5480,18 +5480,43 @@ protected void verifySchemaNameLengthFailurePermissible(Throwable e) | |
| assertThat(e).hasMessageMatching("Could not (write|rename) database schema"); | ||
| } | ||
|
|
||
| @Override | ||
| public void testRenameTableToLongTableName() | ||
| { | ||
| // Override because the max name length is different from CREATE TABLE case | ||
| String sourceTableName = "test_rename_source_" + randomTableSuffix(); | ||
| assertUpdate("CREATE TABLE " + sourceTableName + " AS SELECT 123 x", 1); | ||
|
|
||
| String baseTableName = "test_rename_target_" + randomTableSuffix(); | ||
|
|
||
| int maxLength = 255; | ||
|
|
||
| String validTargetTableName = baseTableName + "z".repeat(maxLength - baseTableName.length()); | ||
| assertUpdate("ALTER TABLE " + sourceTableName + " RENAME TO " + validTargetTableName); | ||
| assertTrue(getQueryRunner().tableExists(getSession(), validTargetTableName)); | ||
| assertQuery("SELECT x FROM " + validTargetTableName, "VALUES 123"); | ||
| assertUpdate("DROP TABLE " + validTargetTableName); | ||
|
|
||
| assertUpdate("CREATE TABLE " + sourceTableName + " AS SELECT 123 x", 1); | ||
| String invalidTargetTableName = validTargetTableName + "z"; | ||
| assertThatThrownBy(() -> assertUpdate("ALTER TABLE " + sourceTableName + " RENAME TO " + invalidTargetTableName)) | ||
| .satisfies(this::verifyTableNameLengthFailurePermissible); | ||
| assertFalse(getQueryRunner().tableExists(getSession(), invalidTargetTableName)); | ||
| } | ||
|
|
||
| @Override | ||
| protected OptionalInt maxTableNameLength() | ||
| { | ||
| // This value depends on metastore type | ||
| // The connector appends uuids to the end of all table names | ||
| return OptionalInt.of(255 - UUID.randomUUID().toString().length()); | ||
| // 33 is the length of random suffix. e.g. {table name}-142763c594d54e4b9329a98f90528caf | ||
| return OptionalInt.of(255 - 33); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, this test passed in Iceberg unintentionally because of its try-catch style. This change is required to adjust to the right max length. |
||
| } | ||
|
|
||
| @Override | ||
| protected void verifyTableNameLengthFailurePermissible(Throwable e) | ||
| { | ||
| assertThat(e).hasMessageContaining("Failed to create file"); | ||
| assertThat(e).hasMessageMatching("Failed to create file.*|Could not create new table directory"); | ||
| } | ||
|
|
||
| private Session prepareCleanUpSession() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, also seems to fix the issue that we would throw raw SQLException instead of wrapping into a TrinoException.