I have 2 classes AAA and BBB, where BBB contains a field of AAA type.
When I call makePersistent() on 10 AAA and 10 BBB objects, the datastore ends up with 20 AAA objects and 10 BBB objects. I understand this is normal since GAE's datastore is non-relational.
However, when I try to deletePersistentAll using the following,
pm.newQuery(BBB.class).deletePersistentAll();
pm.newQuery(AAA.class).deletePersistentAll();
All BBB objects get removed as expected, but all 20 AAA objects remain. Is there something I'm missing?
Isolation and Consistency
The datastore's isolation level outside of transactions is closest to READ_COMMITTED.
These tests pass.
PersistenceManager pm = pmfInstance.getPersistenceManager();
// make 10 AAA objects
for (int i = 0; i < 10; i++) {
pm.makePersistent(new AAA());
}
// make 10 BBB objects
for (int i = 0; i < 10; i++) {
pm.makePersistent(new BBB(new AAA()));
}
// make sure we have 20 AAA's
#SuppressWarnings("unchecked")
List<AAA> aaa = (List<AAA>) pm.newQuery(AAA.class).execute();
assertEquals(20, aaa.size());
// make sure we have 10 BBB's
List<BBB> bbb = (List<BBB>) pm.newQuery(BBB.class).execute();
assertEquals(10, bbb.size());
// try to delete
pm.newQuery(BBB.class).deletePersistentAll();
bbb = (List<BBB>) pm.newQuery(BBB.class).execute();
assertEquals(0, bbb.size());
pm.newQuery(AAA.class).deletePersistentAll();
aaa = (List<AAA>) pm.newQuery(AAA.class).execute();
assertEquals(0, aaa.size());
assertEquals(0, bbb.size());
Related
I have an Azure hosted application in which some of our users have been complaining of difficulty logging-in. So I added some logs which show up in Application Insights. A sample of the data is shown below:
I need to create a report that shows:
The number of unique users (the Identifier field) that successfully logged-in and the number of unique users that failed to login.
The number of failed login attempts that preceded a successful attempt (if any) - is this even possible in KQL?
One one my attempts was:
customEvents
| order by timestamp asc
| summarize TotalUserCount=dcount(tostring(customDimensions["Identifier"])),
SuccessCount=countif(name startswith "Success"),
FailureCount=countif(name !startswith "Success")
But this is wrong, I need countif(name...) to also be distinct by Identifier.
I'm new to KQL and so would appreciate some help.
Thanks.
I would start from analyzing the data in the session level.
It's very easy to take it from there and summarize it to the user level etc.
// Data sample generation. Not part of the solution
// Setup
let p_event_num = 30;
let p_identifiers_num = 3;
let p_max_distance_between_events = 2h;
let p_names = dynamic(["Unsuccessful login. Invalid cred", "Unsuccessful login. Account wa", "Successful login"]);
// Internal
let p_identifiers = toscalar(range i from 1 to p_identifiers_num step 1 | summarize make_list(new_guid()));
let p_names_num = array_length(p_names);
let customEvents = materialize
(
range i from 1 to p_event_num step 1
| extend ['timestamp [UTC]'] = ago(24h*rand())
| extend Identifier = tostring(p_identifiers[toint(rand(p_identifiers_num))])
| extend name = p_names[toint(rand(p_names_num))]
);
// Solution starts here
customEvents
| project-rename ts = ['timestamp [UTC]']
| partition hint.strategy=native by Identifier
(
order by ts asc
| extend session_id = row_cumsum(iff(ts - prev(ts) >= p_max_distance_between_events, 1, 0))
| summarize session_start = min(ts)
,session_end = max(ts)
,session_duration = 0s
,session_events = count()
,session_successes = countif(name startswith "Successful")
,session_failures = countif(name !startswith "Successful")
,arg_max(ts, name)
by Identifier, session_id
)
| project-away ts
| project-rename session_last_name = name
| extend session_duration = session_end - session_start
| order by Identifier asc, session_id asc
| as user_sessions
Identifier
session_id
session_start
session_end
session_duration
session_events
session_successes
session_failures
session_last_name
3b169e06-52e5-45d8-b951-62d5e8ab385b
0
2022-06-26T20:22:22.4006737Z
2022-06-26T20:22:22.4006737Z
00:00:00
1
0
1
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
1
2022-06-26T22:47:01.8487347Z
2022-06-26T22:47:01.8487347Z
00:00:00
1
1
0
Successful login
3b169e06-52e5-45d8-b951-62d5e8ab385b
2
2022-06-27T04:57:15.6405722Z
2022-06-27T07:32:10.4409854Z
02:34:54.8004132
4
1
3
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
3
2022-06-27T10:44:19.8739205Z
2022-06-27T12:46:14.2586725Z
02:01:54.3847520
3
0
3
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
4
2022-06-27T14:50:35.3882433Z
2022-06-27T14:50:35.3882433Z
00:00:00
1
0
1
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
5
2022-06-27T18:33:51.4464796Z
2022-06-27T18:47:06.0628481Z
00:13:14.6163685
2
0
2
Unsuccessful login. Invalid cred
63ce6481-818e-4f3b-913e-88a1b76ac423
0
2022-06-26T19:27:05.1220534Z
2022-06-26T20:24:53.5616443Z
00:57:48.4395909
2
0
2
Unsuccessful login. Account wa
63ce6481-818e-4f3b-913e-88a1b76ac423
1
2022-06-27T02:17:03.4123257Z
2022-06-27T02:36:50.1918116Z
00:19:46.7794859
3
1
2
Successful login
63ce6481-818e-4f3b-913e-88a1b76ac423
2
2022-06-27T13:27:27.2550722Z
2022-06-27T14:32:39.6361479Z
01:05:12.3810757
3
2
1
Successful login
63ce6481-818e-4f3b-913e-88a1b76ac423
3
2022-06-27T17:20:34.3725797Z
2022-06-27T17:20:34.3725797Z
00:00:00
1
0
1
Unsuccessful login. Account wa
6ed81ab3-447e-481d-8bb3-a5f4087234bb
0
2022-06-26T22:38:39.3105749Z
2022-06-26T22:38:39.3105749Z
00:00:00
1
0
1
Unsuccessful login. Account wa
6ed81ab3-447e-481d-8bb3-a5f4087234bb
1
2022-06-27T03:06:04.340965Z
2022-06-27T04:49:37.3314224Z
01:43:32.9904574
3
3
0
Successful login
6ed81ab3-447e-481d-8bb3-a5f4087234bb
2
2022-06-27T07:11:47.260913Z
2022-06-27T07:11:47.260913Z
00:00:00
1
0
1
Unsuccessful login. Account wa
6ed81ab3-447e-481d-8bb3-a5f4087234bb
3
2022-06-27T11:39:02.356791Z
2022-06-27T16:49:23.5818891Z
05:10:21.2250981
4
2
2
Unsuccessful login. Invalid cred
Fiddle
I need countif(name...) to also be distinct by Identifier.
If I understood your intention correctly, you could use dcountif().
For example:
customEvents
| where timestamp > ago(1d)
| extend Identifier = tostring(customDimensions["Identifier"])
| summarize TotalUserCount = dcount(Identifier),
SuccessCount = dcountif(Identifier, name startswith "Success"),
FailureCount = dcountif(Identifier, name !startswith "Success")
The number of failed login attempts that preceded a successful attempt (if any) - is this even possible in KQL?
You could try using the scan operator for this: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/scan-operator
How might I generate a list of date objects for each Monday of a year?
i want like
7 1 2019
14 1 2019
21 1 2019
...
4 3 2019
11 3 2019
blabla
Is there a function to do this in the DateTime library? i think i missed something,the same question asked for R but I really did not understand anything
As far as I know the function doesn't exist but you can try this code:
void main() {
var givenYear = 1999;
var listOfMondays = [];
var dateIter = DateTime(givenYear);
while (dateIter.year < givenYear + 1) {
dateIter.add(new Duration(days: 1));
if (dateIter.weekday == 1) {
//1 for Monday, 2 for Tuesday, 3 for Wednesday and so on.
listOfMondays.add(dateIter);
}
}
}
It looks like things are going wrong on line 9 for me. Here I wish to push a new copy of the TagsTable into a dictionary. I'm aware that once a namedtuple field is recorded, it can not be changed. However, results baffle me as it looks like the values do change - when this code exits all entries of mp3_tags[ any of the three dictionary keys ].date are set to the last date of "1999_03_21"
So, two questions:
Is there a way to get a new TagsTable pushed into the dictionary ?
Why doesnt the code fail and not allow the second (and even third) date to be written to the TagsTable.date field (since it seems to be references to the same namedtuple) ? I thought you could not write a second value ?
from collections import namedtuple
2 TagsTable = namedtuple('TagsTable',['title','date','subtitle','artist','summary','length','duration','pub_date'])
3 mp3files = ['42-001.mp3','42-002.mp3','42-003.mp3']
4 dates = ['1999_01_07', '1999_02_14', '1999_03_21']
5
6 mp3_tags = {}
7
8 for mp3file in mp3files:
9 mp3_tags[mp3file] = TagsTable
10
11 for mp3file,date_string in zip(mp3files,dates):
12 mp3_tags[mp3file].date = date_string
13
14 for mp3file in mp3files:
15 print( mp3_tags[mp3file].date )
looks like this is the fix I was looking for:
from collections import namedtuple
mp3files = ['42-001.mp3','42-002.mp3','42-003.mp3']
dates = ['1999_01_07', '1999_02_14', '1999_03_21']
mp3_tags = {}
for mp3file in mp3files:
mp3_tags[mp3file] = namedtuple('TagsTable',['title','date','subtitle','artist','summary','length','duration','pub_date'])
for mp3file,date_string in zip(mp3files,dates):
mp3_tags[mp3file].date = date_string
for mp3file in mp3files:
print( mp3_tags[mp3file].date )
i am using a gridview in Asp.net to show data in a table
i want to show data like this -
Sr.No ClassStandard Division Total
---------------------------------------------
A B
---------------------------------------------
1. First 10 20 30
2. Second 15 15 30
if i direclty attach the source then the data comes like this-
ClassStandard A B Total
------------------------------------------
First 10 20 30
Second 15 15 30
Here is the code:
if (!IsPostBack)
{
try
{
IApplicationContext ctx = ContextRegistry.GetContext();
IServices reg = (IServices)ctx.GetObject("Services");
DataSet ds = reg.getInstituteStatusByDistrict();
int Count = ds.Tables[0].Rows.Count;
gridviewdistrictReport.DataSource = ds;
gridviewdistrictReport.DataBind();
}
}
Note:I am using Spring .net for database connectivity
inside Aspx file
<asp:GridView ID="gridviewdistrictReport" runat="server">
how should i display the upper row with division spanning to both columns..
Please help me..
These links should help you add multiple headers to a gridview
Example 1
Example 2
I have a database table which contanis a field name Province bits and it adds up the count of the pattern like:
AB-1
BC-2
CD-4
DE-8
EF-16.... and so on.
Now in the table entry I have a value-13(Province bit), which implies checkboxes against entry AB,CD,DE(adds up to 13)should be checked.
I am not able to get the logic behind the same, how can check only those checkboxes whose sum adds up to the entry in the table?
You need to check to see if the value is in the bitwise total.
if( interestedInValue & totalValue == interestedInValue)
{
// this value is in the total, check the box
}
Documentation on & http://msdn.microsoft.com/en-us/library/sbf85k1c(v=vs.71).aspx
e.g. 13 = 1 + 4 + 8
13 & 1 == 1 // true
13 & 2 == 2 // false
13 & 4 == 4 // true
13 & 8 == 8 // true
13 & 16 == 16 // false
EDIT: for more clarification
ab.Checked = 1 && ProvinceBit == 1 // checkbox AB
bc.Checked = 2 && ProvinceBit == 2 // checkbox BC
...
The field is using bit flags.
13 is 1101 binary.
So convert the value to bits and assign one bit to each checkbox.
By converting your number to a string, you can convert to an array or just iterate through the string. A bit brute force, but will give you what you need.
var value = 13
string binary = Convert.ToString(value, 2);
//binary = "1101"