@@ -456,57 +456,61 @@ func (p *Parquet) getPartitionedFilePath(values map[string]any, olakeTimestamp t
456456 return filepath .Join (p .basePath , strings .TrimSuffix (result , "/" ))
457457}
458458
459- func (p * Parquet ) DropStreams (ctx context.Context , selectedStreams []string ) error {
459+ func (p * Parquet ) DropStreams (ctx context.Context , selectedStreams []types.StreamInterface ) error {
460+ // check for s3 writer configuration
461+ err := p .initS3Writer ()
462+ if err != nil {
463+ return err
464+ }
465+
460466 if len (selectedStreams ) == 0 {
461- logger .Infof ("Thread[%s]: no streams selected for clearing, skipping clear operation" , p . options . ThreadID )
467+ logger .Infof ("no streams selected for clearing, skipping clear operation" )
462468 return nil
463469 }
464470
465- logger .Infof ("Thread[%s]: clearing destination for %d selected streams: %v" , p .options .ThreadID , len (selectedStreams ), selectedStreams )
471+ paths := make ([]string , 0 , len (selectedStreams ))
472+ for _ , stream := range selectedStreams {
473+ paths = append (paths , stream .GetDestinationDatabase (nil )+ "." + stream .GetDestinationTable ())
474+ }
466475
467476 if p .s3Client == nil {
468- if err := p .clearLocalFiles (selectedStreams ); err != nil {
477+ if err := p .clearLocalFiles (paths ); err != nil {
469478 return fmt .Errorf ("failed to clear local files: %s" , err )
470479 }
471480 } else {
472- if err := p .clearS3Files (ctx , selectedStreams ); err != nil {
481+ if err := p .clearS3Files (ctx , paths ); err != nil {
473482 return fmt .Errorf ("failed to clear S3 files: %s" , err )
474483 }
475484 }
476-
477- logger .Infof ("Thread[%s]: successfully cleared destination for selected streams" , p .options .ThreadID )
478485 return nil
479486}
480487
481- func (p * Parquet ) clearLocalFiles (selectedStreams []string ) error {
482- for _ , streamID := range selectedStreams {
488+ func (p * Parquet ) clearLocalFiles (paths []string ) error {
489+ for _ , streamID := range paths {
483490 parts := strings .SplitN (streamID , "." , 2 )
484491 if len (parts ) != 2 {
485- logger .Warnf ("Thread[%s]: invalid stream ID format: %s, skipping" , p . options . ThreadID , streamID )
492+ logger .Warnf ("invalid stream ID format: %s, skipping" , streamID )
486493 continue
487494 }
495+ namespace , tableName := parts [0 ], parts [1 ]
496+ streamPath := filepath .Join (p .config .Path , namespace , tableName )
488497
489- namespace , streamName := parts [0 ], parts [1 ]
490- streamPath := filepath .Join (p .config .Path , namespace , streamName )
491-
492- logger .Infof ("Thread[%s]: clearing local path: %s" , p .options .ThreadID , streamPath )
498+ logger .Infof ("clearing local path: %s" , streamPath )
493499
494500 if _ , err := os .Stat (streamPath ); os .IsNotExist (err ) {
495- logger .Debugf ("Thread[%s]: local path does not exist, skipping: %s" , p . options . ThreadID , streamPath )
501+ logger .Debugf ("local path does not exist, skipping: %s" , streamPath )
496502 continue
497503 }
498504
499505 if err := os .RemoveAll (streamPath ); err != nil {
500506 return fmt .Errorf ("failed to remove local path %s: %s" , streamPath , err )
501507 }
502-
503- logger .Debugf ("Thread[%s]: successfully cleared local path: %s" , p .options .ThreadID , streamPath )
504508 }
505509
506510 return nil
507511}
508512
509- func (p * Parquet ) clearS3Files (ctx context.Context , selectedStreams []string ) error {
513+ func (p * Parquet ) clearS3Files (ctx context.Context , paths []string ) error {
510514 deleteS3PrefixStandard := func (filtPath string ) error {
511515 iter := s3manager .NewDeleteListIterator (p .s3Client , & s3.ListObjectsInput {
512516 Bucket : aws .String (p .config .Bucket ),
@@ -519,21 +523,21 @@ func (p *Parquet) clearS3Files(ctx context.Context, selectedStreams []string) er
519523 return nil
520524 }
521525
522- for _ , streamID := range selectedStreams {
526+ for _ , streamID := range paths {
523527 parts := strings .SplitN (streamID , "." , 2 )
524528 if len (parts ) != 2 {
525- logger .Warnf ("Thread[%s]: invalid stream ID format: %s, skipping" , p . options . ThreadID , streamID )
529+ logger .Warnf ("invalid stream ID format: %s, skipping" , streamID )
526530 continue
527531 }
532+ namespace , tableName := parts [0 ], parts [1 ]
533+ s3TablePath := filepath .Join (p .config .Prefix , namespace , tableName , "/" )
528534
529- namespace , streamName := parts [0 ], parts [1 ]
530- s3TablePath := filepath .Join (p .config .Prefix , namespace , streamName , "/" )
531- logger .Debugf ("Thread[%s]: clearing S3 prefix: s3://%s/%s" , p .options .ThreadID , p .config .Bucket , s3TablePath )
535+ logger .Debugf ("clearing S3 prefix: s3://%s/%s" , p .config .Bucket , s3TablePath )
532536 if err := deleteS3PrefixStandard (s3TablePath ); err != nil {
533537 return fmt .Errorf ("failed to clear S3 prefix %s: %s" , s3TablePath , err )
534538 }
535539
536- logger .Debugf ("Thread[%s]: successfully cleared S3 prefix: s3://%s/%s" , p . options . ThreadID , p .config .Bucket , s3TablePath )
540+ logger .Debugf ("successfully cleared S3 prefix: s3://%s/%s" , p .config .Bucket , s3TablePath )
537541 }
538542 return nil
539543}
0 commit comments