I have 2 tables (Tab1 , Tab2) with no common field, I would like to run a query on Tab2 for each row in Tab1 and Where condition in subquery should use column value from outer query.
Pseudo code
tab1
| project timestamp, duration
tab2
| project event_time_t, data
pseudo code/ desired query
tab1 join tab2
| where event_time_t between (tab1.timestamp .. datetime_add('millisecond',toint(tab1.duration),tab1.timestamp))
I have checked below options but couldn't got it working
- MV-Apply : couldn't got it working with tabular expression
- User defined function : have limitation with changing row context data
- repeat : works only with scalar
UPDATE:
Adding more clarity to my question.
I want to find all rows from T2 which lies between T1.timestamp and add_datetime(T1.timestamp + duration_millisecond)
I did tried the cross join approach and got desired result but its to costly as my T2 table is huge. Can i do this programmatically some how as we do in T-SQL corelated subquery where a subquery gets executed for each row in T1 and change the between clause dynamically with reference to outer query?
let T1 = datatable(OperationID:sring,timestamp:datetime, duration_millisecond:int)
[
1, datetime(2021-02-15T10:56:28.768), 22 ,
2, datetime(2021-02-15T11:28:28.165), 17 ,
3, datetime(2021-02-15T12:29:48.954), 90 ,
4, datetime(2021-02-15T13:30:09.786), 2 ,
5, datetime(2021-02-15T14:30:22.333), 6 ,
];
let T2 = datatable(event_time_t:datetime, data:string)
[
datetime(2021-02-15T10:56:28.775), "Some string",
datetime(2021-02-15T10:56:28.788), "Another string",
datetime(2021-02-15T11:28:28.167), "Yet another string",
datetime(2021-02-15T12:29:48.954), "Last string1",
datetime(2021-02-15T12:29:48.999), "Last string2",
datetime(2021-02-15T12:29:49.023), "Last string3",
datetime(2021-02-15T12:29:49.025), "Last string4",
datetime(2021-02-15T13:30:09.787), "Last string5",
datetime(2021-02-15T14:30:22.335), "Last string6",
datetime(2021-02-15T14:30:22.337), "Last string7",
];
T1
| extend temp=1
| join kind=fullouter (
T2
| extend temp=1
) on temp
| project-away temp, temp1
| where event_time_t between (timestamp .. datetime_add('millisecond',duration_millisecond,timestamp))
Expected Result:
Result = datatable(OperationID:sring,timestamp:datetime, duration_millisecond:int, event_time_t:datetime, data:string)
[
1, datetime(2021-02-15T10:56:28.768), 22 ,datetime(2021-02-15T10:56:28.775), "Some string",
1, datetime(2021-02-15T10:56:28.768), 22 ,datetime(2021-02-15T10:56:28.788), "Another string",
2, datetime(2021-02-15T11:28:28.165), 17 ,datetime(2021-02-15T11:28:28.167), "Yet another string",
3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:48.954), "Last string1",
3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:48.999), "Last string2",
3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:49.023), "Last string3",
3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:49.025), "Last string4",
4, datetime(2021-02-15T13:30:09.786), 2 ,datetime(2021-02-15T13:30:09.787), "Last string5",
5, datetime(2021-02-15T14:30:22.333), 6 ,datetime(2021-02-15T14:30:22.335), "Last string6",
5, datetime(2021-02-15T14:30:22.333), 6 ,datetime(2021-02-15T14:30:22.337), "Last string7",
]