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

Fixing minor item on csv parser #2

Merged
merged 3 commits into from
Oct 23, 2023
Merged

Conversation

madflojo
Copy link
Member

@madflojo madflojo commented Oct 23, 2023

Summary by CodeRabbit

  • New Feature: Implemented a CSV parser to process airport data more efficiently. This feature enhances the software's ability to handle large volumes of data and improves the overall data processing speed.
  • Refactor: Simplified error handling in the CSV parser. Instead of stopping at the first error, the parser now skips any problematic records and continues processing. This change increases the resilience of the data parsing process and ensures maximum data utilization.
  • Chore: Added logging for the number of airports fetched. This provides better visibility into the data fetching process and can help in troubleshooting if needed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2023

Walkthrough

The changes primarily focus on enhancing the airport data parsing process in the Go application. A CSV parser is introduced to parse the fetched data, and the error handling logic is improved to skip record-level errors, ensuring maximum data processing.

Changes

File Path Summary
functions/src/init/main.go Introduced the bytes package and a custom CSV parser package. The CSV parser is used to parse the fetched airport data. Added error handling and logging for the parsing process.
pkg/airport/parsers/csv/csv.go Modified the Parse method to skip record-level errors, simplifying the error handling process and allowing the parser to process as many valid records as possible.

🐇💻

In the land of code, where the brackets lie,

A rabbit hopped, with a twinkle in its eye.

Parsing data, skipping errors with glee,

"More airports to find!", it said with a spree. 🛫🌍


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 82de542 and ea8f496.
Files ignored due to filter (4)
  • functions/src/init/go.mod
  • functions/src/init/go.sum
  • go.mod
  • go.sum
Files selected for processing (2)
  • functions/src/init/main.go (2 hunks)
  • pkg/airport/parsers/csv/csv.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/airport/parsers/csv/csv.go
Additional comments (Suppressed): 5
functions/src/init/main.go (5)
  • 4-7: The new import statements are for the "bytes" package and a custom CSV parser package. Ensure that the "github.com/tarmac-project/example-airport-lookup-go/pkg/airport/parsers/csv" package is available and accessible.
    [APPROVE]

  • 18-22: The fetched airport data is now being stored in the data variable. This is a necessary change for the new CSV parser.
    [APPROVE]

  • 25-29: The code creates a new CSV parser with the fetched data. If there's an error during this process, it's logged and returned. This is a good practice for error handling.
    [APPROVE]

  • 31-35: The code parses the airport data using the CSV parser. If there's an error during parsing, it's logged and returned. This is a good practice for error handling.
    [APPROVE]

  • 36-36: The number of fetched airports is logged. This could be useful for debugging and monitoring.
    [APPROVE]

@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (01da1f9) 92.07% compared to head (878ca02) 92.92%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
+ Coverage   92.07%   92.92%   +0.85%     
==========================================
  Files           2        2              
  Lines         101       99       -2     
==========================================
- Hits           93       92       -1     
+ Misses          6        5       -1     
  Partials        2        2              
Files Coverage Δ
pkg/airport/parsers/csv/csv.go 92.15% <100.00%> (+1.59%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Commits Files that changed from the base of the PR and between ea8f496 and b542bf2.
Files selected for processing (2)
  • functions/src/init/main.go (2 hunks)
  • pkg/airport/parsers/csv/csv.go (1 hunks)
Additional comments (Suppressed): 1
functions/src/init/main.go (1)
  • 4-6: The new import statements for "bytes" and the custom CSV parser package are appropriate for the changes made in this PR. Ensure that the "github.com/tarmac-project/example-airport-lookup-go/pkg/airport/parsers/csv" package is available and accessible.

pkg/airport/parsers/csv/csv.go Show resolved Hide resolved
functions/src/init/main.go Outdated Show resolved Hide resolved
functions/src/init/main.go Outdated Show resolved Hide resolved
functions/src/init/main.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between b542bf2 and 878ca02.
Files selected for processing (1)
  • functions/src/init/main.go (2 hunks)
Additional comments (Suppressed): 3
functions/src/init/main.go (3)
  • 4-6: The new import statements for the bytes package and the custom CSV parser package are appropriate for the changes made in this PR. The bytes package is used to create a new reader for the fetched data, and the CSV parser package is used to parse the airport data.

  • 18-22: The error message in the log has been updated to include the error returned from the fetch function call. This is a good practice as it provides more context in the logs when an error occurs.

  • 25-35: The new code creates a CSV parser with the fetched data, parses the airport data, and logs the number of fetched airports. It also includes error handling for the creation and parsing process. This is a significant improvement over the previous code, which did not parse the data or log the number of fetched airports.

However, there is a potential issue with the error handling. If an error occurs during the creation of the CSV parser or during the parsing process, the function returns immediately. This means that if there is an error with one record, the entire parsing process will be aborted. This could be problematic if the data contains many records and only a few of them have errors. It might be better to handle these errors in a way that allows the function to continue processing the remaining records.

	airports, err := parser.Parse()
	if err != nil {
-		f.tarmac.Logger.Error(fmt.Sprintf("Failed to parse airport data - %s", err))
-		return []byte(""), fmt.Errorf("Failed to parse airport data: %s", err)
+		f.tarmac.Logger.Warn(fmt.Sprintf("Failed to parse some airport data - %s", err))
	}

@madflojo madflojo merged commit e4b3efd into tarmac-project:main Oct 23, 2023
4 checks passed
@madflojo madflojo deleted the parsecsv branch October 23, 2023 01:04
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.

1 participant