11 Replies Latest reply on Nov 24, 2017 4:21 AM by dsawyer RSS
    dsawyer Explorer

    delete values from stream

    Hello Experts

     

    I need to delete a range of data from a Stream.

    How do I go about doing this? It is only for one things values though.

     

    Help..

      • Re: delete values from stream
        carlesc Heavyweight Champ

        Hi Darryl, Stream or ValueStream?

          • Re: delete values from stream
            dsawyer Explorer

            Hi

             

            Stream.

              • Re: delete values from stream
                carlesc Heavyweight Champ

                If you have to delete all the entries for a given period, you are lucky, you just need to use PurgeStreamEntries service. If you need to delete entries with a query condition, then you aren't that lucky, you have to query first and then execute one by one the service DeleteStreamEntry. For the second option, if you have to delete a lot of entries you will start having problems, well at least with Neo4J, we have a special code in order to delete entries in batch, now we are on PostgreSQL and we didn't had time to test if this problem that we had on Neo4J still persist on PostgreSQL...

                 

                For sure we need better services in order to delete Stream Entries out of the box.

                  • Re: delete values from stream
                    dsawyer Explorer

                    Thanks Carles

                     

                    Ya I am using Postgres. How do I put the multiple stream entry ID's into the form? Should I be separating them by comma?

                      • Re: delete values from stream
                        carlesc Heavyweight Champ

                        Which form the mashup? the composer one?

                         

                        Better you go with a custom service which accepts as imput stream entries, and loops on all the given entries and calls the DeleteStreamEntry, something like:

                         

                        var stream = Things["StreamName"];

                        for each(entry in entries.rows) {

                          stream.DeleteStreamEntry({ streamEntryId: entry.id });

                        }

                          • Re: delete values from stream
                            dsawyer Explorer

                            Tx Carles

                             

                            That makes sense, but how would i tell it just just do a specific range? by id or by date?

                              • Re: delete values from stream
                                carlesc Heavyweight Champ

                                I don't understand your question

                                  • Re: delete values from stream
                                    dsawyer Explorer

                                    i want to be able to specify the source, startDate and endDate as inputs for the service and then run the loop using those inputs.

                                      • Re: delete values from stream
                                        carlesc Heavyweight Champ

                                        Just use QueryStreamEntries service and give the result of this QueryStreamEntries to the custom DeleteStreamEntries that I've pointed out.

                                          • Re: delete values from stream
                                            dsawyer Explorer

                                            Thanks, am sure I am almost there:

                                             

                                            ReferenceError: "entries" is not defined. (deleteEntriesStream#16)


                                            var params = {
                                            oldestFirst: undefined /* BOOLEAN */,
                                            maxItems: undefined /* NUMBER */,
                                            sourceTags: undefined /* TAGS */,
                                            endDate: endDate /* DATETIME */,
                                            query: undefined /* QUERY */,
                                            source: source /* STRING */,
                                            startDate: startDate /* DATETIME */,
                                            tags: undefined /* TAGS */
                                            };
                                            
                                            
                                            // result: INFOTABLE
                                            var stream = Things["ApexReadingsStream"].QueryStreamEntriesWithData(params);
                                            
                                            
                                            //var stream = Things["StreamName"];
                                            for each(entry in entries.rows) {
                                              stream.DeleteStreamEntry({ streamEntryId: entry.id });
                                            }
                                            
                                            
                                            //var stream = Things["StreamName"];
                                            for each(entry in entries.rows) {
                                              stream.DeleteStreamEntry({ streamEntryId: entry.id });
                                            }
                                            
                                            
                                              • Re: delete values from stream
                                                dsawyer Explorer

                                                Excellent. Here is the working code:

                                                 

                                                var params = {

                                                oldestFirst: undefined /* BOOLEAN */,

                                                maxItems: undefined /* NUMBER */,

                                                sourceTags: undefined /* TAGS */,

                                                endDate: endDate /* DATETIME */,

                                                query: undefined /* QUERY */,

                                                source: source /* STRING */,

                                                startDate: startDate /* DATETIME */,

                                                tags: undefined /* TAGS */

                                                };

                                                 

                                                 

                                                // result: INFOTABLE

                                                var result = Things["ApexReadingsStream"].QueryStreamEntriesWithData(params);

                                                 

                                                 

                                                var stream = Things["ApexReadingsStream"];

                                                for each(entry in result.rows) {

                                                  stream.DeleteStreamEntry({ streamEntryId: entry.id });

                                                }