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

TDL-19835: Adding new streams and discovery mode #38

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

jtilala
Copy link

@jtilala jtilala commented Jul 20, 2022

Description of change

  • Added discovery mode.
  • Added New streams with class-based implementation.

Manual QA steps

  • Run discovery mode, sync mode with state and without state

Risks

Rollback steps

  • revert this branch

@@ -0,0 +1,67 @@
from asyncio.log import logger

Choose a reason for hiding this comment

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

Remove unused import statement.

Copy link
Author

Choose a reason for hiding this comment

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

Removed unused imports

def get_abs_path(path):
return os.path.join(os.path.dirname(os.path.realpath(__file__)), path)

def get_schemas():

Choose a reason for hiding this comment

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

Add function doc string.

Copy link
Author

Choose a reason for hiding this comment

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

Added doc strings for all the fuctions.


return schemas, field_metadata

def discover():

Choose a reason for hiding this comment

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

Add function doc string for all the functions.

Copy link
Author

Choose a reason for hiding this comment

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

Added doc strings for all the fuctions.


return schemas, field_metadata

def discover():

Choose a reason for hiding this comment

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

Divide this file into two files schema.py and discover.py because you are doing full refactoring.
Reference: https://github.com/singer-io/tap-github/pull/168/files

Copy link
Author

@jtilala jtilala Jul 22, 2022

Choose a reason for hiding this comment

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

