data-prep-toolkit-transforms 0.2.2__1-py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- UAST.py +270 -0
- UAST_parser.py +271 -0
- __init__.py +0 -0
- base_tokenizer.py +36 -0
- cc_net_prepro.py +168 -0
- cluster_estimator.py +59 -0
- code2parquet_local.py +51 -0
- code2parquet_local_python.py +60 -0
- code2parquet_local_ray.py +63 -0
- code2parquet_s3_python.py +61 -0
- code2parquet_s3_ray.py +64 -0
- code2parquet_transform.py +222 -0
- code2parquet_transform_python.py +39 -0
- code2parquet_transform_ray.py +123 -0
- code_profiler_local.py +66 -0
- code_profiler_local_python.py +46 -0
- code_profiler_local_ray.py +59 -0
- code_profiler_transform.py +208 -0
- code_profiler_transform_python.py +47 -0
- code_profiler_transform_ray.py +47 -0
- code_quality_local.py +37 -0
- code_quality_local_python.py +50 -0
- code_quality_local_ray.py +56 -0
- code_quality_s3_ray.py +57 -0
- code_quality_transform.py +312 -0
- code_quality_transform_python.py +27 -0
- code_quality_transform_ray.py +29 -0
- compute_shingles.py +50 -0
- data_prep_toolkit_transforms-0.2.2.dist-info/METADATA +199 -0
- data_prep_toolkit_transforms-0.2.2.dist-info/RECORD +211 -0
- data_prep_toolkit_transforms-0.2.2.dist-info/WHEEL +5 -0
- data_prep_toolkit_transforms-0.2.2.dist-info/top_level.txt +1 -0
- doc_Gopher_statistics.py +158 -0
- doc_c4_statistics.py +167 -0
- doc_chunk_chunkers.py +138 -0
- doc_chunk_local.py +34 -0
- doc_chunk_local_python.py +56 -0
- doc_chunk_local_ray.py +50 -0
- doc_chunk_s3_ray.py +57 -0
- doc_chunk_transform.py +255 -0
- doc_chunk_transform_python.py +43 -0
- doc_chunk_transform_ray.py +50 -0
- doc_id_local.py +54 -0
- doc_id_local_python.py +52 -0
- doc_id_local_ray.py +57 -0
- doc_id_s3_ray.py +60 -0
- doc_id_transform_base.py +177 -0
- doc_id_transform_python.py +120 -0
- doc_id_transform_ray.py +116 -0
- doc_quality_local.py +43 -0
- doc_quality_local_python.py +57 -0
- doc_quality_local_ray.py +59 -0
- doc_quality_s3_ray.py +70 -0
- doc_quality_transform.py +241 -0
- doc_quality_transform_python.py +42 -0
- doc_quality_transform_ray.py +43 -0
- doc_quality_utils.py +67 -0
- dpk_repo_level_order/__init__.py +2 -0
- dpk_repo_level_order/internal/check_languages.py +93 -0
- dpk_repo_level_order/internal/repo_grouper.py +137 -0
- dpk_repo_level_order/internal/repo_level_wrappers.py +227 -0
- dpk_repo_level_order/internal/sorting/semantic_ordering/__init__.py +5 -0
- dpk_repo_level_order/internal/sorting/semantic_ordering/build_dep_graph.py +460 -0
- dpk_repo_level_order/internal/sorting/semantic_ordering/sort_by_semantic_dep.py +91 -0
- dpk_repo_level_order/internal/sorting/semantic_ordering/topological_sort.py +204 -0
- dpk_repo_level_order/internal/sorting/semantic_ordering/utils.py +132 -0
- dpk_repo_level_order/internal/store/ray_store.py +152 -0
- dpk_repo_level_order/internal/store/store.py +139 -0
- dpk_repo_level_order/internal/store/store_factory.py +139 -0
- dpk_web2parquet/config.py +81 -0
- dpk_web2parquet/local.py +26 -0
- dpk_web2parquet/local_python.py +49 -0
- dpk_web2parquet/python_runtime.py +44 -0
- dpk_web2parquet/transform.py +126 -0
- dpk_web2parquet/utils.py +38 -0
- ededup_compute_execution_params.py +131 -0
- ededup_local.py +43 -0
- ededup_local_python.py +46 -0
- ededup_local_python_incremental.py +53 -0
- ededup_local_ray.py +55 -0
- ededup_local_ray_incremental.py +62 -0
- ededup_s3_ray.py +58 -0
- ededup_transform_base.py +249 -0
- ededup_transform_python.py +145 -0
- ededup_transform_ray.py +241 -0
- fdedup_compute_execution_params.py +232 -0
- fdedup_local_ray.py +71 -0
- fdedup_s3_ray.py +76 -0
- fdedup_support.py +621 -0
- fdedup_transform_ray.py +803 -0
- filter_local.py +58 -0
- filter_local_python.py +60 -0
- filter_local_ray.py +71 -0
- filter_s3_ray.py +74 -0
- filter_test_support.py +135 -0
- filter_transform.py +192 -0
- filter_transform_python.py +31 -0
- filter_transform_ray.py +32 -0
- flair_recognizer.py +160 -0
- hap_local.py +49 -0
- hap_local_python.py +53 -0
- hap_local_ray.py +60 -0
- hap_s3_ray.py +64 -0
- hap_transform.py +176 -0
- hap_transform_python.py +35 -0
- hap_transform_ray.py +39 -0
- header_cleanser_local.py +52 -0
- header_cleanser_local_python.py +53 -0
- header_cleanser_local_ray.py +64 -0
- header_cleanser_s3_ray.py +67 -0
- header_cleanser_test_support.py +94 -0
- header_cleanser_transform.py +237 -0
- header_cleanser_transform_python.py +31 -0
- header_cleanser_transform_ray.py +32 -0
- html2parquet_local.py +35 -0
- html2parquet_local_python.py +46 -0
- html2parquet_local_ray.py +55 -0
- html2parquet_s3_ray.py +57 -0
- html2parquet_transform.py +238 -0
- html2parquet_transform_python.py +42 -0
- html2parquet_transform_ray.py +70 -0
- lang_id_local.py +49 -0
- lang_id_local_python.py +55 -0
- lang_id_local_ray.py +65 -0
- lang_id_s3_ray.py +71 -0
- lang_id_transform.py +141 -0
- lang_id_transform_python.py +42 -0
- lang_id_transform_ray.py +43 -0
- lang_models.py +52 -0
- license_select_local.py +43 -0
- license_select_local_python.py +54 -0
- license_select_local_ray.py +61 -0
- license_select_s3_ray.py +56 -0
- license_select_transform.py +181 -0
- license_select_transform_python.py +27 -0
- license_select_transform_ray.py +30 -0
- malware_local.py +40 -0
- malware_local_python.py +55 -0
- malware_local_ray.py +62 -0
- malware_transform.py +194 -0
- malware_transform_python.py +31 -0
- malware_transform_ray.py +31 -0
- nlp.py +46 -0
- noop_local.py +34 -0
- noop_local_python.py +45 -0
- noop_local_python_multiprocessor.py +46 -0
- noop_local_ray.py +51 -0
- noop_s3_ray.py +57 -0
- noop_transform.py +118 -0
- noop_transform_python.py +45 -0
- noop_transform_ray.py +42 -0
- offline-customizations/config_LLM_runner_app.py +22 -0
- offline-customizations/generic_LLM_runner_app.py +583 -0
- pdf2parquet_local.py +39 -0
- pdf2parquet_local_python.py +56 -0
- pdf2parquet_local_ray.py +52 -0
- pdf2parquet_s3_ray.py +57 -0
- pdf2parquet_transform.py +494 -0
- pdf2parquet_transform_python.py +42 -0
- pdf2parquet_transform_ray.py +72 -0
- pii_analyzer.py +83 -0
- pii_anonymizer.py +38 -0
- pii_redactor_local.py +35 -0
- pii_redactor_local_python.py +37 -0
- pii_redactor_local_ray.py +54 -0
- pii_redactor_s3_ray.py +59 -0
- pii_redactor_transform.py +162 -0
- pii_redactor_transform_python.py +34 -0
- pii_redactor_transform_ray.py +49 -0
- profiler_compute_execution_params.py +122 -0
- profiler_local.py +44 -0
- profiler_local_python.py +45 -0
- profiler_local_ray.py +52 -0
- profiler_s3_ray.py +55 -0
- profiler_transform_base.py +176 -0
- profiler_transform_python.py +125 -0
- profiler_transform_ray.py +209 -0
- proglang_select_local.py +51 -0
- proglang_select_local_python.py +61 -0
- proglang_select_local_ray.py +67 -0
- proglang_select_transform.py +167 -0
- proglang_select_transform_python.py +32 -0
- proglang_select_transform_ray.py +88 -0
- repo_level_order_local_ray.py +63 -0
- repo_level_order_s3_ray.py +64 -0
- repo_level_order_transform.py +467 -0
- repo_level_order_transform_ray.py +24 -0
- resize_local.py +36 -0
- resize_local_python.py +46 -0
- resize_local_ray.py +51 -0
- resize_s3_ray.py +57 -0
- resize_transform.py +193 -0
- resize_transform_python.py +40 -0
- resize_transform_ray.py +40 -0
- text_encoder_local.py +44 -0
- text_encoder_local_python.py +44 -0
- text_encoder_local_ray.py +50 -0
- text_encoder_s3_ray.py +56 -0
- text_encoder_transform.py +127 -0
- text_encoder_transform_python.py +44 -0
- text_encoder_transform_ray.py +51 -0
- tokenization_local_long_doc_python.py +49 -0
- tokenization_local_python.py +40 -0
- tokenization_local_ray.py +49 -0
- tokenization_s3_long_doc_python.py +52 -0
- tokenization_s3_ray.py +59 -0
- tokenization_transform.py +258 -0
- tokenization_transform_python.py +27 -0
- tokenization_transform_ray.py +32 -0
- tokenization_utils.py +143 -0
- transformer.py +151 -0
cc_net_prepro.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
"""
|
|
14
|
+
@ Create on: 2023/04/25
|
|
15
|
+
@ Description:
|
|
16
|
+
To incorporate preprocessing steps from cc_net/
|
|
17
|
+
|
|
18
|
+
@ Reference:
|
|
19
|
+
https://github.com/facebookresearch/cc_net/blob/main/cc_net/text_normalizer.py
|
|
20
|
+
https://github.com/bigscience-workshop/data_tooling/blob/master/kenlm_training/cc_net/text_normalizer.py
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
import unicodedata
|
|
25
|
+
from typing import Dict
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
unicode_punct_dict: Dict[str, str] = {
|
|
29
|
+
",": ",",
|
|
30
|
+
"。": ".",
|
|
31
|
+
"、": ",",
|
|
32
|
+
"„": '"',
|
|
33
|
+
"”": '"',
|
|
34
|
+
"“": '"',
|
|
35
|
+
"«": '"',
|
|
36
|
+
"»": '"',
|
|
37
|
+
"1": '"',
|
|
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
|
+
_unicode_punct_re = re.compile(f"[{''.join(unicode_punct_dict.keys())}]")
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
Generate regex pattern obj for later searching using re.search() or re.match()
|
|
69
|
+
(r'[\x00\x01...\x9e\x9f]',re.UNICODE)
|
|
70
|
+
"""
|
|
71
|
+
_non_printing_chars_re = re.compile(f"[{''.join(map(chr, list(range(0, 32)) + list(range(127, 160))))}]")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def unicode_normalization(line: str, language="en") -> str:
|
|
75
|
+
"""
|
|
76
|
+
For some languages like 'ja' or 'en', its text should be normalized with the right unicode format
|
|
77
|
+
prior to calling tokenization by sentence piece tokenizer
|
|
78
|
+
"""
|
|
79
|
+
if language == "ja":
|
|
80
|
+
line = unicodedata.normalize("NFKC", line)
|
|
81
|
+
elif language == "en":
|
|
82
|
+
line = unicodedata.normalize("NFD", line) # normalize line using Unicode Normalization Form D
|
|
83
|
+
else:
|
|
84
|
+
"""
|
|
85
|
+
TODO: add relevant unicodedata normalization here for other languages as needed
|
|
86
|
+
"""
|
|
87
|
+
return line
|
|
88
|
+
|
|
89
|
+
return line
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _strip_accents(line) -> str:
|
|
93
|
+
"""
|
|
94
|
+
This currently is applied for `en` and `ja` language to strip out accents from text.
|
|
95
|
+
The given text 'line' should be normalized with the right unicode format prior to calling this method.
|
|
96
|
+
For example:
|
|
97
|
+
line = "Café élevàtor ôperàtor naïve Noël façade don't"
|
|
98
|
+
-> "Cafe elevator operator naive Noel facade don't" if line was normalized with unicode format NFD
|
|
99
|
+
-> "Cafe elevator operator naïve Noël façade don't" if line was NOT normalized with any unicode format
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
"""Keep char whose category is NOT "Mn", i.e,
|
|
103
|
+
"Mn" is category for Mark or Non-Spacing characters like diacritic/accent or non-spacing marks
|
|
104
|
+
Example of some diacritic/non-spacing marks: ^,´,` as they don't occupy space
|
|
105
|
+
"""
|
|
106
|
+
output = [c for c in line if unicodedata.category(c) != "Mn"] # decompose line into chars and diacritical marks
|
|
107
|
+
if len(output) == line:
|
|
108
|
+
return line
|
|
109
|
+
return "".join(output)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _replace_unicode_punct(line: str) -> str:
|
|
113
|
+
"""
|
|
114
|
+
Replace unicode punctuations defined in `unicode_punct_dict'
|
|
115
|
+
"""
|
|
116
|
+
return "".join(unicode_punct_dict.get(c, c) for c in line)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _remove_unicode_punct(line: str) -> str:
|
|
120
|
+
"""
|
|
121
|
+
More aggressive _replace_unicode_punct
|
|
122
|
+
"""
|
|
123
|
+
return _unicode_punct_re.sub("", line)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _remove_non_printing_char(line: str) -> str:
|
|
127
|
+
return _non_printing_chars_re.sub("", line)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def cc_net_normalize(
|
|
131
|
+
line: str,
|
|
132
|
+
strip_accent: bool = True,
|
|
133
|
+
lower_case: bool = True,
|
|
134
|
+
digit_2_zero: bool = True,
|
|
135
|
+
punct_level: int = 1,
|
|
136
|
+
language: str = "en",
|
|
137
|
+
) -> str:
|
|
138
|
+
line = line.strip()
|
|
139
|
+
|
|
140
|
+
if not line:
|
|
141
|
+
return line
|
|
142
|
+
|
|
143
|
+
line = unicode_normalization(line=line, language=language)
|
|
144
|
+
|
|
145
|
+
if lower_case:
|
|
146
|
+
line = line.lower()
|
|
147
|
+
|
|
148
|
+
if strip_accent:
|
|
149
|
+
line = _strip_accents(line)
|
|
150
|
+
|
|
151
|
+
if digit_2_zero:
|
|
152
|
+
# eg, "int 10 float 2.01 scientific 1.2e10" -> "int 00 float 0.00 scientific 0.0e00"
|
|
153
|
+
line = re.compile(r"\d").sub("0", line)
|
|
154
|
+
|
|
155
|
+
if punct_level == 1:
|
|
156
|
+
line = _replace_unicode_punct(line)
|
|
157
|
+
|
|
158
|
+
elif punct_level == 2:
|
|
159
|
+
line = _remove_unicode_punct(line)
|
|
160
|
+
|
|
161
|
+
line = _remove_non_printing_char(line)
|
|
162
|
+
return line
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
if __name__ == "__main__":
|
|
166
|
+
line = "Int 10 float 2.01 scientific 1.2e10 Café ôperàtor"
|
|
167
|
+
new_line = cc_net_normalize(line)
|
|
168
|
+
print(f"== {line} -> {new_line}")
|
cluster_estimator.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
import math
|
|
14
|
+
|
|
15
|
+
from data_processing.utils import GB
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
This is a small code, that should be run locally to get the estimate of required cluster based on the amount
|
|
20
|
+
the documents to be processed and Ray worker nodes numbers of CPUs. These values can
|
|
21
|
+
be modified based on the job you need to run. The rest of the values are based on the experience of running
|
|
22
|
+
exact dedup and should not be modified.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# change these parameters for specific use case
|
|
26
|
+
av_table_size = 189056510 # bytes
|
|
27
|
+
number_of_docs = 4179209729
|
|
28
|
+
|
|
29
|
+
# Number of workers
|
|
30
|
+
n_workers = 1000
|
|
31
|
+
# pod cpus
|
|
32
|
+
ray_node_cpu = 15
|
|
33
|
+
# cpu sizes fo actors
|
|
34
|
+
worker_cpu = 0.75
|
|
35
|
+
hash_cpu = 0.5
|
|
36
|
+
|
|
37
|
+
print(f"suggested number of workers {n_workers}")
|
|
38
|
+
|
|
39
|
+
n_hashes = math.ceil(number_of_docs * 32 / GB)
|
|
40
|
+
required_hash_cpu = n_hashes * hash_cpu
|
|
41
|
+
required_hash_mem = n_hashes * 2
|
|
42
|
+
|
|
43
|
+
print(
|
|
44
|
+
f"Estimated Required hashes {n_hashes}, cpus for hashes {required_hash_cpu}, "
|
|
45
|
+
f"memory for hashes {required_hash_mem} GB"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
execution_required_cpus = math.ceil((worker_cpu * n_workers + required_hash_cpu) / 0.85)
|
|
49
|
+
|
|
50
|
+
print(f"required cpus for execution: {execution_required_cpus}")
|
|
51
|
+
n_ray_nodes = math.ceil(execution_required_cpus / ray_node_cpu)
|
|
52
|
+
print(f"Required ray nodes with {ray_node_cpu} cpus is {n_ray_nodes}")
|
|
53
|
+
|
|
54
|
+
execution_required_memory = math.ceil((n_workers * av_table_size * 4 / GB + required_hash_cpu) / 0.6)
|
|
55
|
+
print(f"required memory for execution: {execution_required_memory}")
|
|
56
|
+
print(
|
|
57
|
+
f"Minimal required memory per ray pod is {math.ceil(execution_required_memory / n_ray_nodes)} GB. "
|
|
58
|
+
f"Practically use the larger number"
|
|
59
|
+
)
|
code2parquet_local.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
import ast
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
from code2parquet_transform import ( # domain_key,; snapshot_key,
|
|
17
|
+
CodeToParquetTransform,
|
|
18
|
+
data_factory_key,
|
|
19
|
+
detect_programming_lang_key,
|
|
20
|
+
supported_langs_file_key,
|
|
21
|
+
)
|
|
22
|
+
from data_processing.data_access import DataAccessFactory, DataAccessLocal
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
supported_languages_file = os.path.abspath(
|
|
26
|
+
os.path.join(os.path.dirname(__file__), "../../ray/test-data/languages/lang_extensions.json")
|
|
27
|
+
)
|
|
28
|
+
input_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../test-data/input"))
|
|
29
|
+
|
|
30
|
+
params = {
|
|
31
|
+
supported_langs_file_key: supported_languages_file,
|
|
32
|
+
detect_programming_lang_key: True,
|
|
33
|
+
# snapshot_key: "github",
|
|
34
|
+
# domain_key: "code",
|
|
35
|
+
"data_files_to_use": ast.literal_eval("['.zip']"),
|
|
36
|
+
data_factory_key: DataAccessFactory(), # Expect to create DataAccessLocal
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
# Here we show how to run outside of ray
|
|
41
|
+
# Create and configure the transform.
|
|
42
|
+
# transform = CodeToParquetPythonTransform(params)
|
|
43
|
+
transform = CodeToParquetTransform(params)
|
|
44
|
+
# Use the local data access to read a parquet table.
|
|
45
|
+
data_access = DataAccessLocal()
|
|
46
|
+
file_to_process = os.path.join(input_folder, "application-java.zip")
|
|
47
|
+
byte_array, _ = data_access.get_file(file_to_process)
|
|
48
|
+
# Transform the table
|
|
49
|
+
files_list, metadata = transform.transform_binary(file_name=file_to_process, byte_array=byte_array)
|
|
50
|
+
print(f"Got {len(files_list)} output files")
|
|
51
|
+
print(f"output metadata : {metadata}")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
import ast
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
from code2parquet_transform import ( # domain_key,; snapshot_key,
|
|
18
|
+
detect_programming_lang_cli_key,
|
|
19
|
+
supported_langs_file_cli_key,
|
|
20
|
+
)
|
|
21
|
+
from code2parquet_transform_python import CodeToParquetPythonConfiguration
|
|
22
|
+
from data_processing.runtime.pure_python import PythonTransformLauncher
|
|
23
|
+
from data_processing.utils import ParamsUtils
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# create parameters
|
|
27
|
+
supported_languages_file = os.path.abspath(
|
|
28
|
+
os.path.join(os.path.dirname(__file__), "../test-data/languages/lang_extensions.json")
|
|
29
|
+
)
|
|
30
|
+
input_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../test-data/input"))
|
|
31
|
+
output_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../output"))
|
|
32
|
+
local_conf = {
|
|
33
|
+
"input_folder": input_folder,
|
|
34
|
+
"output_folder": output_folder,
|
|
35
|
+
}
|
|
36
|
+
worker_options = {"num_cpus": 0.8}
|
|
37
|
+
code_location = {"github": "github", "commit_hash": "12345", "path": "path"}
|
|
38
|
+
ingest_config = {
|
|
39
|
+
supported_langs_file_cli_key: supported_languages_file,
|
|
40
|
+
detect_programming_lang_cli_key: True,
|
|
41
|
+
# snapshot_key: "github",
|
|
42
|
+
# domain_key: "code",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
params = {
|
|
46
|
+
# Data access. Only required parameters are specified
|
|
47
|
+
"data_local_config": ParamsUtils.convert_to_ast(local_conf),
|
|
48
|
+
"data_files_to_use": ast.literal_eval("['.zip']"),
|
|
49
|
+
# orchestrator
|
|
50
|
+
"runtime_pipeline_id": "pipeline_id",
|
|
51
|
+
"runtime_job_id": "job_id",
|
|
52
|
+
"runtime_code_location": ParamsUtils.convert_to_ast(code_location),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
sys.argv = ParamsUtils.dict_to_req(d=(params | ingest_config))
|
|
57
|
+
# create launcher
|
|
58
|
+
launcher = PythonTransformLauncher(CodeToParquetPythonConfiguration())
|
|
59
|
+
# launch
|
|
60
|
+
launcher.launch()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
import ast
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
from code2parquet_transform import (
|
|
18
|
+
detect_programming_lang_cli_key,
|
|
19
|
+
supported_langs_file_cli_key,
|
|
20
|
+
)
|
|
21
|
+
from code2parquet_transform_ray import CodeToParquetRayConfiguration
|
|
22
|
+
from data_processing.utils import GB, ParamsUtils
|
|
23
|
+
from data_processing_ray.runtime.ray import RayTransformLauncher
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# create parameters
|
|
27
|
+
supported_languages_file = os.path.abspath(
|
|
28
|
+
os.path.join(os.path.dirname(__file__), "../test-data/languages/lang_extensions.json")
|
|
29
|
+
)
|
|
30
|
+
input_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../test-data/input"))
|
|
31
|
+
output_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../output"))
|
|
32
|
+
local_conf = {
|
|
33
|
+
"input_folder": input_folder,
|
|
34
|
+
"output_folder": output_folder,
|
|
35
|
+
}
|
|
36
|
+
worker_options = {"num_cpus": 0.8, "memory": 2 * GB}
|
|
37
|
+
code_location = {"github": "github", "commit_hash": "12345", "path": "path"}
|
|
38
|
+
ingest_config = {
|
|
39
|
+
supported_langs_file_cli_key: supported_languages_file,
|
|
40
|
+
detect_programming_lang_cli_key: True,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
params = {
|
|
44
|
+
# where to run
|
|
45
|
+
"run_locally": True,
|
|
46
|
+
# Data access. Only required parameters are specified
|
|
47
|
+
"data_local_config": ParamsUtils.convert_to_ast(local_conf),
|
|
48
|
+
"data_files_to_use": ast.literal_eval("['.zip']"),
|
|
49
|
+
# orchestrator
|
|
50
|
+
"runtime_worker_options": ParamsUtils.convert_to_ast(worker_options),
|
|
51
|
+
"runtime_num_workers": 3,
|
|
52
|
+
"runtime_pipeline_id": "pipeline_id",
|
|
53
|
+
"runtime_job_id": "job_id",
|
|
54
|
+
"runtime_creation_delay": 0,
|
|
55
|
+
"runtime_code_location": ParamsUtils.convert_to_ast(code_location),
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
sys.argv = ParamsUtils.dict_to_req(d=(params | ingest_config))
|
|
60
|
+
# create launcher
|
|
61
|
+
launcher = RayTransformLauncher(CodeToParquetRayConfiguration())
|
|
62
|
+
# launch
|
|
63
|
+
launcher.launch()
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
import ast
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from code2parquet_transform import ( # domain_key,; snapshot_key,
|
|
17
|
+
detect_programming_lang_cli_key,
|
|
18
|
+
supported_langs_file_cli_key,
|
|
19
|
+
)
|
|
20
|
+
from code2parquet_transform_python import CodeToParquetPythonConfiguration
|
|
21
|
+
from data_processing.runtime.pure_python import PythonTransformLauncher
|
|
22
|
+
from data_processing.utils import GB, ParamsUtils
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# create parameters
|
|
26
|
+
s3_cred = {
|
|
27
|
+
"access_key": "localminioaccesskey",
|
|
28
|
+
"secret_key": "localminiosecretkey",
|
|
29
|
+
"url": "http://localhost:9000",
|
|
30
|
+
}
|
|
31
|
+
s3_conf = {
|
|
32
|
+
"input_folder": "test/ingest_2_parquet/input",
|
|
33
|
+
"output_folder": "test/ingest_2_parquet/output",
|
|
34
|
+
}
|
|
35
|
+
worker_options = {"num_cpus": 0.8, "memory": 2 * GB}
|
|
36
|
+
code_location = {"github": "github", "commit_hash": "12345", "path": "path"}
|
|
37
|
+
ingest_config = {
|
|
38
|
+
supported_langs_file_cli_key: "test/ingest_2_parquet/languages/lang_extensions.json",
|
|
39
|
+
detect_programming_lang_cli_key: True,
|
|
40
|
+
# snapshot_key: "github",
|
|
41
|
+
# domain_key: "code",
|
|
42
|
+
"code2parquet_s3_cred": ParamsUtils.convert_to_ast(s3_cred),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
params = {
|
|
46
|
+
# Data access. Only required parameters are specified
|
|
47
|
+
"data_s3_cred": ParamsUtils.convert_to_ast(s3_cred),
|
|
48
|
+
"data_s3_config": ParamsUtils.convert_to_ast(s3_conf),
|
|
49
|
+
"data_files_to_use": ast.literal_eval("['.zip']"),
|
|
50
|
+
# orchestrator
|
|
51
|
+
"runtime_pipeline_id": "pipeline_id",
|
|
52
|
+
"runtime_job_id": "job_id",
|
|
53
|
+
"runtime_code_location": ParamsUtils.convert_to_ast(code_location),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
sys.argv = ParamsUtils.dict_to_req(d=(params | ingest_config))
|
|
58
|
+
# create launcher
|
|
59
|
+
launcher = PythonTransformLauncher(CodeToParquetPythonConfiguration())
|
|
60
|
+
# launch
|
|
61
|
+
launcher.launch()
|
code2parquet_s3_ray.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# (C) Copyright IBM Corp. 2024.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
import ast
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from code2parquet_transform import (
|
|
17
|
+
detect_programming_lang_cli_key,
|
|
18
|
+
supported_langs_file_cli_key,
|
|
19
|
+
)
|
|
20
|
+
from code2parquet_transform_ray import CodeToParquetRayConfiguration
|
|
21
|
+
from data_processing.utils import GB, ParamsUtils
|
|
22
|
+
from data_processing_ray.runtime.ray import RayTransformLauncher
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# create parameters
|
|
26
|
+
s3_cred = {
|
|
27
|
+
"access_key": "localminioaccesskey",
|
|
28
|
+
"secret_key": "localminiosecretkey",
|
|
29
|
+
"url": "http://localhost:9000",
|
|
30
|
+
}
|
|
31
|
+
s3_conf = {
|
|
32
|
+
"input_folder": "test/ingest_2_parquet/input",
|
|
33
|
+
"output_folder": "test/ingest_2_parquet/output",
|
|
34
|
+
}
|
|
35
|
+
worker_options = {"num_cpus": 0.8, "memory": 2 * GB}
|
|
36
|
+
code_location = {"github": "github", "commit_hash": "12345", "path": "path"}
|
|
37
|
+
ingest_config = {
|
|
38
|
+
supported_langs_file_cli_key: "test/ingest_2_parquet/languages/lang_extensions.json",
|
|
39
|
+
detect_programming_lang_cli_key: True,
|
|
40
|
+
"code2parquet_s3_cred": ParamsUtils.convert_to_ast(s3_cred),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
params = {
|
|
44
|
+
# where to run
|
|
45
|
+
"run_locally": True,
|
|
46
|
+
# Data access. Only required parameters are specified
|
|
47
|
+
"data_s3_cred": ParamsUtils.convert_to_ast(s3_cred),
|
|
48
|
+
"data_s3_config": ParamsUtils.convert_to_ast(s3_conf),
|
|
49
|
+
"data_files_to_use": ast.literal_eval("['.zip']"),
|
|
50
|
+
# orchestrator
|
|
51
|
+
"runtime_worker_options": ParamsUtils.convert_to_ast(worker_options),
|
|
52
|
+
"runtime_num_workers": 3,
|
|
53
|
+
"runtime_pipeline_id": "pipeline_id",
|
|
54
|
+
"runtime_job_id": "job_id",
|
|
55
|
+
"runtime_creation_delay": 0,
|
|
56
|
+
"runtime_code_location": ParamsUtils.convert_to_ast(code_location),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
sys.argv = ParamsUtils.dict_to_req(d=(params | ingest_config))
|
|
61
|
+
# create launcher
|
|
62
|
+
launcher = RayTransformLauncher(CodeToParquetRayConfiguration())
|
|
63
|
+
# launch
|
|
64
|
+
launcher.launch()
|