-
Notifications
You must be signed in to change notification settings - Fork 7
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
add method to upload sources from schema and metadata #82
Conversation
src/pycrunch/importing.py
Outdated
@@ -52,6 +52,25 @@ def wait_for_batch_status(self, batch, status): | |||
else: | |||
raise ValueError("The batch did not reach the '%s' state in the " | |||
"given time. Please check again later." % status) | |||
|
|||
def add_schema_metadata(self, ds, source_url, filename, fp, mimetype, schema, metadata): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the dataset here, it's only being used for the session, this could be obtained from the connection I believe.
The source_url
is not a user input either, you will get this from the main API catalog, under catalogs.sources
.
This signature should be:
def add_schema_metadata(self, ds, source_url, filename, fp, mimetype, schema, metadata): | |
def add_schema_metadata(self, schema, metadata, filename, fp, mimetype): |
I think that for this case, since it's going to be crunch lake, the mimetype is always known because it has to be a parquet file, we don't accept anything else do we?
Note that schema
and metadata
are first, because they are the main thing about the name of this function.
Additionally, add a docstring indicating what are the types of the arguments. Particularly, schema and metadata, are they dictionaries? Or are they file pointers to my local json files?
tests/test_lake.py
Outdated
class TestCrunchLakeWorkflow: | ||
def test_ping(self): | ||
command = ["cr.core.launch", "ping", "crunch-lake-ping", '--kwargs={"pong": "test-ping"}'] | ||
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to check if we have connection to the lake service from pycrunch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's just a temporary test? It doesn't feel like this is the right place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alig1493 something to notice is that this pycrunch is an open source consumer library. It does not communicate with our internals at Crunch.
The tests we implement here should be able to run stand alone alone. We can do the integration tests in other internal repositories.
…ing. move test_lake from pycrunch tests to functests in zoom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need a test for this, read through the pycrunch tests to see how they are built. Note that they are all offline tests with stubs
src/pycrunch/elements.py
Outdated
@@ -283,6 +283,7 @@ class ElementResponseHandler(lemonpy.ResponseHandler): | |||
parsers = {"application/json": parse_json_element_from_response} | |||
|
|||
def status_401(self, r): | |||
print(r.json()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this print
src/pycrunch/importing.py
Outdated
} | ||
) | ||
return shoji.Entity(site.session, body={ | ||
"status_code": response.status_code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't the attributes of a new Source entity.
These body
attributes should match the same as if you were reading a Source from the API. At this point right after the creation you won't have them. The response will probably be a 201 with a Location header.
So, the only attribute you should be able to fill form there is the self
.
See how it's being done here:
https://github.com/Crunch-io/pycrunch/blob/master/src/pycrunch/shoji.py#L180
entity["self"] = URL(seeother[-1].headers["Location"], "")
The Entity
you return is ok to be empty as long as it has a self
url.
Then the consumer will be able to do source.refresh()
to trigger a new GET request and fetch all the attributes if they want.
"schema": schema, | ||
"metadata": metadata, | ||
"crunchlake": "create", | ||
"dataset_id": "None" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no dataset ID to create a new source. Sources are not linked to datasets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument is required for the sources post request endpoint. Otherwise there's errors.
See here: https://github.com/Crunch-io/zoom/blob/master/server/tests/controllers/test_sources.py#L282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it looks like that is incorrect. Sources are not linked to datasets.
This controller should not create sources depending on datasets. The relationship is the other way around. Sources do not point to datasets. Datasets point to sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm simply making a post request with the help of pycrunch to the endpoint that requires a dataset_id
to be added. Otherwise I get the following error:
E pycrunch.lemonpy.ServerError: (<Response [500]>, 'https://test01.crunch.io/api/sources/', {'status': 500, 'exception': ['cr.lib.files.CrunchLakeMissingDatasetID: attr dataset_id: str is required for purposes of CrunchLake\n'], 'traceback': [['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cherrypy/_cprequest.py', 670, 'respond', 'response.body = self.handler()'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cherrypy/lib/encoding.py', 221, '__call__', 'self.body = self.oldhandler(*args, **kwargs)'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/core/monitoring/tracer.py', 903, 'inner', 'return f(*args, **kwargs)'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/server/api/controllers/tools.py', 705, 'tracing_inner', 'return oldhandler(*args, **kwargs)'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/server/shoji.py', 162, 'shojify_inner', 'result = request._pre_shojify_handler(*args, **kwargs)'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cherrypy/_cpdispatch.py', 60, '__call__', 'return self.callable(*self.args, **self.kwargs)'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/server/api/controllers/sources.py', 161, 'POST', '**options,'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/core/monitoring/tracer.py', 903, 'inner', 'return f(*args, **kwargs)'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/lib/entities/sources.py', 1049, 'from_file', 'creation_time=data["creation_time"],'], ['/var/lib/crunch.io/crserver_api_venv_python3.6/lib/python3.6/site-packages/cr/lib/files/__init__.py', 215, '__init__', '"attr dataset_id: str is required for purposes of CrunchLake"']], 'message': "['cr.lib.files.CrunchLakeMissingDatasetID: attr dataset_id: str is required for purposes of CrunchLake\\n']"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this is a bug that has been introduced on the backend. And we should not grow this bug. Sources do not hold references to Datasets. Because multiple datasets are allowed to source rows from the same source entity. In which case, which of those multiple datasets does Source.dataset_id
is pointing to?
@mgdotdev Why does the CrunchLake source require to know about a Dataset ID? For a fresh user, they will first have to upload a parquet file while they do not have any Datasets existing in the system yet. And only later they can create a Dataset by using this source. This relation is backwards.
data={ | ||
"schema": schema, | ||
"metadata": metadata, | ||
"crunchlake": "create", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's crunchlake specific. @mgdotdev can expand on this.
a137d4c
to
f7d0546
Compare
src/pycrunch/importing.py
Outdated
|
||
Parameters: | ||
site (shoji.Catalog): a shoji Catalog object, from which we acquire session and sources url | ||
schema (str): json string containing schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not require the user to provide a JSON string. Make it accept dictionaries. If this needs to convert to JSON we do it internally.
src/pycrunch/importing.py
Outdated
Parameters: | ||
site (shoji.Catalog): a shoji Catalog object, from which we acquire session and sources url | ||
schema (str): json string containing schema | ||
metadata (str): json string containing metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
"schema": schema, | ||
"metadata": metadata, | ||
"crunchlake": "create", | ||
"dataset_id": "None" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it looks like that is incorrect. Sources are not linked to datasets.
This controller should not create sources depending on datasets. The relationship is the other way around. Sources do not point to datasets. Datasets point to sources.
Closed in favour of #83 |
No description provided.