Skip to content
Snippets Groups Projects
Commit 917f16e2 authored by lcd22's avatar lcd22
Browse files

ajustando clean.py

parent 6a4629a6
No related branches found
No related tags found
No related merge requests found
...@@ -16,10 +16,23 @@ spark = SparkSession.builder \ ...@@ -16,10 +16,23 @@ spark = SparkSession.builder \
def clean_bucket(bucket_path): def clean_bucket(bucket_path):
try: try:
print(f"Limpando o diretório {bucket_path}...") print(f"Limpando o diretório {bucket_path}...")
spark._jvm.org.apache.hadoop.fs.FileSystem \
.get(spark._jsc.hadoopConfiguration()) \ # Certifique-se de que o caminho S3 seja tratado corretamente
.delete(spark._jvm.org.apache.hadoop.fs.Path(bucket_path), True) if not bucket_path.startswith("s3a://"):
print(f"Caminho inválido: {bucket_path}. Deve começar com 's3a://'.")
return
# Usando a API Hadoop FileSystem para deletar o diretório S3
fs = spark._jvm.org.apache.hadoop.fs.FileSystem.get(spark._jsc.hadoopConfiguration())
path = spark._jvm.org.apache.hadoop.fs.Path(bucket_path)
# Apagar o diretório S3 (o parâmetro 'True' remove recursivamente)
if fs.exists(path):
fs.delete(path, True)
print(f"Diretório {bucket_path} limpo com sucesso.") print(f"Diretório {bucket_path} limpo com sucesso.")
else:
print(f"O diretório {bucket_path} não existe.")
except Exception as e: except Exception as e:
print(f"Erro ao limpar o diretório {bucket_path}: {e}") print(f"Erro ao limpar o diretório {bucket_path}: {e}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment