Repository navigation
Expand file tree
/
Copy pathchunkenizator.sql
More file actions
86 lines (79 loc) · 2.67 KB
/
Copy pathchunkenizator.sql
File metadata and controls
86 lines (79 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Chunkenization */
CREATE OR REPLACE FUNCTION jobs_chunk(
JOB_TITLE STRING,
COMPANY STRING,
JOB_LOCATION STRING,
JOB_LINK STRING,
FIRST_SEEN STRING,
SEARCH_CITY STRING,
SEARCH_COUNTRY STRING,
JOB_LEVEL STRING,
JOB_TYPE STRING,
JOB_SUMMARY STRING
)
RETURNS TABLE (
chunk STRING,
job_summary STRING,
job_title STRING,
company_name STRING,
search_city STRING,
search_country STRING
)
LANGUAGE PYTHON
RUNTIME_VERSION = '3.9'
HANDLER = 'JobsChunkUDTF' -- AQUI VAI O NOME DA CLASSE
PACKAGES = ('snowflake-snowpark-python', 'langchain')
AS
$$
from langchain.text_splitter import RecursiveCharacterTextSplitter
from typing import Optional
# Lista de palavras-chave para Data Engineering
SKILL_KEYWORDS = [
'SQL', 'Python', 'Apache Spark', 'Hadoop', 'Kafka', 'ETL',
'Data Pipeline', 'Data Warehouse', 'Snowflake', 'BigQuery', 'Redshift',
'Airflow', 'Databricks', 'AWS Glue', 'Azure Data Factory', 'Google Cloud Dataflow',
'NoSQL', 'PostgreSQL', 'MongoDB', 'Delta Lake', 'Dremio', 'Presto',
'Data Lake', 'OLAP', 'Batch Processing', 'Streaming', 'Parquet', 'Avro',
'Athena', 'Terraform', 'Data Modeling', 'Data Governance', 'Data Quality'
]
class JobsChunkUDTF:
def process(
self,
job_title: str,
company: str,
job_location: str,
job_link: str,
first_seen: str,
search_city: str,
search_country: str,
job_level: str,
job_type: str,
job_summary: Optional[str]
):
# Caso o resumo esteja nulo
if job_summary is None:
job_summary = ""
# Inicializa o text splitter do LangChain
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=2000,
chunk_overlap=300
)
# Divide o texto em chunks
chunks = text_splitter.split_text(job_summary)
# Para cada chunk, vamos gerar uma linha
for chunk in chunks:
skill_mentions = [skill for skill in SKILL_KEYWORDS if skill.lower() in chunk.lower()]
if skill_mentions:
chunk_with_skills = f"Skills: {', '.join(skill_mentions)}\n{chunk}"
else:
chunk_with_skills = chunk
# Use yield para retornar várias linhas
yield (
chunk_with_skills, # chunk
job_summary, # job_summary
job_title, # job_title
company, # company_name
search_city, # search_city
search_country # search_country
)
$$;