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

Combine multiple PEcAn.db calls in a single query #3312

Merged
merged 10 commits into from
Jul 10, 2024

Conversation

Sweetdevil144
Copy link
Contributor

Description

This is an example demonstration of how we may proceed with : Refactor convert_input.R to Optimise Workflow #3307

Motivation and Context

Review Time Estimate

  • Immediately
  • Within one week
  • When possible

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • My name is in the list of CITATION.cff
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

This is an example demonstration of how we may proceed with Refactor `convert_input.R` to Optimise Workflow PecanProject#3307

Signed-off-by: Abhinav Pandey <[email protected]>
# Retrieve format name and mimetype from the database
register$format <- PEcAn.DB::db.query(
paste("SELECT name, mime_type AS mimetype FROM formats WHERE id = ", register$format$id), con
)
Copy link
Member

Choose a reason for hiding this comment

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

Two problems here:

  1. Assigning the result to register$format will overwrite the existing format object (which contains at least id and inputtype -- see lines 25 and 35) with one that contains only name and mimetype. Better to query once into a temporary result and then assign from there into register$format$name and `register$format$mimetype.
  2. The existing line 41 is broken because the formats table doesn't have a mime_type column, it has a mimetype_id tht then needs to be looked up in the mimetypes table. I think you want "SELECT name, type_string AS mimetype FROM formats JOIN mimetypes ON formats.mimetype_id = mimetypes.id WHERE formats.id ="

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I seemed to miss it. Fixing it now.
  2. Ahh, I recall us having a conversation about this earlier and that seems to be the case.

Sweetdevil144 and others added 2 commits June 28, 2024 16:04
Change broken `mime_type` to `mimetype_id`. Suggested by @infotroph

Signed-off-by: Abhinav Pandey <[email protected]>
@infotroph infotroph added this pull request to the merge queue Jul 10, 2024
Merged via the queue into PecanProject:develop with commit 1fd72ab Jul 10, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants