Skip to content

Commit e70963a

Browse files
committed
WIP
1 parent 774df11 commit e70963a

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

api/py/ai/chronon/repo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
MODEL_FOLDER_NAME = "models"
2121
# TODO - make team part of thrift API?
2222
TEAMS_FILE_PATH = "teams.json"
23-
23+
OUTPUT_ROOT = "production"
2424

2525
# This is set in the main function -
2626
# from command line or from env variable during invocation

api/py/ai/chronon/repo/compilev2.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ def extract_and_convert(
7171
validator = ChrononRepoValidator(
7272
chronon_root, os.path.join(chronon_root_path, "production"), log_level=log_level
7373
)
74-
75-
successful_writes = {}
74+
7675
compile_errors = {}
7776

7877
for obj_folder_name in obj_folder_names:
@@ -88,7 +87,6 @@ def extract_and_convert(
8887
raise ValueError(f"Error in file {target_object_file}: \n {target_file_error}")
8988

9089
compile_errors.update(obj_folder_errors)
91-
num_written_objs = 0
9290

9391
full_output_root = os.path.join(chronon_root_path, output_root)
9492
teams_path = os.path.join(chronon_root_path, TEAMS_FILE_PATH)
@@ -106,12 +104,6 @@ def extract_and_convert(
106104
if obj_write_errors:
107105
compile_errors[origin_file] = obj_write_errors
108106
else:
109-
num_written_objs += 1
110-
111-
# TODO -- handle target object file and logging in case of failure.
112-
if obj == target_object:
113-
target_object_written = True
114-
115107
# In case of online join, we need to materialize the underlying online group_bys.
116108
if obj_class is Join and obj.metaData.online:
117109
online_group_bys = {}
@@ -126,10 +118,6 @@ def extract_and_convert(
126118
" You can do this by passing the `online=True` argument to the GroupBy constructor."
127119
" Fix the following: {}".format(offline_gbs)
128120
)
129-
130-
if num_written_objs > 0:
131-
obj_class_name = obj_class.__name__
132-
successful_writes[obj_class_name] = successful_writes.get(obj_class_name, 0) + num_written_objs
133121

134122
if compile_errors:
135123
create_error_logs(compile_errors, chronon_root)
@@ -155,8 +143,8 @@ def show_lineage_and_schema(target_object):
155143
raise NotImplementedError("TODO")
156144
except Exception as e:
157145

158-
_print_warning("Failed to connect to ZiplineHub (check connection and VPN settings). \n\n " +
159-
"Showing output column names, but cannot show schema/lineage without ZiplineHub.\n\n")
146+
_print_warning(f"Failed to connect to ZiplineHub: {str(e)}\n\n" +
147+
"Showing output column names, but cannot show schema/lineage without ZiplineHub.\n\n")
160148

161149
obj_class = target_object.__class__
162150

@@ -293,7 +281,3 @@ def _print_error(left, right):
293281
def _print_warning(string):
294282
# print in yellow - \u001b[33m
295283
print(f"\u001b[33m{string}\u001b[0m")
296-
297-
298-
if __name__ == "__main__":
299-
extract_and_convert()

api/py/ai/chronon/repo/extract_objects.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def from_folder(full_path: str, cls: type, log_level=logging.INFO):
4242

4343
def from_folderV2(full_path: str, target_file: str, cls: type):
4444
"""
45-
Recursively consumes a folder, and constructs a map
46-
Creates a map of object qualifier to
45+
Recursively consumes a folder, and constructs a map of
46+
object qualifier to StagingQuery, GroupBy, or Join
4747
"""
4848
if full_path.endswith("/"):
4949
full_path = full_path[:-1]
@@ -57,7 +57,6 @@ def from_folderV2(full_path: str, target_file: str, cls: type):
5757
results_dict = from_file(f, cls, log_level=logging.NOTSET)
5858
for k, v in results_dict.items():
5959
results[k] = (v, f)
60-
#results.update(from_file(f, cls, log_level=logging.NOTSET))
6160
except Exception as e:
6261
if f == target_file:
6362
target_file_error = e

api/py/ai/chronon/repo/runner.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
import inspect
33
from ai.chronon.repo.compilev2 import extract_and_convert
44
from ai.chronon.utils import get_mod_and_var_name_from_gc
5-
6-
# TODO -- how do we want to set this?
7-
OUTPUT_ROOT = "production"
5+
from ai.chronon.repo import (
6+
FOLDER_NAME_TO_CLASS,
7+
JOIN_FOLDER_NAME,
8+
GROUP_BY_FOLDER_NAME,
9+
STAGING_QUERY_FOLDER_NAME,
10+
MODEL_FOLDER_NAME,
11+
OUTPUT_ROOT
12+
)
813

914
def get_chronon_root(filepath):
1015
"""
1116
Infer chronon root from a filepath to a Chronon object
1217
"""
13-
target_dirs = {'group_bys', 'joins', 'staging_queries'}
18+
target_dirs = FOLDER_NAME_TO_CLASS.keys()
1419

1520
current_path = os.path.dirname(os.path.abspath(filepath))
1621

@@ -27,8 +32,13 @@ def get_target_compiled_file(zipline_obj):
2732
"""
2833
Given a compiled repository, identifies the compiled file
2934
for this entity
30-
"""
31-
zipline_obj_type = "group_bys"
35+
"""
36+
# Validate object is a valid Chronon type
37+
if not any(isinstance(zipline_obj, cls) for cls in FOLDER_NAME_TO_CLASS.values()):
38+
valid_types = [cls.__name__ for cls in FOLDER_NAME_TO_CLASS.values()]
39+
raise ValueError(f"Can only run one of {valid_types}, got {type(zipline_obj).__name__}")
40+
41+
zipline_obj_type = next(k for k, v in FOLDER_NAME_TO_CLASS.items() if v == zipline_obj.__class__)
3242

3343
zipline_obj_module, zipline_var_name = get_mod_and_var_name_from_gc(zipline_obj, zipline_obj_type)
3444

0 commit comments

Comments
 (0)