I have two schemas;
src.xsd
destination.xsd
src.xsd has 2 dates and 1 string
-FromDate (example: 2001-01-01)
-ToDate (example: 2002-01-01)
-Intervaltype (example: 'A long year')
dest.xsd has 1 string property
-Query
I would like to map this so that I achieve a concatenated string in the Query property in the destination schema, like:
"WHERE date1 >= 2001-01-01 AND date2 <= ToDate AND IntervalDescription = 'A long year'"
I've achieved this by using the "string concatenate" functoid.
The problem is that the dates are optional, and i would like to set "default" values in the mapping if none are supplied in src.xsd. In that case i would like
FromDate to be the current date - 10days
and
ToDate to be de current date
How can this be achieved?
Thanks for your help!
The solution was quite simple,
FromDate -> LogicalDate -> ScriptingFunctioid -> StringConcatenate -> Destination
FromDate ---------------->
ToDate -> LogicalDate -> ScriptingFunctioid ->
ToDate ---------------->
Intervaltype -------------------------------------->
Related
Is there a way to create a data table using dynamic dates function like now() or ago()? I am not sure it's possible or just an issue of finding the right syntax.
Works
let Logs = datatable(timestamp: datetime) [
datetime(2022-12-02 2:00:00.00),
datetime(2022-12-02 6:00:00.00),
];
Does not work
let Logs = datatable(timestamp: datetime) [
now(),
datetime(now()- ago(3h)),
];
Thoughts?
datatable accept only literals (no expressions, no functions).
You can use the union operator with multiple print statements:
union
(print 1, now())
,(print 2, ago(3h))
| project-rename id = print_0, timestamp = print_1
id
timestamp
2
2023-02-15T05:29:23.2203689Z
1
2023-02-15T08:29:23.2203689Z
Fiddle
P.S.
datetime(now()- ago(3h)) is wrong.
datetime accept only literal.
now() - ago(3h) is equal to 3h.
Use ago(3h) or now() - 3h
Attempting to cast a string (formatted as YYYY-MM-DD) as ISO date. It's already in the right format but it is erroring out.
SELECT
*
FROM TABLE1
WHERE CHAR(VARCHAR((SUBSTRING(PARAMETER_VALUE,8,4)||
CASE SUBSTRING(PARAMETER_VALUE,4,3)
WHEN 'Jan' THEN '-01-'
WHEN 'Feb' THEN '-02-'
WHEN 'Mar' THEN '-03-'
WHEN 'Apr' THEN '-04-'
WHEN 'May' THEN '-05-'
WHEN 'Jun' THEN '-06-'
WHEN 'Jul' THEN '-07-'
WHEN 'Aug' THEN '-08-'
WHEN 'Sep' THEN '-09-'
WHEN 'Oct' THEN '-10-'
WHEN 'Nov' THEN '-11-'
WHEN 'Dec' THEN '-12-' END||
SUBSTRING(PARAMETER_VALUE,1,2))
),ISO) > CURRENT DATE;
I receive the following error: The statement was not processed because the data type, length or value of the argument for the parameter in position "1" of routine "SYSIBM.CHAR" is incorrect. Parameter name: "".. SQLCODE=-171, SQLSTATE=42815, DRIVER=4.19.56
I am using IBM Data Studio to run this.
PARAMETER_VALUE looks like it's DDMonYYYY if you wanted to use TO_DATE similar to:
SELECT
*
FROM TABLE1
WHERE TO_DATE(PARAMETER_VALUE, 'DDMonYYYY') > CURRENT DATE;
If that's not the correct format of that column then you can put together the correct string from here: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0007107.html
This is my value in the table : FY20 JAN
And i am looking for 'FY20 (M01) JAN'. How can convert like this in Oracle 11g SQL query ?
First you convert your string to a value of DATE type. Anything enclosed in double quotes is somewhat hard coded and TO_DATE function ignores them as long as they match the characters in the input in their specific locations. Here FY are in location (index) 1 and 2.
alter session set nls_date_format = 'yyyy-mm-dd';
select to_date('FY20 JAN', '"FY"yy MON') d from dual;
D
----------
2020-01-01
Then, you apply another function TO_CHAR to the date value we got above to get the desired output.
select to_char(
to_date('FY20 JAN', '"FY"YY MON')
, '"FY"yy "(M"mm")" MON'
) c from dual;
C
-----------------------
FY20 (M01) JAN
I have a
class MedicationPeriod {
LocalDateTime startDate, endDate;
//assume getters and setters
}
Then I have a List<MedicationPeriod> medPrd = getMedPeriods();
Elements in medPrd may have the same startDate.
Now I want to filter the list such that, for elements having the same startDate, the one with the greatest endDate should remain in the list. I.e. having the longest day.
Example: If list elements are:
1) startDate = 2018-Jan-1, endDate = 2018-Feb-25 // 25 days
2) startDate = 2018-Jan-1, endDate = 2018-Feb-20 // 20 days
3) startDate = 2018-Jan-5, endDate = 2018-Feb-25 // startDate is diff, we don't care
So the final list should have only elements 1) and 3). Element 2 will be removed since other MedicationPeriod with the same startDate has a greater endDate.
Here is my attempt (non happily working) to get the result:
mps.stream().collect(Collectors.toMap(MedicationPeriod::getStartDate, e -> e, (a,b) -> a.endDate.isAfter(b.endDate) ? a : b)).values();
My requirement:
I want List<MedicationPeriod> not Collection<MedicationPeriod> as my solution gives Collection<>
I want to achieve this without collecting them and using .values() , because I may do further transformations while in streams and collecting them later.
Let's say I have to perform some test after filtering the MedicationPeriods and then collect it into:
class DateRange {
LocalDate startDate, endDate;
}
How can I do this with only one terminal operation?
There is nothing wrong with your code. It works. Just did a bit of refactoring
new ArrayList<>(medPrd.stream()
.collect(Collectors.toMap(MedicationPeriod::getStartDate, Function.identity(), (a, b) -> a.endDate.isAfter(b.endDate) ? a : b))
.entrySet()
.stream()
.map(entry -> new DateRange(entry.getValue().startDate, entry.getValue().getEndDate())).collect(Collectors.toList()));
Incorporating #Holger 's suggestion it would look like
new ArrayList<>(medPrd.stream()
.collect(Collectors.toMap(MedicationPeriod::getStartDate, Function.identity(), BinaryOperator.maxBy(Comparator.comparing(MedicationPeriod::getEndDate))))
.entrySet()
.stream()
.map(entry -> new DateRange(entry.getValue().startDate, entry.getValue().getEndDate())).collect(Collectors.toList()));
I am working on statistics page of my app and trying to query data by date.
To get the date range, I use Calendar.Date
date_range = Date.days_after_until(start_date, end_date, true)
|> Enum.to_list
And it returns date list of dates and each date looks like "2017-04-07". So with the date I got from date_range, I tried to query but it triggers an error like below.
where cannot be cast to type Ecto.DateTime in query: from o in Myapp.Order,
where: o.created_date >= ^~D[2017-04-07]
For created_date field of Order, I made field like this,
field :created_date, Ecto.DateTime.
If I want to query by date, how can I query it?
Thank in advance.
It looks like you're trying to compare a date and datetime. You need to cast one of them to the other type so the comparison works, e.g. convert the datetime in the database to a date:
date = ~D[2017-01-01]
from p in Post, where: fragment("?::date", p.inserted_at) >= ^date
or convert the Elixir Date to NaiveDateTime:
{:ok, datetime} = NaiveDateTime.new(date, ~T[00:00:00])
from p in Post, where: p.inserted_at >= ^datetime
If you have a start and end date, you just need to add an and to either. You don't need to generate the whole list of dates using any library.
from p in Post,
where: fragment("?::date", p.inserted_at) >= ^start_date and
fragment("?::date", p.inserted_at) <= ^end_date
or
from p in Post,
where: p.inserted_at >= ^start_datetime and
p.inserted_at <= ^end_datetime