Skip to content
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

SQLite utility methods #366

Merged
merged 18 commits into from
Dec 8, 2022
Merged

Conversation

asogaard
Copy link
Collaborator

@asogaard asogaard commented Dec 6, 2022

Closes #358

cc @Peterandresen12

Copy link
Collaborator

@RasmusOrsoe RasmusOrsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey. I had a look here, and I can't by eye gauge if this works as intended. I would need to test these new changes to make sure everything works as intended.

Because parquet_to_sqlite_converter relies on these sqlite functions, which are also used by the sqlite_data_converter, we could end up in a situation where we change something based on usage of the sqlite_data_converter that breaks the parquet_to_sqlite_converter. So a unit test might be a good idea here.

@asogaard
Copy link
Collaborator Author

asogaard commented Dec 8, 2022

The functions that are used in parquet_to_sqlite_converter and sqlite_data_converter are virtually identical, which is why it would make sense to consolidate them and why I think the risk of introducing bugs is quite small. But I agree that unit tests are always healthy! I'll look into adding one — let me know if you have any concrete suggestions you'd like the test(s) to do. :)

@asogaard
Copy link
Collaborator Author

asogaard commented Dec 8, 2022

Alright, have added a unit test now, @RasmusOrsoe. The existing unit test converts a test I3-file using both ParquetDataConverter and SQLiteDataConverter. The new test then further converts the parquet output into a second SQLite database and compares this to the output of the SQLiteDataConverter. If this conversion works, and if the two databases look the same (i.e. have the same number of events, and identical feature tensors for each event) then we considering the code running as intended. :)

Copy link
Collaborator

@RasmusOrsoe RasmusOrsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! I think this is great.

Could we add a second test that checks that the tables are indexed correctly? I have a conceptual snippet here:

def test_search_plan(sqlite_database, parquet_converted_database, pulsemap, event_no = 1):
    with sqlite3.connect(sqlite_database) as con:
        query = f'EXPLAIN QUERY PLAN SELECT * FROM {pulsemap} WHERE event_no={event_no}'
        sqlite_plan  = pd.read_sql(query,con)

    with sqlite3.connect(parquet_converted_database) as con:
        query = f'EXPLAIN QUERY PLAN SELECT * FROM {pulsemap} WHERE event_no={event_no}'
        parquet_plan  = pd.read_sql(query,con)
    
    assert 'USING INDEX event_no' in sqlite_plan['detail']
    assert 'USING INDEX event_no' in parquet_plan['detail']
    
    assert sqlite_plan['detail'] == parquet_plan['detail']

    return

Testing one event_no is enough pr. pulsemap

@asogaard
Copy link
Collaborator Author

asogaard commented Dec 8, 2022

There we go, @RasmusOrsoe: Have now added a unit test like the one suggested, and... it actually caught a (seemingly ancient) bug! 🎉 One place in the SQLiteDataConverter, the index wasn't being attached to the pulse map table. I have added a create_table_and_save_to_sql function that automatically creates a table being saved to if it doesn't already exist.

Copy link
Collaborator

@RasmusOrsoe RasmusOrsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!!

I will sleep better after this :-)

@asogaard asogaard merged commit f64a29a into graphnet-team:main Dec 8, 2022
@asogaard asogaard deleted the sqlite-utility-methods branch December 8, 2022 12:51
RasmusOrsoe pushed a commit to RasmusOrsoe/graphnet that referenced this pull request Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature I3FeatureExtractorIceCube86 has issues when "pulse" is not in the name of the pulsemap
2 participants