Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
airflow-dags
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Team DB
airflow-dags
Commits
0ec0f117
Commit
0ec0f117
authored
4 months ago
by
lcd22
Browse files
Options
Downloads
Patches
Plain Diff
volta versão
parent
7c91518f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
clean.py
+0
-52
0 additions, 52 deletions
clean.py
dags.py
+1
-6
1 addition, 6 deletions
dags.py
with
1 addition
and
58 deletions
clean.py
deleted
100644 → 0
+
0
−
52
View file @
7c91518f
from
pyspark.sql
import
SparkSession
# Configuração do Spark para acessar o MinIO
print
(
"
Iniciando a configuração do Spark...
"
)
spark
=
SparkSession
.
builder
\
.
appName
(
"
clean_directories
"
)
\
.
config
(
"
spark.hadoop.fs.s3a.endpoint
"
,
"
http://minio.minio-cluster.svc.cluster.local:9000
"
)
\
.
config
(
"
spark.hadoop.fs.s3a.access.key
"
,
"
minioadmin
"
)
\
.
config
(
"
spark.hadoop.fs.s3a.secret.key
"
,
"
minioadmin
"
)
\
.
config
(
"
spark.hadoop.fs.s3a.path.style.access
"
,
"
true
"
)
\
.
config
(
"
spark.hadoop.fs.s3a.impl
"
,
"
org.apache.hadoop.fs.s3a.S3AFileSystem
"
)
\
.
config
(
"
spark.hadoop.fs.s3a.aws.credentials.provider
"
,
"
org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider
"
)
\
.
config
(
"
spark.hadoop.fs.defaultFS
"
,
"
s3a://
"
)
\
# Garantir que o fs padrão seja o s3a
.
getOrCreate
()
# Função para limpar os diretórios (buckets)
def
clean_bucket
(
bucket_path
):
try
:
print
(
f
"
Limpando o diretório
{
bucket_path
}
...
"
)
# Certifique-se de que o caminho S3 seja tratado corretamente
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.
"
)
else
:
print
(
f
"
O diretório
{
bucket_path
}
não existe.
"
)
except
Exception
as
e
:
print
(
f
"
Erro ao limpar o diretório
{
bucket_path
}
:
{
e
}
"
)
# Diretórios para limpar
buckets
=
[
"
s3a://bronze/warehouse
"
,
"
s3a://silver/warehouse
"
,
"
s3a://gold/warehouse
"
]
# Limpar os buckets
for
bucket
in
buckets
:
clean_bucket
(
bucket
)
# Finalizar o Spark
spark
.
stop
()
This diff is collapsed.
Click to expand it.
dags.py
+
1
−
6
View file @
0ec0f117
...
@@ -15,11 +15,6 @@ def process_records():
...
@@ -15,11 +15,6 @@ def process_records():
"""
"""
DAG que realiza o fluxo landing -> bronze -> silver -> gold
DAG que realiza o fluxo landing -> bronze -> silver -> gold
"""
"""
task_0
=
SparkSubmitOperator
(
application
=
f
"
{
repo_home
}
/clean.py
"
,
task_id
=
"
clean_directories
"
,
packages
=
"
org.apache.hadoop:hadoop-aws:3.3.4
"
)
task_1
=
SparkSubmitOperator
(
task_1
=
SparkSubmitOperator
(
application
=
f
"
{
repo_home
}
/gen_bronze.py
"
,
application
=
f
"
{
repo_home
}
/gen_bronze.py
"
,
...
@@ -38,7 +33,7 @@ def process_records():
...
@@ -38,7 +33,7 @@ def process_records():
bash_command
=
"
dbt deps && dbt build
"
,
bash_command
=
"
dbt deps && dbt build
"
,
)
)
task_0
>>
task_1
>>
task_2
>>
task_3
task_1
>>
task_2
>>
task_3
dag
=
process_records
()
dag
=
process_records
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment