queryClient module

queryClient.drop(token, table='')[source]

Drop the specified table from the user’s MyDB

Parameters:table (str) – The specific table to drop

Example

# List the tables
queryClient.drop('foo1')
queryClient.get_profile(profile)[source]

Get the profile

Returns:profile – The name of the current profile used with the query manager service
Return type:str

Example

# get the profile
queryClient.get_profile()
queryClient.get_svc_url()[source]

Get the query manager service URL.

Parameters:None
Returns:
Return type:Current Query Manager service URL

Example

# get the service url
print (queryClient.get_scv_url())
queryClient.get_timeout_request()[source]

Get the current sync query timeout value.

Parameters:None
Returns:
Return type:Current sync query timeout value.

Example

# get the current timeout value
print (queryClient.get_timeout_request())
queryClient.isAlive(svc_url='https://dlsvcs.datalab.noao.edu/query')[source]

Check whether the QueryManager service at the given URL is alive and responding. This is a simple call to the root service URL or ping() method.

queryClient.list(token, table='')[source]

List the tables in the user’s MyDB

Parameters:table (str) – The specific table to list (returns the schema)
Returns:listing – The list of tables in the user’s MyDB or the schema of a specific table
Return type:str

Example

# List the tables
queryClient.list()
queryClient.list_profiles(token, profile=None, format='text')[source]

Retrieve the profiles supported by the query manager service

Parameters:
  • token (str) – Authentication token (see function dl.auth.login())
  • profile (str) – A specific profile to list
Returns:

profiles – A list of the names of the supported profiles or a dictionary of the specific profile

Return type:

list/dict

Example

# get the list of profiles
profiles = queryClient.list_profiles(token)
queryClient.query(token, adql=None, sql=None, fmt='csv', out=None, async=False, **kw)[source]

Send SQL query to DB.

Parameters:
  • token (str) – Secure token obtained via dl.auth.login()
  • adql (str or None) –

    ADQL query string that will be passed to the DB query manager, e.g.

    adql='select ra,dec from gaia_dr1.gaia_source limit 3'
    

    If adql=None, then a kwarg uri must be provided, which contains a properly formatted URI to an object (e.g. data table) on some remote service, e.g.

    dl.queryClient.query(token, adql=None, uri=XYZ)
    

    Todo

    [20161110] write example once this works

  • sql (str or None) –

    SQL query string that will be passed to the DB query manager, e.g.

    adql='select ra,dec from gaia_dr1.gaia_source limit 3'
    

    This will be run as a query directly against the DB. If sql=None, then a kwarg uri must be provided, which contains a properly formatted URI to an object (e.g. data table) on some remote service, e.g.

    dl.queryClient.query(token, adql=None, uri=XYZ)
    

    Todo

    [20161110] write example once this works

  • fmt (str) –
    Format of the result to be returned by the query. Permitted values are:
    • ‘csv’ the returned result is a comma-separated string that looks like a csv file (newlines at the end of every row)
    • ‘ascii’ same, but the column separator is a tab
    • ‘votable’ result is a string XML-formatted as a VO table
    • ‘fits’ FITS binary
    • ‘hdf5’ HDF5 file

    Todo

    [20161110] fits and hdf5 currently don’t work

  • out (str or None) –

    If None

    Todo

    [20161110] write this...

  • async (bool) – If True, the query is asynchronous, i.e. a job is submitted to the DB, and a job token is returned. The token must be then used to check the query’s status and to retrieve the result (when status is COMPLETE). Default is False, i.e. synchroneous query.
Returns:

result – If async=False, the return value is the result of the query as a formatted string (see fmt). Otherwise the result string is a job token, with which later the asynchroneaous query’s status can be checked (dl.query.status()), and the result retrieved (see dl.query.result().

Return type:

str

Example

Get security token first, see dl.auth.login(). Then:

from dl import queryClient
query = 'select ra,dec from gaia_dr1.gaia_source limit 3'
response = queryClient.query(token, adql = query, fmt = 'csv')
print response

This prints

ra,dec
315.002571989537842,35.2662974820284489
315.00408275885701,35.2665448169895797
314.996334457679438,35.2673478725552698
exception queryClient.queryClientError(message)[source]

Bases: exceptions.Exception

queryClient.results(token, jobId=None)[source]

Retrieve the results of an asynchronous query, once completed.

Parameters:
  • token (str) – Authentication token (see function dl.auth.login())
  • jobId (str) – The jobId returned when issuing an asynchronous query via dl.queryClient.query() with async=True.

Example

# issue a async query (here a tiny one, but nonetheless async, just for this example)
query = 'select ra,dec from gaia_dr1.gaia_source limit 3'
jobId = queryClient.query(token, adql = query, fmt = 'csv', async=True)

# wait a bit... then check status and retrieve results
time.sleep(4)
if queryClient.status(token, jobId) == 'COMPLETED':
    results = queryClient.results(token,jobId)
    print type(results)
    print results

This prints

<type 'str'>
ra,dec
301.37502633933002,44.4946851014515588
301.371102372343785,44.4953207577355698
301.385106974224186,44.4963443903961604
queryClient.schema(value, format, profile)[source]

Return information about a data service schema value.

value : str format : str profile : str

The name of the profile to use. The list of available ones can be retrieved from the service (see function queryClient.list_profiles())

Example

# set the profile
queryClient.schema("usno.a2.raj2000","text","default")
queryClient.set_profile(profile)[source]

Set the profile

Parameters:profile (str) – The name of the profile to use. The list of available ones can be retrieved from the service (see function queryClient.list_profiles())

Example

# set the profile
queryClient.set_profile("default")
queryClient.set_svc_url(svc_url)[source]

Set the query manager service URL.

Parameters:svc_url (str) – The service URL of the query manager to use

Example

# set the service url

url = "http://dldemo.sdm.noao.edu:7002"
queryClient.set_scv_url(url)
queryClient.set_timeout_request(nsec)[source]

Set the requested sync query timeout value (in seconds).

Parameters:nsec (int) – The number of seconds requested before a sync query timeout occurs. The service may cap this as a server defined maximum.

Example

# set the sync query timeout request to 30 seconds
queryClient.set_timeout_request(30)
queryClient.siaquery(token, input=None, out=None, search=0.5)[source]

Send a SIA (Simple Image Access) query to the query manager service

queryClient.status(token, jobId=None)[source]

Get the status of an asynchronous query.

Use the authentication token and the jobId of a previously issued asynchronous query to check the query’s current status.

Parameters:
  • token (str) – Authentication token (see function dl.auth.login())
  • jobId (str) – The jobId returned when issuing an asynchronous query via dl.queryClient.query() with async=True.
Returns:

status – Either ‘QUEUED’ or ‘EXECUTING’ or ‘COMPLETED’. If the token & jobId combination does not correspond to an actual job, then a HTML-formatted error message is returned. If there is a problem with the backend, the returned value can be ‘ERROR’.

When status is ‘COMPLETED’, you can retrieve the results of the query via dl.queryClient.results()

Return type:

str

Example

import time
query = 'select ra,dec from gaia_dr1.gaia_source limit 200000'
jobId = queryClient.query(token, adql = query, fmt = 'csv', async=True)
while True:
    status = queryClient.status(token, jobId)
    print "time index =", time.localtime()[5], "   status =", status
    if status == 'COMPLETED':
        break
    time.sleep(1)

This prints

time index = 16    status = EXECUTING
time index = 17    status = EXECUTING
time index = 18    status = COMPLETED