-
Notifications
You must be signed in to change notification settings - Fork 19
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
NERSC vs. NOIRLab DB interoperation #107
Comments
Can you post an example psycopg2 query here? The queryClient understands SQL and ADQL so as long as you can convert to these languages it should be workable. |
I suspect that the SQL queries themselves would be identical; it's more of a question about the wrapper code to perform the query and get the results back. e.g. when working at NERSC: import psycopg2
conn = psycopg2.connect(dbname='desi', user='desi', host='specprod-db.desi.lbl.gov')
specprod = "iron"
cur = conn.cursor()
cur.execute(f"SET search_path TO {specprod}")
q = """
SELECT zpix.targetid,ra,dec,z,flux_g,flux_r,flux_z
FROM zpix
JOIN photometry ON zpix.targetid=photometry.targetid
WHERE survey='main' AND (desi_target & 1) = 1
AND zwarn=0 AND spectype='GALAXY' AND deltachi2>25
"""
cur.execute(q)
rows = cur.fetchall() Is there equivalent code that would run the query Update: I replaced it with a simpler query, but same point remains. |
This is a side-discussion, but this is dangerous because you are potentially excluding the |
But |
Hi @sbailey -- so we only have desi_edr in production and our test version of desi_dr1 only includes zpix and only a subset of columns. I think the ideal approach would be to transfer the iron database to desi_dr1 in our test database. It would not be available to non-Data Lab people but I and/or Ben could benchmark some queries in this way. So I guess this would have to be after NERSC is back online. As far as what the code would look like, here's a version I tried with Some take-away points are that:
|
P.S. I was going to add that I don't think DISTINCT is necessary for just zpix and phot but I think you might have changed the query after I copy-pasted the first example? Anyways, running without DISTINCT still takes ~2sec |
Thanks for the example code snippets. Does datalab have anything equivalent to def query_datalab(query, releasename):
from dl import queryClient
# code to perform query on that release via queryClient, returning a table of results
def query_nersc(query, releasename)
import psycopg2
# code to perform query on that release using psycopg2, returning a table of results
def get_query_function(site, releasename):
if site == 'nersc':
return partial(query_nersc, releasename=releasename)
elif site == 'datalab':
return partial(query_datalab, releasename=releasename)
else:
... Then user code could be something like
and the helper functions would handle the details of "fuji" vs. "desi_edr", If we could come up with something like that, I'd suggest putting it into desiutil or desispec for the tutorials to use. Brainstorming for consideration. |
Do we have a recipe for one someone could write database query code that could be used interchangeably between NERSC and NOIRLab with minimal modification, ideally with a starting if/then block to identify location and then allow everything else to be the same?
It appears that NOIRLab requires access through the datalab dl.queryClient.query interface specific to the NOIRLab DBs, while the DESI NERSC database supports direct access via psycopg2 or the schema-specific specprod-db . But I don't see an obvious way to write database query code that could work at either location, despite both locations having very similar DESI databases. Or maybe NOIRLab does allow direct psycopg2 connections, it just isn't the documented/recommended way if working entirely within the NOIRLab ecosystem?
Detail: They also use different schema names (e.g.
desi_edr
vs.fuji
) but if that was the only difference I think it could be easily handled at the top of a script.@weaverba137 @stephjuneau ?
The text was updated successfully, but these errors were encountered: