You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importballerina/io;
typeStudentrecord {|readonlyint id;
string name;
int score;
|};
publicfunction main() {
table<Student>students=table [
{id:1, name:"John", score:100},
{id:2, name:"Jane", score:150},
{id:1, name:"John", score:200}
];
// Result of the following will be an error since key `John` is duplicated// and `isSafeReplace()` function returns error for the name `John`map<int>|errorstudentScores=mapfromvar {name, score} instudentsselect [name, score]
onconflictisSafeReplace(name);
io:println(studentScores);
// Result of the following will be an error since key `1` is duplicated// and `isSafeReplace()` function returns error for the name `John`table<Student>key(id)|errorstudentScoresTable=tablekey(id) fromvar student in students
selectstudentonconflictisSafeReplace(student.name);
io:println(studentScoresTable);
table<Student>students2=table [
{id:1, name:"John", score:100},
{id:2, name:"Mike", score:150},
{id:2, name:"Mike", score:200}
];
// Value `100` of the key `Mike` will be replaced by the second occurrence value `200`// since `isSafeReplace()` function returns nill for the name 'Mike`map<int>|errorlastRoundScore=mapfromvar student in students2
select [student.name, student.score]
onconflictisSafeReplace(student.name);
io:println(lastRoundScore);
// Return value will be just the construct type if the `on conflict` clause// always returns `()`map<int>lastRoundScore2=mapfromvar student in students2
select [student.name, student.score]
onconflict ();
io:println(lastRoundScore2);
}
function isSafeReplace(stringname) returnserror? {
ifname=="John" {
returnerror("Key Conflict", message="record with same key exists.");
}
}
Describe your task(s)
No response
Related area
-> Website
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered:
Description
Due to ballerina-platform/ballerina-lang#38991 usage of frame variables inside
on conflict
clause has been removed from theon conflict clause BBE
. Need to update it with the below sample after fixing ballerina-platform/ballerina-lang#38991.Describe your task(s)
No response
Related area
-> Website
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered: