Package gavo :: Package svcs :: Module dalipars
[frames] | no frames]

Source Code for Module gavo.svcs.dalipars

 1  """ 
 2  DALI-type input parameters. 
 3   
 4  These, in particular, make intervals out of floats;  uploads are as in "PQL". 
 5   
 6  All this is rife with crazy rules and conventions.  I'd much rather 
 7  we hadn't gone for intervals, but... well, the standards process went the 
 8  other way. 
 9  """ 
10   
11  #c Copyright 2008-2019, the GAVO project 
12  #c 
13  #c This program is free software, covered by the GNU GPL.  See the 
14  #c COPYING file in the source distribution. 
15   
16   
17  INTERVAL_TYPES = set( 
18          ["real", "double precision", "timestamp", "date", "bigint",  
19                  "integer", "smallint"]) 
20   
21   
22 -def adaptInputKey(inputKey):
23 """returns inputKey changed to generate SQL for DALI-standard parameters. 24 25 This is used by buildFrom on CondDescs when renderers have a 26 parameterStyle of dali. 27 28 It will return intervals for INTERVAL_TYPES, make enumerated keys 29 multiple, turn dates and timestamps into MJD intervals. 30 31 InputKeys that already have xtypes are returned unchanged. 32 """ 33 if inputKey.xtype: 34 return inputKey 35 36 if inputKey.type in ["timestamp", "date"]: 37 res = inputKey.change(unit="d", xtype="interval", 38 type="double precision[2]", multiplicity="single") 39 res.setProperty("database-column-is-date", "") 40 return res 41 42 if inputKey.type in INTERVAL_TYPES: 43 if not inputKey.isEnumerated(): 44 return inputKey.change(type=inputKey.type+"[2]", xtype="interval", 45 multiplicity="single") 46 47 return inputKey
48