Seperated discover.py's code into schema.py and discover.py

}
}
},
"android_pay_cards": {

Choose a reason for hiding this comment

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

Looks like all the *_cards related fields have the same kind of schema. Can you check it once, if those are the same then use schema reference for it?

Copy link
Author

@jtilala jtilala Aug 2, 2022

Choose a reason for hiding this comment

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

Added reference schema in require schemas

"items": {
"type": [
"null",
"objects"

Choose a reason for hiding this comment

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

I think this should be object and not objects.

Copy link
Author

@jtilala jtilala Aug 2, 2022

Choose a reason for hiding this comment

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

Corrected field type value

"settlement_date": {
"type": [
"null",
"strings"

Choose a reason for hiding this comment

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

I think this should be string and not strings.

Copy link
Author

@jtilala jtilala Aug 2, 2022

Choose a reason for hiding this comment

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

Corrected field type value

@@ -0,0 +1,366 @@
from readline import replace_history_item

Choose a reason for hiding this comment

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

Remove unused import statement.

Copy link
Author

Choose a reason for hiding this comment

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

Removed unused imports

"array"
],
"items": {
"$ref": "subscription.json#/"

Choose a reason for hiding this comment

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

Do we have separate stream for subscriptions? If not then we can move subscription.json into the shared folder.

Copy link
Author

@jtilala jtilala Aug 2, 2022

Choose a reason for hiding this comment

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

Updated customer schema

}
}
},
"transaction": {

Choose a reason for hiding this comment

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

I can see multiple occurrences of it, can we create a reference for it?

Copy link
Author

@jtilala jtilala Aug 2, 2022

Choose a reason for hiding this comment

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

Added schema reference in require's schema

"object"
],
"properties": {
"address_details": {

Choose a reason for hiding this comment

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

address_details used multiple times, we can create a reference of it.

Copy link
Author

Choose a reason for hiding this comment

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

removed this stream, so no need to create reference schema for this

DEFAULT_TIMESTAMP = "1970-01-01T00:00:00Z"
LOGGER = singer.get_logger()

SDK_CALL = {

Choose a reason for hiding this comment

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

Instead of creating dict, pass this in the stream object.

Copy link
Author

Choose a reason for hiding this comment

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

Updated streams.py as per your suggestions

replication_keys = "updated_at"
key_properties = ["id"]

def sync_endpoint(self, gateway, config, schema, state, selected_streams, sync_streams):
Copy link

@savan-chovatiya savan-chovatiya Jul 21, 2022

Choose a reason for hiding this comment

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

Looks like all the classes have only 3 kinds of sync_endpoint() function. Create 3 parent classes with specific sync_endpoint() as per functionality and extend those from all the classes. Also, move common attribute variables to those parent classes.
Also move sync_without_window, sync_with_window and sync_full_table method to specific classes with common name sync.

Copy link
Author

Choose a reason for hiding this comment

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

Updated streams.py and created 3 parent classes for sync.

setup.py Outdated
@@ -10,7 +10,7 @@
classifiers=['Programming Language :: Python :: 3 :: Only'],
py_modules=['tap_braintree'],
install_requires=[
'singer-python==5.5.0',
'singer-python==5.12.2',
'requests==2.20.0',
'braintree==3.53.0',

Choose a reason for hiding this comment

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

Can we use the latest version of braintree i.e. 4.16.0

Copy link
Author

Choose a reason for hiding this comment

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

updated version of the Braintree


def discover():
"""
Generate catalog for call the streams

Choose a reason for hiding this comment

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

Suggested change
Generate catalog for call the streams
Run the discovery mode, prepare the catalog file, and return the catalog.

Copy link
Author

Choose a reason for hiding this comment

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

Updated doc strings

Copy link

@umangagrawal-crest umangagrawal-crest left a comment

Choose a reason for hiding this comment

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

Please update setup.py and include changes same as https://github.com/singer-io/tap-quickbooks/blob/master/setup.py#L31-L36
Also, please check the grammar for all the doc string.


# increment through each day (20k results max from api)
for start, end in daterange(period_start, period_end):
LOGGER.info("Starting discovery")

Choose a reason for hiding this comment

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

Suggested change
LOGGER.info("Starting discovery")
LOGGER.info("Starting discover mode")

Copy link
Author

Choose a reason for hiding this comment

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

Updated logger messages

LOGGER.info("Starting discovery")
catalog = discover()
json.dump(catalog.to_dict(), sys.stdout, indent=2)
LOGGER.info("Finished discover")

Choose a reason for hiding this comment

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

Suggested change
LOGGER.info("Finished discover")
LOGGER.info("Finished discover mode")

Copy link
Author

Choose a reason for hiding this comment

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

Updated logger messages as per your suggestions

"array"
],
"items": {
"$ref": "add_on.json#/"

Choose a reason for hiding this comment

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

Suggested change
"$ref": "add_on.json#/"
"$ref": "add_ons.json#/"

Copy link
Author

Choose a reason for hiding this comment

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

Updated all schema with the correct name of the schema

"array"
],
"items": {
"$ref": "discount.json#/"

Choose a reason for hiding this comment

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

Suggested change
"$ref": "discount.json#/"
"$ref": "discounts.json#/"

Copy link
Author

Choose a reason for hiding this comment

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

Updated all schema with the correct name of the schema

Copy link

@umangagrawal-crest umangagrawal-crest left a comment

Choose a reason for hiding this comment

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

References used in the streams schema are not resolved

"array"
],
"items": {
"$ref": "add_on.json#/"

Choose a reason for hiding this comment

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

Suggested change
"$ref": "add_on.json#/"
"$ref": "add_ons.json#/"

Copy link
Author

Choose a reason for hiding this comment

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

Updated all schema with the correct name of the schema

@@ -0,0 +1,32 @@
{

Choose a reason for hiding this comment

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

Please update package_data in setup.py and include a shared schema path in MANIFEST.in

Copy link
Author

Choose a reason for hiding this comment

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

Added shared path in setup.py

Comment on lines 37 to 40
if test_value[0]:
call_count = mocked_discover.call_count
else:
call_count = mocked_sync.call_count

Choose a reason for hiding this comment

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

Don't use if-else in a test case to decide call_count. Create separate test cases in such scenarios. Use @parameterized.expand for common scenarios only.

Copy link
Author

@jtilala jtilala Aug 2, 2022

Choose a reason for hiding this comment

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

Seperated unit tests for sync mode and discover mode

Comment on lines 141 to 144
"paypal_details": {
"anyOf": [
{
"type": "object",

Choose a reason for hiding this comment

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

Any reason to remove many fields from the existing schema.

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.

4 participants