Refactor split raw data storage into a DataSetInSeparateSqliteDbFile subclass - #406
Open
astafan8 wants to merge 1 commit into
Open
Refactor split raw data storage into a DataSetInSeparateSqliteDbFile subclass#406astafan8 wants to merge 1 commit into
astafan8 wants to merge 1 commit into
Conversation
…bclass Move the per-dataset SQLite storage behaviour out of the config-flag conditionals in DataSet and into a dedicated DataSetInSeparateSqliteDbFile subclass, selected at the factory boundary. - Base DataSet gains generic results-backend hooks (no-ops by default): _setup_results_backend_on_load/_on_new_run/_on_start, plus the class attribute _creates_results_table_in_main_db. The generic 'results may live on a separate connection' routing (_data_conn, get_parameter_data, add_results) stays in the base and activates only when _raw_data_conn is populated. - DataSetInSeparateSqliteDbFile(DataSet) overrides only those hooks to create/ connect the per-dataset file and record raw_data_db_path. - Class selection moves to the factory boundary: new_data_set() and Measurement instantiate the subclass when the feature is enabled; a new _load_dataset_from_run_id() helper picks the subclass for existing runs that record a raw_data_db_path. Routed through experiment_container.data_set, extract_runs, and _get_datasetprotocol_from_guid. - Note: direct DataSet(run_id=...) construction on a split run no longer auto-detects the raw backend; use _load_dataset_from_run_id / load_by_id. Updated make_shadow_dataset accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on top of microsoft#8219 (targets
feature/split-raw-data-sqlite, notmain). Implements the subclass option from the "class structure" idea discussion: move the split raw data storage behaviour out of the config-flag conditionals insideDataSetinto a dedicatedDataSetInSeparateSqliteDbFile(DataSet)subclass, selected at the factory boundary.This is a prototype for review — it implements the architecture I described in the idea thread so it can be evaluated as an isolated diff.
What changes
Generic seam in the base
DataSetDataSetgains a small set of overridable hooks whose base implementations reproduce today's main-DB behaviour (all no-ops for a plainDataSet):_setup_results_backend_on_load(read_only)/_setup_results_backend_on_new_run()/_setup_results_backend_on_start()_creates_results_table_in_main_db = True_data_conn, theget_parameter_databypass, theadd_resultsbackground-writer item) stays in the base and only activates once_raw_data_connis populated. The backend-agnostic parts added earlier (_results_table_exists, tolerantnumber_of_results/__len__, deferred subscribers) also stay in the base.The SQLite backend subclass
DataSetInSeparateSqliteDbFile(DataSet)overrides only the hooks: create/connect the per-dataset<guid>.dbfile, recordraw_data_db_path, flip_creates_results_table_in_main_db = False. Allis_raw_data_storage_enabled()conditionals leaveDataSet.Class selection at the factory boundary
new_data_set()andMeasurementinstantiate the subclass when the feature is enabled._load_dataset_from_run_id()helper picks the subclass when the run records araw_data_db_path. Routed throughexperiment_container.data_set(),extract_runs_into_db,_copy_dataset_as_is, and_get_datasetprotocol_from_guid.Tradeoff surfaced by this refactor (worth a look)
Moving class selection to a factory means direct
DataSet(run_id=...)construction on a split run no longer auto-detects the raw backend — you must go through_load_dataset_from_run_id/load_by_id. In the current PR microsoft#8219 (config-flag design),DataSet.__init__auto-detects from the DB row, so direct construction "just works" everywhere.I routed every construction site in the library through the factory, and updated the
make_shadow_datasettest helper. But this is a real behavioural difference for any external code that constructsDataSet(run_id=...)directly. A composition/strategy design (aResultsBackendobject chosen insideDataSet.__init__) would keep the subclass-free base and preserve auto-detection — arguably the best of both. I'm flagging this so we can decide between:Either way, this cleanly sets up the future non-SQLite backends goal (a later
DataSetInSeparateFilebase, or additionalResultsBackendimplementations).Verification
test_raw_data_storage.py(+ new tests assertingnew_data_set/load_by_idreturn the subclass when enabled and a plainDataSetwhen disabled),test_database_extract_runs.py,test_export_datasets_and_create_metadata_db.py: 64 passed, 1 skipped.test_dataset_basic.py,dond/,test_measurement_extensions.py: 333 passed in default mode.tests/datasetsuite in default mode: 1064 passed, 35 skipped — no regressions.queries.get_parameter_data(ds.conn, ...)bypass tests, db-overview/guid-scan tests that inherently assume data in the main DB). One additional order-dependent flake under the randomized harness (test_do1d_additional_setpoints_shape) passes in isolation and in default mode.