-
Notifications
You must be signed in to change notification settings - Fork 92
refactor(clp-py-utils): Move CLP metadata DB table-creation logic into utility module; Conditionally create the datasets table when using the CLP_S storage engine.
#831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
69307e6
Add dataset specification to compress script
Bill-hbrhbr bd230c0
Add missing commas
Bill-hbrhbr c501c9e
Create table entries upon getting new dataset names
Bill-hbrhbr 6b909d7
Add local cache
Bill-hbrhbr 4d14449
Move table creation to helpers
Bill-hbrhbr e008fb8
Typo fix
Bill-hbrhbr f600d25
Revert "Move table creation to helpers"
Bill-hbrhbr a46bb7d
Create utils file for creating sql tables
Bill-hbrhbr 5f43ab7
Apply to dataset table creation
Bill-hbrhbr 3f19234
Remove unrelated change
Bill-hbrhbr 5ffcf92
Move datasets table creation into compression runtime. Optimize the l…
Bill-hbrhbr 279c339
Revert --dataset interface changes
Bill-hbrhbr 2ba9525
Remove unrelated changes
Bill-hbrhbr 9d9d0d6
Move all table creations into utility file
Bill-hbrhbr bd33ebc
Fix bugs
Bill-hbrhbr 01618f8
Fix datasets table schema
Bill-hbrhbr 45258ce
Group metadata db tables creation into a single function
Bill-hbrhbr c8bf33d
Fix typo
Bill-hbrhbr f18089b
Remove logging statements
Bill-hbrhbr 943020f
Add missing import
Bill-hbrhbr ff83cc7
Add type for db_cursor
Bill-hbrhbr c0cacfd
Change table creation functions from public to private and change to …
Bill-hbrhbr 9ca99d9
rename utils file
Bill-hbrhbr d07e3f4
Fix typo
Bill-hbrhbr 6d1b356
Use pipe syntax
Bill-hbrhbr ec106ba
Merge branch 'main' into add-dataset-tables
Bill-hbrhbr ad67fd9
Propagate storage engine config to metadata db table creation code
Bill-hbrhbr 5f2cde5
Syntax fix
Bill-hbrhbr b62e26a
Add dataset TODO
Bill-hbrhbr 58d46da
Add dataset table creation
Bill-hbrhbr 32c369d
Add todo for dataset table default entries
Bill-hbrhbr 84ee737
Add docstring
Bill-hbrhbr 6fd2536
Apply suggestions from code review
Bill-hbrhbr ab2654a
Address review concerns
Bill-hbrhbr eaa0550
Stil create the column metadata for the indexer
Bill-hbrhbr bc5ee6e
add comment
Bill-hbrhbr 9a82570
Apply suggestions from code review
Bill-hbrhbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
142 changes: 142 additions & 0 deletions
142
components/clp-py-utils/clp_py_utils/clp_metadata_db_utils.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from clp_py_utils.clp_config import ( | ||
| ARCHIVE_TAGS_TABLE_SUFFIX, | ||
| ARCHIVES_TABLE_SUFFIX, | ||
| CLP_DEFAULT_DATASET_NAME, | ||
| COLUMN_METADATA_TABLE_SUFFIX, | ||
| DATASETS_TABLE_SUFFIX, | ||
| FILES_TABLE_SUFFIX, | ||
| TAGS_TABLE_SUFFIX, | ||
| ) | ||
|
|
||
|
|
||
| def _create_archives_table(db_cursor, archives_table_name: str) -> None: | ||
| db_cursor.execute( | ||
| f""" | ||
| CREATE TABLE IF NOT EXISTS `{archives_table_name}` ( | ||
| `pagination_id` BIGINT unsigned NOT NULL AUTO_INCREMENT, | ||
| `id` VARCHAR(64) NOT NULL, | ||
| `begin_timestamp` BIGINT NOT NULL, | ||
| `end_timestamp` BIGINT NOT NULL, | ||
| `uncompressed_size` BIGINT NOT NULL, | ||
| `size` BIGINT NOT NULL, | ||
| `creator_id` VARCHAR(64) NOT NULL, | ||
| `creation_ix` INT NOT NULL, | ||
| KEY `archives_creation_order` (`creator_id`,`creation_ix`) USING BTREE, | ||
| UNIQUE KEY `archive_id` (`id`) USING BTREE, | ||
| PRIMARY KEY (`pagination_id`) | ||
| ) | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def _create_tags_table(db_cursor, tags_table_name: str) -> None: | ||
| db_cursor.execute( | ||
| f""" | ||
| CREATE TABLE IF NOT EXISTS `{tags_table_name}` ( | ||
| `tag_id` INT unsigned NOT NULL AUTO_INCREMENT, | ||
| `tag_name` VARCHAR(255) NOT NULL, | ||
| UNIQUE KEY (`tag_name`) USING BTREE, | ||
| PRIMARY KEY (`tag_id`) | ||
| ) | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def _create_archive_tags_table( | ||
| db_cursor, archive_tags_table_name: str, archives_table_name: str, tags_table_name: str | ||
| ) -> None: | ||
| db_cursor.execute( | ||
| f""" | ||
| CREATE TABLE IF NOT EXISTS `{archive_tags_table_name}` ( | ||
| `archive_id` VARCHAR(64) NOT NULL, | ||
| `tag_id` INT unsigned NOT NULL, | ||
| PRIMARY KEY (`archive_id`,`tag_id`), | ||
| FOREIGN KEY (`archive_id`) REFERENCES `{archives_table_name}` (`id`), | ||
| FOREIGN KEY (`tag_id`) REFERENCES `{tags_table_name}` (`tag_id`) | ||
| ) | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def _create_files_table(db_cursor, table_prefix: str) -> None: | ||
| db_cursor.execute( | ||
| f""" | ||
| CREATE TABLE IF NOT EXISTS `{table_prefix}{FILES_TABLE_SUFFIX}` ( | ||
| `id` VARCHAR(64) NOT NULL, | ||
| `orig_file_id` VARCHAR(64) NOT NULL, | ||
| `path` VARCHAR(12288) NOT NULL, | ||
| `begin_timestamp` BIGINT NOT NULL, | ||
| `end_timestamp` BIGINT NOT NULL, | ||
| `num_uncompressed_bytes` BIGINT NOT NULL, | ||
| `begin_message_ix` BIGINT NOT NULL, | ||
| `num_messages` BIGINT NOT NULL, | ||
| `archive_id` VARCHAR(64) NOT NULL, | ||
| KEY `files_path` (path(768)) USING BTREE, | ||
| KEY `files_archive_id` (`archive_id`) USING BTREE, | ||
| PRIMARY KEY (`id`) | ||
| ) ROW_FORMAT=DYNAMIC | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def _create_column_metadata_table(db_cursor, table_name: str) -> None: | ||
| db_cursor.execute( | ||
| f""" | ||
| CREATE TABLE IF NOT EXISTS `{table_name}` ( | ||
| `name` VARCHAR(512) NOT NULL, | ||
| `type` TINYINT NOT NULL, | ||
| PRIMARY KEY (`name`, `type`) | ||
| ) | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def create_datasets_table(db_cursor, table_prefix: str) -> None: | ||
| """ | ||
| Creates the dataset information table. | ||
|
|
||
| :param db_cursor: The database cursor to execute the table creation. | ||
| :param table_prefix: A string to prepend to the table name. | ||
| """ | ||
| db_cursor.execute( | ||
| f""" | ||
| CREATE TABLE IF NOT EXISTS `{table_prefix}{DATASETS_TABLE_SUFFIX}` ( | ||
| `name` VARCHAR(255) NOT NULL, | ||
| `archive_storage_directory` VARCHAR(4096) NOT NULL, | ||
| PRIMARY KEY (`name`) | ||
| ) | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def create_metadata_db_tables(db_cursor, table_prefix: str, dataset: str | None = None) -> None: | ||
| """ | ||
| Creates the standard set of tables for CLP's metadata. | ||
|
|
||
| :param db_cursor: The database cursor to execute the table creations. | ||
| :param table_prefix: A string to prepend to all table names. | ||
| :param dataset: If set, all tables will be named in a dataset-specific manner. | ||
| """ | ||
| if dataset is not None: | ||
| table_prefix = f"{table_prefix}{dataset}_" | ||
|
|
||
| archives_table_name = f"{table_prefix}{ARCHIVES_TABLE_SUFFIX}" | ||
| tags_table_name = f"{table_prefix}{TAGS_TABLE_SUFFIX}" | ||
| archive_tags_table_name = f"{table_prefix}{ARCHIVE_TAGS_TABLE_SUFFIX}" | ||
|
|
||
| # TODO: Update this to | ||
| # {table_prefix}{CLP_DEFAULT_DATASET_NAME}_{COLUMN_METADATA_TABLE_SUFFIX} when we can also | ||
| # change the indexer to match. | ||
| column_metadata_table_name = ( | ||
| f"{table_prefix}{COLUMN_METADATA_TABLE_SUFFIX}_{CLP_DEFAULT_DATASET_NAME}" | ||
| ) | ||
|
|
||
| _create_archives_table(db_cursor, archives_table_name) | ||
| _create_tags_table(db_cursor, tags_table_name) | ||
| _create_archive_tags_table( | ||
| db_cursor, archive_tags_table_name, archives_table_name, tags_table_name | ||
| ) | ||
| _create_files_table(db_cursor, table_prefix) | ||
| _create_column_metadata_table(db_cursor, column_metadata_table_name) | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.