diff --git a/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RDBPreferences.java b/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RDBPreferences.java index abe5caa48d..3b916c1490 100644 --- a/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RDBPreferences.java +++ b/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RDBPreferences.java @@ -19,6 +19,8 @@ public class RDBPreferences @Preference static String user, password, prefix; @Preference static int timeout_secs; @Preference static boolean use_array_blob; + @Preference static String raw_query; + @Preference static boolean use_utc_in_raw_query; @Preference static String stored_procedure; @Preference static String starttime_function; @Preference static int fetch_size; diff --git a/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RawSampleIterator.java b/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RawSampleIterator.java index f5c256cbee..840eb75e6f 100644 --- a/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RawSampleIterator.java +++ b/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/RawSampleIterator.java @@ -13,6 +13,8 @@ import java.sql.ResultSet; import java.sql.Timestamp; import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.logging.Level; import org.epics.vtype.VType; @@ -67,6 +69,9 @@ public RawSampleIterator(final RDBArchiveReader reader, } } + // UTC time zone + private static final ZoneId UTC = ZoneId.of("UTC"); + /** Get the samples: result_set will have the samples, * value will contain the first sample * @param start Start time @@ -132,8 +137,20 @@ private void determineInitialSample(final Instant start, final Instant end) thro reader.addForCancellation(sel_samples); sel_samples.setInt(1, channel_id); - sel_samples.setTimestamp(2, start_stamp); - sel_samples.setTimestamp(3, end_stamp); + + if (RDBPreferences.use_utc_in_raw_query) + { // Send a 'local' time stamp, no time zone info, with UTC-based values + Timestamp start_utc = Timestamp.valueOf(LocalDateTime.ofInstant(start_stamp.toInstant(), UTC)); + Timestamp end_utc = Timestamp.valueOf(LocalDateTime.ofInstant(end_stamp.toInstant(), UTC)); + sel_samples.setTimestamp(2, start_utc); + sel_samples.setTimestamp(3, end_utc); + } + else + { // Send time stamp that's based on EPOCH. + // All but Oracle will properly deal with local/UTC conversions + sel_samples.setTimestamp(2, start_stamp); + sel_samples.setTimestamp(3, end_stamp); + } result_set = sel_samples.executeQuery(); // Get first sample if (result_set.next()) diff --git a/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/SQL.java b/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/SQL.java index bf3f894fc2..6409f3b827 100644 --- a/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/SQL.java +++ b/app/trends/archive-reader/src/main/java/org/phoebus/archive/reader/rdb/SQL.java @@ -87,12 +87,13 @@ class SQL " WHERE channel_id=?" + " AND smpl_time BETWEEN ? AND ?" + " ORDER BY smpl_time"; - sample_sel_by_id_start_end_with_blob = - "SELECT smpl_time, severity_id, status_id, num_val, float_val, str_val, datatype, array_val" + + sample_sel_by_id_start_end_with_blob = RDBPreferences.raw_query.isEmpty() + ? "SELECT smpl_time, severity_id, status_id, num_val, float_val, str_val, datatype, array_val" + " FROM " + prefix + "sample" + " WHERE channel_id=?" + " AND smpl_time>=? AND smpl_time<=?" + - " ORDER BY smpl_time"; + " ORDER BY smpl_time" + : RDBPreferences.raw_query; sample_sel_array_vals = "SELECT float_val FROM " + prefix + "array_val" + " WHERE channel_id=? AND smpl_time=? ORDER BY seq_nbr"; } diff --git a/app/trends/archive-reader/src/main/resources/archive_reader_rdb_preferences.properties b/app/trends/archive-reader/src/main/resources/archive_reader_rdb_preferences.properties index 35a6c245ad..3bf8626288 100644 --- a/app/trends/archive-reader/src/main/resources/archive_reader_rdb_preferences.properties +++ b/app/trends/archive-reader/src/main/resources/archive_reader_rdb_preferences.properties @@ -38,6 +38,15 @@ timeout_secs=120 # When running against an old database, this parameter must be set to false. use_array_blob=true +# Optional replacement for the built-in raw data query. +# When empty, default to `SQL.sample_sel_by_id_start_end_with_blob` +raw_query= + +# Use a UTC-based local time stamp for the raw data query? +# Necessary when Oracle doesn't properly convert +# the epoch-based sql.Timestamp to/from local time zone. +use_utc_in_raw_query=false + # Use stored procedures and functions for 'optimized' data readout? # # Set to procedure name, or nothing to disable stored procedure.