-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fixes #634 - Implemented data entry date option for TS data retrieval #927
base: develop
Are you sure you want to change the base?
Changes from 5 commits
95361d7
e04b7e4
6b9a89d
b91145c
20615da
1d0d389
667248d
a4d4394
d6bcf0a
3358bef
8a7c600
9ce5604
b7bfbf3
f73866a
ff688e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
import org.jooq.Record; | ||
import org.jooq.Record1; | ||
import org.jooq.Record3; | ||
import org.jooq.Record4; | ||
import org.jooq.Record7; | ||
import org.jooq.Result; | ||
import org.jooq.SQL; | ||
|
@@ -165,7 +166,7 @@ public String getTimeseries(String format, String names, String office, String u | |
public TimeSeries getTimeseries(String page, int pageSize, String names, String office, | ||
String units, | ||
ZonedDateTime beginTime, ZonedDateTime endTime, | ||
ZonedDateTime versionDate, boolean shouldTrim) { | ||
ZonedDateTime versionDate, boolean shouldTrim, boolean includeEntryDate) { | ||
TimeSeries retVal = null; | ||
String cursor = null; | ||
Timestamp tsCursor = null; | ||
|
@@ -237,7 +238,7 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
|
||
// put all those columns together as "valid" | ||
CommonTableExpression<Record7<BigDecimal, String, String, String, String, BigDecimal, | ||
String>> valid = | ||
String>> valid = | ||
name("valid").fields("tscode", "tsid", "office_id", "loc_part", "units", | ||
"interval", "parm_part") | ||
.as( | ||
|
@@ -249,7 +250,6 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
unit.as("units"), | ||
ival.as("interval"), | ||
param.as("parm_part") | ||
|
||
).from(validTs) | ||
); | ||
|
||
|
@@ -369,6 +369,8 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
); | ||
}); | ||
|
||
Field<Timestamp> dataEntryDate = field("DATA_ENTRY_DATE", Timestamp.class).as("data_entry_date"); | ||
|
||
if (pageSize != 0) { | ||
SelectConditionStep<Record3<Timestamp, Double, BigDecimal>> query = | ||
dsl.select( | ||
|
@@ -391,14 +393,55 @@ public TimeSeries getTimeseries(String page, int pageSize, String names, String | |
query.limit(DSL.val(pageSize + 1)); | ||
} | ||
|
||
logger.fine(() -> query.getSQL(ParamType.INLINED)); | ||
SelectConditionStep<Record3<Timestamp, Double, BigDecimal>> finalQuery = query; | ||
logger.fine(() -> finalQuery.getSQL(ParamType.INLINED)); | ||
|
||
query.forEach(tsRecord -> timeseries.addValue( | ||
tsRecord.getValue(dateTimeCol), | ||
tsRecord.getValue(valueCol), | ||
tsRecord.getValue(qualityNormCol).intValue() | ||
) | ||
); | ||
if (includeEntryDate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This query is doubling the time it takes to retrieve time series. Can this replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While it could replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the schema needs to provide more, we can update the schema call |
||
SelectConditionStep<Record4<Timestamp, Double, BigDecimal, Timestamp>> query2 = dsl.select( | ||
dateTimeCol, | ||
valueCol, | ||
qualityNormCol, | ||
dataEntryDate | ||
) | ||
.from(AV_TSV_DQU.AV_TSV_DQU) | ||
.where(dateTimeCol | ||
.greaterOrEqual(CWMS_UTIL_PACKAGE.call_TO_TIMESTAMP__2( | ||
DSL.nvl(DSL.val(tsCursor == null ? null : | ||
tsCursor.toInstant().toEpochMilli()), | ||
DSL.val(beginTime.toInstant().toEpochMilli()))))) | ||
.and(dateTimeCol | ||
.lessOrEqual(CWMS_UTIL_PACKAGE.call_TO_TIMESTAMP__2( | ||
DSL.val(endTime.toInstant().toEpochMilli()))) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.CWMS_TS_ID.equalIgnoreCase(names)) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.OFFICE_ID.eq(office)) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.UNIT_ID.equalIgnoreCase(unit)) | ||
.and(AV_TSV_DQU.AV_TSV_DQU.VERSION_DATE.eq(versionDate == null ? null : | ||
Timestamp.from(versionDate.toInstant()))) | ||
); | ||
|
||
if (pageSize > 0) { | ||
query2.limit(DSL.val(pageSize + 1)); | ||
} | ||
query2.forEach(tsRecord -> { | ||
assert timeseries != null; | ||
timeseries.addValue( | ||
tsRecord.getValue(dateTimeCol), | ||
tsRecord.getValue(valueCol), | ||
tsRecord.getValue(qualityNormCol).intValue(), | ||
tsRecord.getValue(dataEntryDate) | ||
); | ||
}); | ||
} else { | ||
query.forEach(tsRecord -> { | ||
assert timeseries != null; | ||
timeseries.addValue( | ||
tsRecord.getValue(dateTimeCol), | ||
tsRecord.getValue(valueCol), | ||
tsRecord.getValue(qualityNormCol).intValue(), | ||
null | ||
); | ||
}); | ||
} | ||
|
||
retVal = timeseries; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post/Patch should throw an error if the client is sending a time series with a data-entry-date as that field isn't editable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check for data entry date values