jtuglu1 commented on code in PR #18515:
URL: https://github.com/apache/druid/pull/18515#discussion_r2383792271
##########
server/src/test/java/org/apache/druid/metadata/SQLMetadataConnectorTest.java:
##########
@@ -305,6 +303,140 @@ public void testIsTransientException()
);
}
+ @Test
+ public void test_useShortIndexNames_true_tableIndices_areNotAdded_ifExist()
+ {
+ tablesConfig = new MetadataStorageTablesConfig(
+ "druidTest_base_table_name_true",
+ null, null, null, null, null, null, null, null, null, null, null,
+ true
+ );
+ connector = new TestDerbyConnector(new MetadataStorageConnectorConfig(),
tablesConfig);
+
+ final String segmentsTable = tablesConfig.getSegmentsTable();
+
+ connector.createSegmentTable(segmentsTable);
+ connector.alterSegmentTable();
+ connector.getDBI().withHandle(handle -> {
+ handle.execute("DROP INDEX
IDX_B859F28F30657A58518416E445E0AA1A78A68177");
+ handle.execute(StringUtils.format("CREATE INDEX IDX_%1$s_USED ON
%1$s(used)", segmentsTable));
+ return null;
+ });
+
+ connector.createSegmentTable(segmentsTable);
+ connector.alterSegmentTable();
+
+ final Set<String> expectedIndices = Sets.newHashSet(
+ StringUtils.format("IDX_%S_USED", segmentsTable),
+ "IDX_3A789D647A2A70597C2AA5CB1DC4E0F231529B75",
+ "IDX_00F9CD53AC9353C0E98B554ECD8CF5A84D28370F"
+ );
+ assertIndicesPresentOnTable(segmentsTable, expectedIndices);
+
+ dropTable(segmentsTable);
+ connector.tearDown();
+ }
+
+ @Test
+ public void test_useShortIndexNames_false_tableIndices_areNotAdded_ifExist()
+ {
+ tablesConfig = new MetadataStorageTablesConfig(
+ "druidTest_base_table_name",
+ null, null, null, null, null, null, null, null, null, null, null,
+ false
+ );
+ connector = new TestDerbyConnector(new MetadataStorageConnectorConfig(),
tablesConfig);
+
+ final String segmentsTable = tablesConfig.getSegmentsTable();
+
+ connector.createSegmentTable(segmentsTable);
+ connector.alterSegmentTable();
+ connector.getDBI().withHandle(handle -> {
+ handle.execute(StringUtils.format("DROP INDEX IDX_%s_USED",
segmentsTable));
+ handle.execute(StringUtils.format(
+ "CREATE INDEX IDX_3E94AF560719CBA0E08C0B35FB5DF8079DC6D595 ON
%1$s(used)",
+ segmentsTable
+ ));
+ return null;
+ });
+
+ connector.createSegmentTable(segmentsTable);
+ connector.alterSegmentTable();
+
+ final Set<String> expectedIndices = Sets.newHashSet(
+ "IDX_3E94AF560719CBA0E08C0B35FB5DF8079DC6D595",
+ StringUtils.format("IDX_%S_DATASOURCE_USED_END_START", segmentsTable),
+ StringUtils.format("IDX_%S_DATASOURCE_UPGRADED_FROM_SEGMENT_ID",
segmentsTable)
+ );
+ assertIndicesPresentOnTable(segmentsTable, expectedIndices);
+
+ dropTable(segmentsTable);
+ connector.tearDown();
+ }
+
+ @Test
+ public void test_useShortIndexNames_true_tableIndices_areAdded_IfNotExist()
+ {
+ tablesConfig = new MetadataStorageTablesConfig(
+ "druidTest_base_table_name_true",
+ null, null, null, null, null, null, null, null, null, null, null,
+ true
+ );
+ connector = new TestDerbyConnector(new MetadataStorageConnectorConfig(),
tablesConfig);
+
+ final String segmentsTable = tablesConfig.getSegmentsTable();
+
+ final Set<String> expectedIndices = Sets.newHashSet(
+ "IDX_B859F28F30657A58518416E445E0AA1A78A68177",
+ "IDX_3A789D647A2A70597C2AA5CB1DC4E0F231529B75",
+ "IDX_00F9CD53AC9353C0E98B554ECD8CF5A84D28370F"
+ );
+
+ connector.createSegmentTable(segmentsTable);
+ connector.alterSegmentTable();
+
+ assertIndicesPresentOnTable(segmentsTable, expectedIndices);
+ dropTable(segmentsTable);
+ connector.tearDown();
+ }
+
+ @Test
+ public void test_useShortIndexNames_false_tableIndices_areAdded_IfNotExist()
+ {
+ final String segmentsTable = tablesConfig.getSegmentsTable();
+
+ final Set<String> expectedIndices = Sets.newHashSet(
+ StringUtils.format("IDX_%S_USED", segmentsTable),
Review Comment:
This one the connector choose random UUID. I'll change it but not necessary
IMO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]