forked from TROA/HdbPoet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlFunctions.xml
More file actions
169 lines (169 loc) · 7.8 KB
/
sqlFunctions.xml
File metadata and controls
169 lines (169 loc) · 7.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<SqlFunctions>
<xs:schema id="SqlFunctions" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="SqlFunctions" msdata:IsDataSet="true" msdata:MainDataTable="function" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="function">
<xs:complexType>
<xs:sequence>
<xs:element name="id" msdata:AutoIncrement="true" type="xs:int" minOccurs="0" />
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="sql" type="xs:string" minOccurs="0" />
<xs:element name="desc" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<function>
<id>0</id>
<name></name>
<sql></sql>
<desc>You may select a pre-configured SQL statement from the list or type your own</desc>
</function>
<function>
<id>1</id>
<name>Lookup SDI by Site and Datatype</name>
<sql>SELECT hdb_site.site_id, hdb_site.site_name, hdb_objecttype.objecttype_name, hdb_site_datatype.site_datatype_id, hdb_datatype.datatype_name, hdb_unit.unit_common_name, hdb_site.db_site_code
FROM hdb_site
INNER JOIN hdb_site_datatype ON hdb_site.site_id=hdb_site_datatype.site_id
INNER JOIN hdb_datatype ON hdb_site_datatype.datatype_id=hdb_datatype.datatype_id
INNER JOIN hdb_unit ON hdb_datatype.unit_id=hdb_unit.unit_id
INNER JOIN hdb_objecttype ON hdb_site.objecttype_id=hdb_objecttype.objecttype_id
WHERE lower(hdb_site.site_name) LIKE
'%$X%'
AND lower(hdb_datatype.datatype_name) LIKE
'%$Y%'</sql>
<desc>Search available datasets via full or partial Site Name and Datatype keywords. Example: To look for Lake Mead elevations, search for $X=mead and $Y=ele.</desc>
</function>
<function>
<id>2</id>
<name>Get SDIs given Site ID</name>
<sql>SELECT hdb_site.site_id, hdb_site.site_name, hdb_datatype.datatype_name, hdb_unit.unit_common_name , hdb_site_datatype.site_datatype_id
FROM hdb_site
INNER JOIN hdb_site_datatype
ON hdb_site.site_id=hdb_site_datatype.site_id
INNER JOIN hdb_datatype
ON hdb_site_datatype.datatype_id=hdb_datatype.datatype_id
INNER JOIN hdb_unit
ON hdb_datatype.unit_id=hdb_unit.unit_id
WHERE hdb_site.site_id =
$X
ORDER BY site_datatype_id</sql>
<desc>Shows the available SDIs and their matching HDB Datatype and Units of measurement given a Site ID. Ex: To GET SDIs for Lake Powell, use $X=919</desc>
</function>
<function>
<id>3</id>
<name>Get period-of-record given SDI</name>
<sql>SELECT * FROM
(
SELECT 'M_MONTH' as source, COUNT(m_month.site_datatype_id) as count, min(m_month.start_date_time) as minDate, max(m_month.start_date_time) as maxDate FROM m_month where site_datatype_id=
$X
UNION
SELECT 'R_DAY' as source, COUNT(r_day.site_datatype_id) as count, min(r_day.start_date_time) as minDate, max(r_day.start_date_time) as maxDate FROM r_day where site_datatype_id=
$X
UNION
SELECT 'R_HOUR' as source, COUNT(r_hour.site_datatype_id) as count, min(r_hour.start_date_time) as minDate, max(r_hour.start_date_time) as maxDate FROM r_hour where site_datatype_id=
$X
UNION
SELECT 'R_MONTH' as source, COUNT(r_month.site_datatype_id) as count, min(r_month.start_date_time) as minDate, max(r_month.start_date_time) as maxDate FROM r_month where site_datatype_id=
$X
)</sql>
<desc>Returns the time period for existing data and counts the number of datapoints within this period in the R Hour, Day, and Month tables along with the M Month table. To count datapoints for Lake Mead elevations, use $X=1930.</desc>
</function>
<function>
<id>4</id>
<name>Get archive history given SDI and Date</name>
<sql>SELECT interval, start_date_time, end_date_time, date_time_archived, value
FROM r_base_archive
WHERE site_datatype_id=
$X
AND start_date_time=
'$Y'
ORDER BY date_time_archived ASC</sql>
<desc>Get data from archive tables to show previous values for an SDI for a given date. Example: To look for the history of values for Lake Mead elevation on Jan-01, 2016, use $X=1930 and $Y=01-JAN-2016</desc>
</function>
<function>
<id>5</id>
<name>Timemachine Query</name>
<sql>WITH arc AS (SELECT t.date_time, arcInner.date_time_archived, arcInner.value, ROW_NUMBER() OVER (PARTITION BY t.date_time ORDER BY t.date_time ASC) rank FROM (SELECT DATE_TIME FROM TABLE(DATES_BETWEEN(
'$T1'
,
'$T2'
,LOWER(
'$Y'
)))) t LEFT OUTER JOIN (SELECT arc.start_date_time, CAST(NVL(arc.date_time_archived,to_date('11-jan-1111')) AS DATE) as date_time_archived, CAST(NVL(arc.value,NULL) AS VARCHAR(10)) as value, ROW_NUMBER() OVER (PARTITION BY start_date_time ORDER BY date_time_archived ASC) rank FROM r_base_archive arc WHERE site_datatype_id=
$X
AND start_date_time BETWEEN
'$T1'
AND
'$T2'
AND interval=lower(
'$Y'
) AND date_time_archived >=
'$Tx'
) arcInner ON t.date_time=arcInner.start_date_time ORDER BY t.date_time, arcInner.date_time_archived) SELECT obs.start_date_time, obs.end_date_time, obs.value as CurrentValue, obs.date_time_loaded as CurrentValue_LoadedOn, CAST(NVL(arc.value, obs.value) AS VARCHAR(10)) as TimeMachineValue, CAST(NVL(arc.date_time_archived,to_date('11-jan-1111')) AS DATE)as TimeMachineValue_ArchivedOn
FROM
r_$Y
obs LEFT OUTER JOIN arc ON obs.start_date_time=arc.date_time WHERE obs.site_datatype_id=
$X
AND arc.rank = 1 ORDER BY obs.start_date_time ASC</sql>
<desc>This function queries data based on what it looked like during a certain date in the past. $X=SDI, $Y=data interval (hour, day, month), $T1 and $T2 for your query dates, and $Tx for the date you want the timemachine to go back to</desc>
</function>
<function>
<id>6</id>
<name>Lookup information given SDI</name>
<sql>SELECT hdb_site_datatype.site_datatype_id, hdb_site.site_name, hdb_objecttype.objecttype_name, hdb_datatype.datatype_name, hdb_unit.unit_common_name, hdb_site.db_site_code
FROM hdb_site
INNER JOIN hdb_site_datatype ON hdb_site.site_id=hdb_site_datatype.site_id
INNER JOIN hdb_datatype ON hdb_site_datatype.datatype_id=hdb_datatype.datatype_id
INNER JOIN hdb_unit ON hdb_datatype.unit_id=hdb_unit.unit_id
INNER JOIN hdb_objecttype ON hdb_site.objecttype_id=hdb_objecttype.objecttype_id
WHERE hdb_site_datatype.site_datatype_id=
$X</sql>
<desc>Search for Site and Datatype information given a Site Datatype ID (SDI). Example: $X=21323</desc>
</function>
<function>
<id>7</id>
<name>Get SDI Summary Statistics per Time-Step</name>
<sql>SELECT
to_char(START_DATE_TIME,
'$X'
) t,
percentile_disc(.0) within group(order by value) min,
percentile_disc(.25) within group(order by value) q1,
percentile_disc(.5) within group(order by value) q2,
percentile_disc(.75) within group(order by value) q3,
percentile_disc(1.0) within group(order by value) max,
round(avg(value)) avg
FROM r_day
WHERE SITE_DATATYPE_ID=
$Y
AND START_DATE_TIME BETWEEN
'$T1'
AND
'$T2'
GROUP BY
to_char(START_DATE_TIME,
'$X'
)
ORDER BY t
</sql>
<desc>Get summary statistics (min, max, avg, IQR) on a per-timestep basis given an SDI. Example: To get summary stats for Lake Mead elevation for CY2000 - CY2010 on a daily time-step, use $X=ddd, $Y=1930, $T1=01-JAN-2000, and $T2=31-DEC-2010. You may also set $Y=mm to get the same stats on a monthly time-step.</desc>
</function>
<function>
<id>8</id>
<name>Update Password</name>
<sql>alter user
$UserName
identified by
"$NewPassword"
replace
"$OldPassword"
</sql>
<desc>This will update a password for an HDB user. Note that you may update the password for the current logged-in user but you would have to log-in as the DB owner to update a different user's password.</desc>
</function>
</SqlFunctions>