Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DBRepo
Manage
Activity
Members
Labels
Plan
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FAIR Data Austria DB Repository
DBRepo
Commits
0b2d91e3
Commit
0b2d91e3
authored
3 years ago
by
Moritz Staudinger
Browse files
Options
Downloads
Patches
Plain Diff
fixed where mapping of queries
Former-commit-id:
f6f0b194
parent
660438d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java
+37
-13
37 additions, 13 deletions
.../services/src/main/java/at/tuwien/mapper/QueryMapper.java
with
37 additions
and
13 deletions
fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java
+
37
−
13
View file @
0b2d91e3
...
...
@@ -174,10 +174,23 @@ public interface QueryMapper {
if
(
timestamp
==
null
)
{
throw
new
IllegalArgumentException
(
"Timestamp must be provided"
);
}
return
"SELECT COUNT(*) FROM "
+
query
.
toLowerCase
(
Locale
.
ROOT
).
split
(
"from "
)[
1
]
+
" FOR SYSTEM_TIME AS OF TIMESTAMP '"
+
LocalDateTime
.
ofInstant
(
timestamp
,
ZoneId
.
of
(
"Europe/Vienna"
))
+
"';"
;
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"SELECT COUNT(*) FROM"
);
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
{
...
...
@@ -186,18 +199,29 @@ public interface QueryMapper {
throw
new
ImageNotSupportedException
(
"Currently only MariaDB is supported"
);
}
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
)
{
return
query
+
" FOR SYSTEM_TIME AS OF TIMESTAMP '"
+
LocalDateTime
.
ofInstant
(
timestamp
,
ZoneId
.
of
(
"Europe/Vienna"
))
+
"' LIMIT "
+
size
+
" OFFSET "
+
(
page
*
size
)
+
";"
;
sb
.
append
(
" LIMIT "
+
size
+
" OFFSET "
+
(
page
*
size
));
}
return
query
+
" FOR SYSTEM_TIME AS OF TIMESTAMP '"
+
LocalDateTime
.
ofInstant
(
timestamp
,
ZoneId
.
of
(
"Europe/Vienna"
))
+
"';"
;
sb
.
append
(
";"
);
log
.
debug
(
sb
.
toString
());
return
sb
.
toString
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment