Skip to content

Commit 32f5940

Browse files
committed
Added samples for InsertDocumentAsJson and
Up(date/sert)Document(s)AsJson custom output functions.
1 parent 16c92df commit 32f5940

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

samples/HelloWorldInsertSample/sample/HelloWorldInsertSample.spl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ composite HelloWorldInsertSample {
2020
greeting2 = "Hello again";
2121
}
2222

23-
stream<rstring error1, rstring error2, rstring error3, rstring error4, rstring error5, rstring error6> MongoSink = Insert(B1Stream; B2Stream){
23+
stream<rstring error1, rstring error2, rstring error3, rstring error4, rstring error5, rstring error6, rstring error7, rstring error8> MongoSink =
24+
Insert(B1Stream; B2Stream) {
2425
param
2526
dbHost : "localhost";
2627

@@ -83,7 +84,25 @@ composite HelloWorldInsertSample {
8384
* Store a constant map (map/tuple doesn't require key, but can use it to add a root key), the resulting document is:
8485
* { "_id" : ObjectId("53c795f7e66ebea0c454c813"), "greeting5_1" : "Hello", "greeting5_2" : "world" }
8586
*/
86-
error5 = InsertDocument("streams", "sample", {"greeting5_1" : "Hello", "greeting5_2" : "world"});
87+
error5 = InsertDocument("streams", "sample", {"greeting5_1" : "Hello", "greeting5_2" : "world"}),
88+
89+
/**
90+
* Store a constant rstring JSON, the resulting document is:
91+
* { "_id" : ObjectId("53c795f7e66ebea0c454c814"), "greeting6_1" : "Hello", "greeting6_2" : "world" }
92+
*/
93+
error6 = InsertDocumentAsJson("streams", "sample", '{"greeting6_1" : "Hello", "greeting6_2" : "world"}'),
94+
95+
/**
96+
* Store a constant rstring JSON (doesn't require key, but can use it to add a root key), the resulting document is:
97+
* { "_id" : ObjectId("53c795f7e66ebea0c454c815"), "greeting7_1" : { "greeting7_2" : [ "Hello", "world" ] } }
98+
*/
99+
error7 = InsertDocumentAsJson("streams", "sample", "greeting7_1", '{"greeting7_2" : ["Hello", "world"]}'),
100+
101+
/**
102+
* Store a constant rstring JSON with wrong syntax, the exception is:
103+
* FailedToParse: First character in field must be [A-Za-z$_]: offset:1 of:{[ : "Hello world"}
104+
*/
105+
error8 = InsertDocumentAsJson("streams", "sample", '{[ : "Hello world"}');
87106
}
88107

89108
/**

samples/HelloWorldUpdateSample/sample/HelloWorldUpdateSample.spl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ composite HelloWorldUpdateSample {
1717
stream<rstring greeting2> B2Stream = Beacon() {
1818
param iterations: 1;
1919
output B2Stream :
20-
greeting2 = "Hello again";
20+
greeting2 = '{"Hello" : "again"}';
2121
}
2222

2323
stream<rstring error1> MongoSink = Update(B1Stream; B2Stream) {
@@ -60,8 +60,12 @@ composite HelloWorldUpdateSample {
6060
*/
6161
error1 = UpdateDocument("streams", "sample", B1Stream); // Updates one document where 'greeting1' exists
6262
// error1 = UpdateDocuments("streams", "sample", B1Stream); // Updates all documents where 'greeting1' exists
63-
// error1 = UpsertDocument("streams", "sample", "$set", B2Stream); // Upserts one document where 'greeting1' exists
64-
// error1 = UpsertDocuments("streams", "sample", "$set", B2Stream); // Upserts all document where 'greeting1' exists
63+
// error1 = UpsertDocument("streams", "sample", "$set", B1Stream); // Upserts one document where 'greeting1' exists
64+
// error1 = UpsertDocuments("streams", "sample", "$set", B1Stream); // Upserts all document where 'greeting1' exists
65+
// error1 = UpdateDocumentAsJson("streams", "sample", greeting2); // Updates one document with JSON where 'greeting1' exists
66+
// error1 = UpdateDocumentsAsJson("streams", "sample", greeting2); // Updates all documents with JSON where 'greeting1' exists
67+
// error1 = UpsertDocumentAsJson("streams", "sample", "$set", greeting2); // Upserts one document with JSON where 'greeting1' exists
68+
// error1 = UpsertDocumentsAsJson("streams", "sample", "$set", greeting2); // Upserts all documents with JSON where 'greeting1' exists
6569
}
6670

6771
/**

0 commit comments

Comments
 (0)