I am trying to port old synapse code that used the query command. Here is the error that I am getting:
Traceback (most recent call last):
File "/share/damons/MICCAI/Challenge_2015/synDownload.py", line 202, in
result = SYN.query('SELECT id, name FROM entity WHERE parentId=="'+ARGS.projects+'"')
File "/usr/local/lib/python2.7/dist-packages/synapseclient/client.py", line 1501, in query
return self.restGET('/query?query=' + quote(queryStr))
File "/usr/local/lib/python2.7/dist-packages/synapseclient/client.py", line 3543, in restGET
exceptions._raise_for_status(response, verbose=self.debug)
File "/usr/local/lib/python2.7/dist-packages/synapseclient/exceptions.py", line 140, in _raise_for_status
raise SynapseHTTPError(message, response=response)
synapseclient.exceptions.SynapseHTTPError: 410 Client Error:
The service you are attempting to access is deprecated.
I tried replacing query with tableQuery and I get:
ValueError: Couldn't extract synapse ID from query: "SELECT * FROM entity WHERE parentId=="####""
where ### is the synapse id that I am trying to get.
Could you please help?
Created by BAL syn.getChildren returns all of the files and folders in a parentId. See https://python-docs.synapse.org/build/html/Client.html?highlight=getchildren#synapseclient.Synapse.getChildren That sounds great. How do I replace query with getchildren? @BAL it looks like your query is trying to get everything in a folder or project. For that you can also use the syn.getChildren function. This means you can avoid having to create a fileview first. I've double checked the code and it seems like the Views documentation for the Synapse Python client that you linked above has typos. Parameter `addDefaultViewColumns` was documented as `add_default_columns`.
I updated my comment above to the correct parameter, and will open an issue in the Python client docs to fix this. Please notes that in the previous answer above, I addressed the "columns" related question.
You can also customize what will show up in the view by adjusting the `includeEntityTypes` list. Please let us know if any part of the documentation about this parameter or `EntityViewType` is not clear to you. Hi @BAL ,
> Also, do I call the create view once per session or are the views stored permanently?
The view is stored permanently until you delete it. After you created a view in the Python client, you can also view it on the website.
What are the queries you are planing to run on this view? Or what questions would you like to be answered by this view? We can help you determine the columns from how you would like to use the view. In general, if you created a view with all default columns and all annotation columns as below, you have all of the fields you can get from the system:
```
view = EntityViewSchema(name="my first file view",
parent=project['id'],
scopes=project['id'],
includeEntityTypes=[EntityViewType.FILE, EntityViewType.FOLDER],
addDefaultViewColumns=True,
addAnnotationColumns=True)
view = syn.store(view)
```
The `columns` parameter provides a way to add user defined columns. If I want to create a view with exactly the same columns and rows as the old query interface, what should I use in with the following documentation?
Also, do I call the create view once per session or are the views stored permanently?
Thanks,
Bennett
From: https://python-docs.synapse.org/build/html/Views.html
To create a view, defines its name, columns, parent, scope, and the type of the view:
view = EntityViewSchema(name="my first file view",
columns=[
Column(name="contributor", columnType="STRING"),
Column(name="class", columnType="STRING"),
Column(name="rank", columnType="STRING")),
parent=project['id'],
scopes=project['id'],
includeEntityTypes=[EntityViewType.FILE, EntityViewType.FOLDER],
add_default_columns=True)
view = syn.store(view)
We support the following entity type in a View:
EntityViewType.FILE
EntityViewType.PROJECT
EntityViewType.TABLE
EntityViewType.FOLDER
EntityViewType.VIEW
EntityViewType.DOCKER
To see the content of your newly created View, use syn.tableQuery():
query_results = syn.tableQuery("select * from %s" % view['id'])
data = query_results.asDataFrame()
Hello @BAL ,
To perform a table query, you first needs to create a table/ file view. In this case, I think you need a FileView.
You can follow this docs to create a FileView: https://docs.synapse.org/articles/views.html (The video has outdated UI looks but the content should stay the same.)
After you created a FileView, look for its ID staring with "syn". You will use this ID in your table query. The query should look like this:
```SELECT * FROM syn123```
You can also play around with composing these queries on the web client.
> I am trying to port old synapse code that used the query command.
Please let us know what you are trying to do and maybe we can help more here. Thanks. I changed tableQuery to query and the same text string is no longer working. The first error is with query. The second error is when it's changed to tablequry. I believe it is syn.tableQuery(query) now.