1+ import typing
2+
13import pytest
24
35import neptune_query as npt
79)
810from neptune_query .filters import AttributeFilter
911from neptune_query .internal import identifiers
12+ from neptune_query .internal .filters import (
13+ _AttributeFilter ,
14+ _Filter ,
15+ )
1016from neptune_query .internal .identifiers import (
1117 AttributeDefinition ,
1218 RunAttributeDefinition ,
1319)
20+ from neptune_query .internal .retrieval import search
1421from neptune_query .internal .retrieval .attribute_definitions import fetch_attribute_definitions_single_filter
1522from neptune_query .internal .retrieval .attribute_values import (
1623 AttributeValue ,
2330 fetch_series_values ,
2431)
2532from tests .e2e .conftest import extract_pages
26- from tests .e2e .data import (
27- NOW ,
28- PATH ,
29- TEST_DATA ,
33+ from tests .e2e .data_ingestion import (
34+ IngestedProjectData ,
35+ ProjectData ,
36+ RunData ,
37+ step_to_timestamp ,
3038)
3139
32- LONG_PATH_CONFIGS = TEST_DATA .experiments [0 ].long_path_configs
33- LONG_PATH_SERIES = TEST_DATA .experiments [0 ].long_path_series
34- LONG_PATH_METRICS = TEST_DATA .experiments [0 ].long_path_metrics
40+ MAX_PATH_LENGTH = 1024
41+ NUM_LONG_ATTRIBUTES = 4000
42+ STEP = 1.0
43+ STEP_TIMESTAMP_MS = int (step_to_timestamp (STEP ).timestamp () * 1000 )
44+
45+ _LONG_CONFIG_PREFIX = "int-value-"
46+ _LONG_CONFIG_DIGITS = MAX_PATH_LENGTH - len (_LONG_CONFIG_PREFIX )
47+ LONG_PATH_CONFIGS = {f"{ _LONG_CONFIG_PREFIX } { k :0{_LONG_CONFIG_DIGITS }d} " : k for k in range (NUM_LONG_ATTRIBUTES )}
48+
49+ _LONG_SERIES_PREFIX = "string-series-"
50+ _LONG_SERIES_DIGITS = MAX_PATH_LENGTH - len (_LONG_SERIES_PREFIX )
51+ LONG_PATH_SERIES = {
52+ f"{ _LONG_SERIES_PREFIX } { k :0{_LONG_SERIES_DIGITS }d} " : f"string-{ k } " for k in range (NUM_LONG_ATTRIBUTES )
53+ }
54+
55+ _LONG_METRICS_PREFIX = "float-series-"
56+ _LONG_METRICS_DIGITS = MAX_PATH_LENGTH - len (_LONG_METRICS_PREFIX )
57+ LONG_PATH_METRICS = {
58+ f"{ _LONG_METRICS_PREFIX } { k :0{_LONG_METRICS_DIGITS }d} " : float (k ) for k in range (NUM_LONG_ATTRIBUTES )
59+ }
60+
61+
62+ @pytest .fixture (scope = "module" )
63+ def project (ensure_project ) -> IngestedProjectData :
64+ project_data = ProjectData (
65+ project_name_base = "split-project" ,
66+ runs = [
67+ RunData (
68+ experiment_name_base = f"split-experiment-{ index } " ,
69+ run_id_base = f"split-run-{ index } " ,
70+ configs = {** LONG_PATH_CONFIGS },
71+ string_series = {path : {STEP : value } for path , value in LONG_PATH_SERIES .items ()},
72+ float_series = {path : {STEP : value } for path , value in LONG_PATH_METRICS .items ()},
73+ )
74+ for index in range (3 )
75+ ],
76+ )
77+
78+ return ensure_project (project_data )
79+
80+
81+ @pytest .fixture (scope = "module" )
82+ def experiment_identifiers (client , project ):
83+ project_identifier = identifiers .ProjectIdentifier (project .project_identifier )
84+ experiment_names = [run .experiment_name for run in project .ingested_runs ]
85+ identifiers_by_name : list [identifiers .RunIdentifier ] = []
86+
87+ for experiment_name in experiment_names :
88+ sys_ids : list [identifiers .SysId ] = []
89+ for page in search .fetch_experiment_sys_ids (
90+ client = client ,
91+ project_identifier = project_identifier ,
92+ filter_ = _Filter .name_eq (experiment_name ),
93+ ):
94+ sys_ids .extend (page .items )
95+
96+ if len (sys_ids ) != 1 :
97+ raise RuntimeError (f"Expected to fetch exactly one sys_id for { experiment_name } , got { sys_ids } " )
98+
99+ identifiers_by_name .append (identifiers .RunIdentifier (project_identifier , identifiers .SysId (sys_ids [0 ])))
100+
101+ return identifiers_by_name
35102
36103
37104@pytest .mark .parametrize (
@@ -46,19 +113,15 @@ def test_fetch_attribute_definitions_retrieval(client, project, experiment_ident
46113 # given
47114 exp_identifiers = experiment_identifiers [:exp_limit ]
48115 attribute_paths = list (LONG_PATH_CONFIGS .keys ())[:attr_limit ]
49- project_identifier = project .project_identifier
116+ project_identifier = identifiers .ProjectIdentifier (project .project_identifier )
117+ attribute_filter = typing .cast (_AttributeFilter , _attribute_filter ("int-value" , attr_limit )._to_internal ())
50118
51119 # when
52120 result = None
53121 thrown_e = None
54122 try :
55123 result = extract_pages (
56- fetch_attribute_definitions_single_filter (
57- client ,
58- [project_identifier ],
59- exp_identifiers ,
60- attribute_filter = _attribute_filter ("int-value" , attr_limit )._to_internal (),
61- )
124+ fetch_attribute_definitions_single_filter (client , [project_identifier ], exp_identifiers , attribute_filter )
62125 )
63126 except NeptuneUnexpectedResponseError as e :
64127 thrown_e = e
@@ -82,7 +145,7 @@ def test_fetch_attribute_definitions_retrieval(client, project, experiment_ident
82145)
83146def test_fetch_attribute_definitions_composition (client , project , experiment_identifiers , exp_limit , attr_limit ):
84147 # given
85- exp_names = TEST_DATA . experiment_names [:exp_limit ]
148+ exp_names = [ run . experiment_name for run in project . ingested_runs ] [:exp_limit ]
86149 attribute_paths = list (LONG_PATH_CONFIGS .keys ())[:attr_limit ]
87150
88151 # when
@@ -108,7 +171,7 @@ def test_fetch_attribute_values_retrieval(client, project, experiment_identifier
108171 # given
109172 exp_identifiers = experiment_identifiers [:exp_limit ]
110173 attribute_data = dict (list (LONG_PATH_CONFIGS .items ())[:attr_limit ])
111- project_identifier = project .project_identifier
174+ project_identifier = identifiers . ProjectIdentifier ( project .project_identifier )
112175 attribute_definitions = [AttributeDefinition (key , "int" ) for key in attribute_data ]
113176
114177 # when
@@ -144,7 +207,7 @@ def test_fetch_attribute_values_retrieval(client, project, experiment_identifier
144207)
145208def test_fetch_attribute_values_composition (client , project , experiment_identifiers , exp_limit , attr_limit ):
146209 # given
147- exp_names = TEST_DATA . experiment_names [:exp_limit ]
210+ exp_names = [ run . experiment_name for run in project . ingested_runs ] [:exp_limit ]
148211 attribute_paths = list (LONG_PATH_CONFIGS .keys ())[:attr_limit ]
149212
150213 # when
@@ -201,7 +264,7 @@ def test_fetch_string_series_values_retrieval(client, project, experiment_identi
201264 expected_result = {
202265 RunAttributeDefinition (
203266 run_identifier = exp , attribute_definition = AttributeDefinition (key , "string_series" )
204- ): [SeriesValue (1.0 , value , int ( NOW . timestamp () * 1000 ) )]
267+ ): [SeriesValue (STEP , value , STEP_TIMESTAMP_MS )]
205268 for exp in exp_identifiers
206269 for key , value in attribute_data .items ()
207270 }
@@ -223,7 +286,7 @@ def test_fetch_string_series_values_retrieval(client, project, experiment_identi
223286)
224287def test_fetch_string_series_values_composition (client , project , experiment_identifiers , exp_limit , attr_limit ):
225288 # given
226- exp_names = TEST_DATA . experiment_names [:exp_limit ]
289+ exp_names = [ run . experiment_name for run in project . ingested_runs ] [:exp_limit ]
227290 attribute_paths = list (LONG_PATH_SERIES .keys ())[:attr_limit ]
228291
229292 # when
@@ -276,9 +339,9 @@ def test_fetch_float_series_values_retrieval(client, project, experiment_identif
276339 if success :
277340 expected_values = {
278341 RunAttributeDefinition (
279- run_identifier = identifiers . RunIdentifier ( project . project_identifier , exp . sys_id ) ,
280- attribute_definition = identifiers . AttributeDefinition (key , "float_series" ),
281- ): [(int ( NOW . timestamp () * 1000 ), 1.0 , value , False , 1.0 )]
342+ run_identifier = exp ,
343+ attribute_definition = AttributeDefinition (key , "float_series" ),
344+ ): [(STEP_TIMESTAMP_MS , STEP , value , False , STEP )]
282345 for exp in exp_identifiers
283346 for key , value in attribute_data .items ()
284347 }
@@ -299,7 +362,7 @@ def test_fetch_float_series_values_retrieval(client, project, experiment_identif
299362)
300363def test_fetch_float_series_values_composition (client , project , experiment_identifiers , exp_limit , attr_limit ):
301364 # given
302- exp_names = TEST_DATA . experiment_names [:exp_limit ]
365+ exp_names = [ run . experiment_name for run in project . ingested_runs ] [:exp_limit ]
303366 attribute_paths = list (LONG_PATH_METRICS .keys ())[:attr_limit ]
304367
305368 # when
@@ -316,4 +379,4 @@ def test_fetch_float_series_values_composition(client, project, experiment_ident
316379
317380def _attribute_filter (name , limit ):
318381 id_regex = "|" .join (str (n ) for n in range (limit ))
319- return AttributeFilter (name = f"^{ PATH } /long/ { name } -0+0({ id_regex } )$" )
382+ return AttributeFilter (name = f"^{ name } -0+0({ id_regex } )$" )
0 commit comments