suneet-s commented on a change in pull request #11227:
URL: https://github.com/apache/druid/pull/11227#discussion_r629569200



##########
File path: 
server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java
##########
@@ -1423,4 +1424,40 @@ public boolean insertDataSourceMetadata(String 
dataSource, DataSourceMetadata me
             .execute()
     );
   }
+
+  @Override
+  public int removeDataSourceMetadataOlderThan(long timestamp, @Nullable 
Set<String> excludeDatasources)
+  {
+    DateTime dateTime = DateTimes.utc(timestamp);
+    List<String> datasources = connector.getDBI().withHandle(
+        handle -> handle
+            .createQuery(
+                StringUtils.format(
+                    "SELECT dataSource FROM %1$s WHERE created_date < '%2$s'",
+                    dbTables.getDataSourceTable(),
+                    dateTime.toString()
+                )
+            )
+            .mapTo(String.class)
+            .list()
+    );
+    return connector.getDBI().withHandle(
+        handle -> {
+          final PreparedBatch batch = handle.prepareBatch(
+              StringUtils.format(
+                  "DELETE FROM %1$s WHERE dataSource = :dataSource AND 
created_date < '%2$s'",

Review comment:
       Why did you choose to build the delete statements one at a time instead 
of doing a batch delete?
   
   I think we could encapsulate the `excludeDatasources` logic in a where 
clause of this delete statement instead.
   
   Something like `DELETE FROM datasources where created_date < "date" and 
datasource not in ("excludeDataSources")`




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to