Skip to content
Snippets Groups Projects
Commit 0b2d91e3 authored by Moritz Staudinger's avatar Moritz Staudinger
Browse files

fixed where mapping of queries

Former-commit-id: f6f0b194
parent 660438d8
No related branches found
No related tags found
No related merge requests found
...@@ -174,10 +174,23 @@ public interface QueryMapper { ...@@ -174,10 +174,23 @@ public interface QueryMapper {
if (timestamp == null) { if (timestamp == null) {
throw new IllegalArgumentException("Timestamp must be provided"); throw new IllegalArgumentException("Timestamp must be provided");
} }
return "SELECT COUNT(*) FROM " + query.toLowerCase(Locale.ROOT).split("from ")[1] + StringBuilder sb = new StringBuilder();
" FOR SYSTEM_TIME AS OF TIMESTAMP '" + sb.append("SELECT COUNT(*) FROM");
LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")) + if(query.contains("where")) {
"';"; sb.append(query.toLowerCase(Locale.ROOT).split("from ")[1].split("where")[0]);
} else {
sb.append(query.toLowerCase(Locale.ROOT).split("from ")[1]);
}
sb.append("FOR SYSTEM_TIME AS OF TIMESTAMP '");
sb.append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")));
sb.append("' ");
if(query.contains("where")) {
sb.append("where ");
sb.append(query.toLowerCase(Locale.ROOT).split("from ")[1].split("where")[1]);
}
sb.append(";");
log.debug(sb.toString());
return sb.toString();
} }
default String queryToRawTimestampedQuery(String query, Database database, Instant timestamp, Long page, Long size) throws ImageNotSupportedException { default String queryToRawTimestampedQuery(String query, Database database, Instant timestamp, Long page, Long size) throws ImageNotSupportedException {
...@@ -186,18 +199,29 @@ public interface QueryMapper { ...@@ -186,18 +199,29 @@ public interface QueryMapper {
throw new ImageNotSupportedException("Currently only MariaDB is supported"); throw new ImageNotSupportedException("Currently only MariaDB is supported");
} }
if (timestamp == null) { if (timestamp == null) {
timestamp = Instant.now(); throw new IllegalArgumentException("Please provide a timestamp before");
}
StringBuilder sb = new StringBuilder();
if(query.contains("where")) {
sb.append(query.toLowerCase(Locale.ROOT).split("where")[0]);
} else {
sb.append(query.toLowerCase(Locale.ROOT));
}
sb.append("FOR SYSTEM_TIME AS OF TIMESTAMP '");
sb.append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")));
sb.append("' ");
if(query.contains("where")) {
sb.append("where");
sb.append(query.toLowerCase(Locale.ROOT).split("from ")[1].split("where")[1]);
} }
if(size != null && page != null && size > 0 && page >=0) { if(size != null && page != null && size > 0 && page >=0) {
return query + sb.append(" LIMIT " + size + " OFFSET " + (page*size));
" FOR SYSTEM_TIME AS OF TIMESTAMP '" +
LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")) +
"' LIMIT " + size + " OFFSET " + (page*size) +
";";
} }
return query + sb.append(";");
" FOR SYSTEM_TIME AS OF TIMESTAMP '" +
LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")) + "';"; log.debug(sb.toString());
return sb.toString();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment