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

Implement basic ExchangeRate API using Santa. #2942

Merged
merged 15 commits into from
Apr 21, 2021

Conversation

davinchia
Copy link
Contributor

@davinchia davinchia commented Apr 19, 2021

What

Take Santa for a test drive by implementing the exchange rate api on the latest route using Santa. I didn't see a good way to implement incremental on this, since the cursor is part of the path, and I don't think we have a good way of 1) passing the start_date from the config 2) the state from the last record. Might be missing something so happy to talk through.

Since I was focused on understanding and evaluating the framework, I did not get to write tests. Honestly was also not sure how to think/structure tests for this. I tested this manually on the command line using the main_dev.py file - python main_dev.py read --config sample_files/config.json --catalog sample_files/configured_catalog.json

How

See the files.

Recommended reading order

  1. source.py
  2. spec.json

@davinchia davinchia requested a review from sherifnada April 19, 2021 11:56
@davinchia davinchia marked this pull request as ready for review April 19, 2021 11:56
@auto-assign auto-assign bot requested a review from ChristopheDuong April 19, 2021 11:56
return None

def path(self, **kwargs) -> str:
return "api/latest"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we shouldn't query for latest in this connector but use the date instead. If we do so then the date can be our state.

Copy link
Contributor

Choose a reason for hiding this comment

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

yup, we can also use stream_state to determine what the date should be. I think this is also a better fit for batching. We should create this PR once #2924 is merged (or rebase it and build on top of it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup! was slowly inching my way through python and santa land to this end state.

@sherifnada
Copy link
Contributor

sherifnada commented Apr 19, 2021

@davinchia

  1. passing the start_date from the config

This can be done as a constructor parameter for the stream class

  1. the state from the last record.

this is provided to path as a named argument, stream_state. You can also generate request_configurations, each corresponding to a date, and those will get passed to path one by one. Both arguments (state and request_configuration) are obfuscated by kwargs in this case. Let's talk about how those work today. This is also making me think we need to introduce all the non-obvious pythonic concepts at play here so non-advanced python devs can work with it very easily.

We'll probably want to implement this using the batching concept introduced in #2924

@@ -139,13 +139,16 @@ def _read_incremental(
logger.info(f"Setting state of {stream_name} stream to {stream_state.get(stream_name)}")

checkpoint_interval = stream_instance.state_checkpoint_interval
batches = stream_instance.stream_slices(
slices = stream_instance.stream_slices(
Copy link
Contributor Author

@davinchia davinchia Apr 20, 2021

Choose a reason for hiding this comment

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

the changes in this file seems like missed changes from the earlier refactor

moduleDirectory 'source_exchange_rates'
}

airbyteStandardSourceTestFile {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

yup!

moduleDirectory 'source_exchange_rates'
}

airbyteStandardSourceTestFile {
Copy link
Contributor

Choose a reason for hiding this comment

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

yup!


def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
response_json = response.json()
yield from [response_json]
Copy link
Contributor

Choose a reason for hiding this comment

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

can also do yield response.json()

Copy link
Contributor

Choose a reason for hiding this comment

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

have you verified that a json is returned also on the weekends when there are no exchange rates?

Copy link
Contributor Author

@davinchia davinchia Apr 21, 2021

Choose a reason for hiding this comment

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

good catch on yield

it returns Fridays, which is alright but strange. edited to exclude weekends. nice catch.

self._base = base
self._start_date = start_date

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to override this method, returns None by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

oh nvm my mistake! I think I made it abstract to "force" the user to take a stance on pagination. LGTM then

@davinchia
Copy link
Contributor Author

/publish connector=bases/base-python

@davinchia
Copy link
Contributor Author

davinchia commented Apr 21, 2021

/publish connector=bases/base-python

🕑 bases/base-python https://github.com/airbytehq/airbyte/actions/runs/769946860
❌ bases/base-python https://github.com/airbytehq/airbyte/actions/runs/769946860

@davinchia
Copy link
Contributor Author

davinchia commented Apr 21, 2021

/publish connector=bases/base-python

🕑 bases/base-python https://github.com/airbytehq/airbyte/actions/runs/769971429
✅ bases/base-python https://github.com/airbytehq/airbyte/actions/runs/769971429

@davinchia davinchia merged commit 3d2d20b into master Apr 21, 2021
@davinchia davinchia deleted the davinchia/exchang-rate-santa branch April 21, 2021 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants