@@ -576,12 +576,31 @@ def add_confidence(repo_id):
576576
577577 # For repos with metrics-only update, preserve existing classifications
578578 if repos_for_metrics_only .count () > 0 :
579- # Join with existing classifications
579+ # Create lookup map for existing classifications
580+ existing_classifications = {row .repository_id : (row .technology_category , row .technology_subcategory , row .classification_confidence )
581+ for row in well_classified .collect ()}
582+
583+ def get_existing_category (repo_id ):
584+ return existing_classifications .get (repo_id , ("Other" , "unknown" , 0.1 ))[0 ]
585+
586+ def get_existing_subcategory (repo_id ):
587+ return existing_classifications .get (repo_id , ("Other" , "unknown" , 0.1 ))[1 ]
588+
589+ def get_existing_confidence (repo_id ):
590+ return existing_classifications .get (repo_id , ("Other" , "unknown" , 0.1 ))[2 ]
591+
592+ # Create UDFs for existing classifications
593+ existing_category_udf = F .udf (get_existing_category , StringType ())
594+ existing_subcategory_udf = F .udf (get_existing_subcategory , StringType ())
595+ existing_confidence_udf = F .udf (get_existing_confidence , DoubleType ())
596+
597+ # Add existing classifications using same pattern as LLM classifications
580598 metrics_with_classification = (repos_for_metrics_only
581- .join (well_classified , "repository_id" , "inner" )
582- .drop (well_classified .repository_id )) # Avoid duplicate column
599+ .withColumn ("technology_category" , existing_category_udf (F .col ("repository_id" )))
600+ .withColumn ("technology_subcategory" , existing_subcategory_udf (F .col ("repository_id" )))
601+ .withColumn ("classification_confidence" , existing_confidence_udf (F .col ("repository_id" ))))
583602
584- # Combine classified and metrics-only repos
603+ # Now both DataFrames have the same schema - safe to union
585604 final_df = classified_repos .union (metrics_with_classification )
586605 else :
587606 final_df = classified_repos
0 commit comments