Debian Codegraph @

gavo/resources/inputs/__system__/dc_tables.rd

raw
1 <resource resdir="__system" schema="dc">
2 <meta name="creationDate">2008-07-24T09:00:00</meta>
3 <meta name="subject">astronomical-software</meta>
4 <meta name="description">Table-related metadata for
5 the tables within this data center.</meta>
6
7 <table id="tablemeta" onDisk="True" system="True"
8 dupePolicy="overwrite">
9 <meta name="description">A table mapping table names and schemas to
10 the resource descriptors they come from and whether they are open
11 to ADQL queries.
12
13 This is used wherever DaCHS needs to go from a database name to the
14 resource description, e.g., when generating tableinfo.
15
16 The table is maintained through gavo imp; to force things out
17 of here, there's gavo drop (for RDs; use -f if the RD is gone or
18 moved away) or gavo purge (for single tables).
19 </meta>
20
21 <primary>tableName</primary>
22
23 <column name="tableName" description="Fully qualified table name"
24 type="text" verbLevel="1"/>
25 <column name="sourceRD" type="text"
26 description="Id of the resource descriptor containing the
27 table's definition"
28 tablehead="RD" verbLevel="15"/>
29 <column name="tableDesc" type="text"
30 description="Description of the table content"
31 tablehead="Table desc." verbLevel="1"/>
32 <column name="resDesc" type="text"
33 description="Description of the resource this table is part of"
34 tablehead="Res desc." verbLevel="15"/>
35 <column name="adql" type="boolean" required="True"
36 description="True if this table may be accessed using ADQL"
37 verbLevel="30"/>
38 <column name="nrows" type="bigint"
39 description="Estimated number of rows in the table.">
40 <values nullLiteral="-1"/>
41 </column>
42 </table>
43
44 <table id="simple_col_stats" onDisk="True" system="True">
45 <meta name="description">Simple (one-column) statistics of
46 orderable columns
47
48 This is usually filled by dachs limits, which might use estimates rather
49 than actual statistics for large tables. Also, values elements on the
50 column definitions themselves override what may be given here.
51 </meta>
52 <primary>tableName, column_name</primary>
53 <index columns="tableName"/>
54 <foreignKey inTable="tablemeta" source="tableName"/>
55
56 <column original="tablemeta.tableName"/>
57
58 <column name="column_name" type="text"
59 description="Name of the column in question, DaCHS internal
60 representation."/>
61
62 <column name="min_value" type="text"
63 description="Minimal value found in this column, tabledata
64 representation."/>
65 <column name="max_value" type="text"
66 description="Maximal value found in this column, tabledata
67 representation."/>
68
69 <column name="percentile03" type="text"
70 description="Value at the 3rd percentile of this column
71 (representative of the lower bound of a '2-sigma interval').
72 Tabledata representation."/>
73 <column name="median" type="text"
74 description="Median value in this column, tabledata representation."/>
75 <column name="percentile97" type="text"
76 description="Value at the 97th percentile of this column
77 (representative of the upper bound of a '2-sigma interval').
78 Tabledata representation."/>
79
80 <column name="fill_factor"
81 description="Ratio of non-null values in this column to the
82 total number of rows in the table."/>
83 </table>
84
85 <STREAM id="fill-stats-table">
86 <doc>A stream to fill a make element to importers for statistics tables.
87
88 These do all the necessary mangling and extraction in their
89 embedded grammars, so it's fairly stereotypical. The main trick
90 is a newSource script that purges previous annotations.
91 </doc>
92 <script type="newSource" lang="python" notify="False">
93 table.connection.execute(
94 f"DELETE FROM {table.tableDef.getQName()}"
95 " WHERE tableName=%(annotatedTable)s",
96 {"annotatedTable": sourceToken.getQName()})
97 </script>
98 <rowmaker idmaps="*"/>
99 </STREAM>
100
101 <data id="import_simple_col_stats" auto="False" updating="True">
102 <!-- this data item is used by updateTableLevelMetadata and
103 pulls numeric column annotations from the table descriptor
104 passed in as sourceToken.
105 -->
106 <embeddedGrammar>
107 <iterator><code>
108 for col in self.sourceToken:
109 if col.type in base.NUMERIC_TYPES or col.type=="timestamp":
110 if hasattr(col, "annotations"):
111 row = col.annotations.copy()
112 if not row:
113 continue
114 row["tableName"] = self.sourceToken.getQName()
115 row["column_name"] = col.name
116 yield row
117 </code></iterator>
118 </embeddedGrammar>
119
120 <make table="simple_col_stats">
121 <FEED source="fill-stats-table"/>
122 </make>
123 </data>
124
125 <table id="discrete_string_values" onDisk="True" system="True">
126 <meta name="description">Discrete values found in string-valued
127 columns.
128
129 This is usually filled by dachs limits. Only columns with
130 a statistics property of "enumerate" are considered here.
131 Values found here are
132 </meta>
133 <primary>tableName, column_name</primary>
134 <index columns="tableName"/>
135 <foreignKey inTable="tablemeta" source="tableName"/>
136
137 <column original="tablemeta.tableName"/>
138
139 <column name="column_name" type="text"
140 description="Name of the column in question, DaCHS internal
141 representation."/>
142 <column name="vals" type="text[]"
143 description="Values found in the column."/>
144 <column name="freqs" type="real[]"
145 description="Relative frequencies of the strings given in values."/>
146 </table>
147
148 <data id="import_discrete_string_values" auto="False" updating="True">
149 <!-- this data item is used by updateTableLevelMetadata to update
150 statistics for enumerated string columns. The input is a td,
151 rows are pulled out of columns annostated with discrete_values.
152 -->
153 <embeddedGrammar>
154 <iterator><code>
155 for col in self.sourceToken:
156 if (hasattr(col, "annotations")
157 and "discrete_values" in col.annotations):
158 items = sorted(col.annotations["discrete_values"].items())
159 yield {
160 "vals": [i[0] for i in items],
161 "freqs": [i[1] for i in items],
162 "tableName": self.sourceToken.getQName(),
163 "column_name": col.name,
164 }
165 </code></iterator>
166 </embeddedGrammar>
167 <make table="discrete_string_values">
168 <FEED source="fill-stats-table"/>
169 </make>
170 </data>
171
172 <table id="metastore" onDisk="True" system="True" primary="key"
173 dupePolicy="overwrite">
174 <meta name="description">A table for storing all kinds of key-value
175 pairs. Key starting with an underscore are for use by user RDs.
176
177 Only one pair per key is supported, newer keys overwrite older ones.
178
179 Currently, this is only used for schemaversion, the version of
180 the DaCHS system tables as used by gavo upgrade to figure out
181 what to change. gavo upgrade manages this.
182
183 From your code, you can use base.getDBMeta(key) and
184 base.setDBMeta(connection, key, value) to put persistent, string-valued
185 metadata in here; if you use this, would you tell us your
186 use case?
187 </meta>
188
189 <column name="quoted/key" type="text" description="A key; everything that
190 starts with an underscore is user defined."/>
191 <column name="quoted/value" type="text" description="A value; no serialization
192 format is defined here, but you are encouraged to use python literals
193 for non-strings."/>
194 </table>
195
196 <rowmaker id="fromColumnList">
197 <!-- turns a rawrec with column, colInd, tableName keys into a
198 columnmeta row -->
199 <apply name="makerow">
200 <code>
201 column = vars["column"]
202 for key in ["description", "unit", "ucd", "tablehead",
203 "utype", "verbLevel", "type"]:
204 result[key] = getattr(column, key)
205 result["displayHint"] = column.getDisplayHintAsString()
206 result["fieldName"] = column.name
207 result["sourceRD"] = column.parent.rd.sourceId
208 </code>
209 </apply>
210 <map dest="colInd"/>
211 <map dest="tableName"/>
212 </rowmaker>
213
214 <data id="import">
215 <make table="tablemeta"/>
216 <make table="simple_col_stats"/>
217 <make table="discrete_string_values"/>
218 <make table="metastore">
219 <script lang="python" type="postCreation" notify="False">
220 from gavo.user import upgrade
221 from gavo import base
222 base.setDBMeta(table.connection,
223 "schemaversion", upgrade.CURRENT_SCHEMAVERSION)
224 </script>
225 </make>
226 </data>
227
228 <service id="show" allowed="tableinfo">
229 <meta name="shortName">Table infos</meta>
230 <meta name="description">This service formats metadata for tables
231 within the \getConfig{web}{sitename}</meta>
232 <meta name="title">\getConfig{web}{sitename} Table Infos</meta>
233 <nullCore/>
234 </service>
235
236 <service id="list">
237 <meta name="shortName">ADQL tables</meta>
238 <meta name="description">An overview over the tables available for ADQL
239 querying within the \getConfig{web}{sitename}</meta>
240 <meta name="title">\getConfig{web}{sitename} Public Tables</meta>
241
242 <fixedQueryCore
243 query="SELECT tableName, tableName as tableinfo, tableDesc, resDesc
244 FROM dc.tablemeta WHERE adql ORDER BY tableName">
245 <outputTable namePath="tablemeta">
246 <outputField original="tableName"/>
247 <outputField name="tableinfo" original="tableName">
248 <formatter>
249 return T.a(href=base.makeSitePath("/__system__/dc_tables/"
250 "show/tableinfo/"+urllib.parse.quote(data)))["Table Info"]
251 </formatter>
252 </outputField>
253 <outputField original="tableDesc"/>
254 <outputField original="resDesc"/>
255 </outputTable>
256 </fixedQueryCore>
257 </service>
258 </resource>
259