Saturday, May 23, 2020

Kotlin vs Java continued

Collections are provided in the Kotlin standard library via extension functions.  For example, groupBy takes a lambda function and returns a Map where each key is the lambda result and the corresponding value is the List of elements which represent the groups 

The groupBy can also be called with a second parameter 'valueTransform' where the keys from the first parameter 'keySelector' is mapped to the result of the transformation rather than the original elements.  

groupBy is different from groupingBy which returns an instance of 'Grouping' type. Here the operations are all applied in a lazy manner. Even the groups are formed just before the operation execution and supports the following operations: 

eachCount() which counts the elements in each group 

fold() and reduce() which operates on each group and returns results 

aggregate() which supports custom operations when fold and reduce are not enough     

Collections can be retrieved with 

 - slice 

 - take and drop 

 - chunked and 

 - windowed. 

slice() returns a list of collection when a set of indices are passed in. The positions of the elements to be retrieved can also be passed in via range descriptors. This is equivalent to subList 

  

Take and drop  are functions that return the elements themselves. 

  

take() and takeLast() work on the two ends of the list. If there are more number of elements specified than the current number, then they return the entire collection. 

  

drop() returns elements not matching the given predicate. 

  

chunked breaks the collection into parts of a given size, all parts are of equal size unless the remaining are smaller than the chunk size. chunks are short living lists that should be consumed right in that lambda. 

  

Windowed retrieves all possible ranges of the collection elements of a given size starting from each collection element. 

 

Lists order elements by position. Two lists cannot be considered similar if their elements are not in the same order. 

Order can be ‘natural’ if the elements in the collection implement the Comparable interface. The Comparable interface has a method called compareTo which has a major version and a minor version. This is the default order when none other is specified. 

Custom orders helps sort instances in any arbitrary way. Even if the objects cannot be compared, it is possible to override the compare method of the Comparator interface in this case. For example, 

companion object: Comparator<ReaderConfiguration> { 

         override fun compare(a: ReaderConfiguration, b: ReaderConfiguration): Int { 

                        if (a.numReaders == b.numReaders && 

                            a.numRetries == b.numRetries && 

                            a.retryMillis == b.retryMillis &&  

                            a.segment == b.segment && 

                            a.position == b.position ) return 0 

                        return -1 

        } 

    } 
Then there is reverse order by running the extension function reversed() on the collection. This creates a new collection. If we want the same collection reversed, the asReversed() method comes helpful. 

 

The random order of elements in a collection can be seen with the shuffled method.  

Aggregate function operations return a single vslue based on the collection content. For example, sum(), count(), average(), min(), and max() are widely used aggregate functions  

 

The Comparator described above can be used with aggregate functions to return the largest or the smallest functions 

The summation functions also take a function as a parameter.  

Friday, May 22, 2020

Kotlin vs Java continued

Lists order elements by position. Two lists cannot be considered similar if their elements are not in the same order.
Order can be ‘natural’ if the elements in the collection implement the Comparable interface. The Comparable interface has a method called compareTo which has a major version and a minor version. This is the default order when none other is specified.
Custom orders helps sort instances in any arbitrary way. Even if the objects cannot be compared, it is possible to override the compare method of the Comparator interface in this case. For example,
companion object: Comparator<ReaderConfiguration> {
         override fun compare(a: ReaderConfiguration, b: ReaderConfiguration): Int {
                        if (a.numReaders == b.numReaders &&
                            a.numRetries == b.numRetries &&
                            a.retryMillis == b.retryMillis && 
                            a.segment == b.segment &&
                            a.position == b.position ) return 0
                        return -1
        }
    }
Then there is reverse order by running the extension function reversed() on the collection. This creates a new collection. If we want the same collection reversed, the asReversed() method comes helpful.

The random order of elements in a collection can be seen with the shuffled method. 
Aggregate function operations return a single vslue based on the collection content. For example, sum(), count(), average(), min(), and max() are widely used aggregate functions 

The Comparator described above can be used with aggregate functions to return the largest or the smallest functions
The summation functions also take a function as a parameter. 

Thursday, May 21, 2020

Kotlin vs java continued

Collections can be retrieved with
 - slice
 - take and drop
 - chunked and
 - windowed.
slice() returns a list of collection when a set of indices are passed in. The positions of the elements to be retrieved can also be passed in via range descriptors. This is equivalent to subList
 
Take and drop  are functions that return the elements themselves.
 
take() and takeLast() work on the two ends of the list. If there are more number of elements specified than the current number, then they return the entire collection.
 
drop() returns elements not matching the given predicate.
 
chunked breaks the collection into parts of a given size, all parts are of equal size unless the remaining are smaller than the chunk size. chunks are short living lists that should be consumed right in that lambda.
 
Windowed retrieves all possible ranges of the collection elements of a given size starting from each collection element.

Lists order elements by position. Two lists cannot be considered similar if their elements are not in the same order.
Order can be ‘natural’ if the elements in the collection implement the Comparable interface. The Comparable interface has a method called compareTo which has a major version and a minor version. This is the default order when none other is specified.
Custom orders helps sort instances in any arbitrary way. Even if the objects cannot be compared, it is possible to override the compare method of the Comparator interface in this case. For example,
companion object: Comparator<ReaderConfiguration> {
         override fun compare(a: ReaderConfiguration, b: ReaderConfiguration): Int {
                        if (a.numReaders == b.numReaders &&
                            a.numRetries == b.numRetries &&
                            a.retryMillis == b.retryMillis && 
                            a.segment == b.segment &&
                            a.position == b.position ) return 0
                        return -1
        }
    }
Then there is reverse order by running the extension function reversed() on the collection. This creates a new collection. If we want the same collection reversed, the asReversed() method comes helpful.

Wednesday, May 20, 2020

Kotlin vs Java continued...

Collections are provided in the Kotlin standard library via extension functions.  

Collections can be retrieved with 

 - slice 

 - take and drop 

 - chunked and 

 - windowed

There are functions available to retrieve single elements from collections such as from lists and sets.

Lists are ordered collections where every element has a position.

Set is not an ordered collection but Kotlin set does leverage some order.

LinkedHashSet uses the order of insertion

SortedSet uses the natural sorting order

or some sets may have unknown order.

An element is retrieved from a collection by position with the help of elementAt with the starting element accessed at position 0 and the ending element accessed at position size-1

There are also useful aliases for retrieving the first and last element of the collection or for safe variations of elementsAt

These aliases support predicates so that the elements are qualified before being retrieved as first or last. They throw exception if no match occurs.

Random access of the elements are also supported with random() function.

The existence of one or more elements in a collection is done with contains() or containsAll()



Tuesday, May 19, 2020

Kotlin vs Java continued

Collections are provided in the Kotlin standard library via extension functions.  For example, groupBy takes a lambda function and returns a Map where each key is the lambda result and the corresponding value is the List of elements which represent the groups 

The groupBy can also be called with a second parameter 'valueTransform' where the keys from the first parameter 'keySelector' is mapped to the result of the transformation rather than the original elements.  

groupBy is different from groupingBy which returns an instance of 'Grouping' type. Here the operations are all applied in a lazy manner. Even the groups are formed just before the operation execution and supports the following operations: 

eachCount() which counts the elements in each group 

fold() and reduce() which operates on each group and returns results 

aggregate() which supports custom operations when fold and reduce are not enough     

Collections can be retrieved with 

 - slice 

 - take and drop 

 - chunked and 

 - windowed

slice() returns a list of collection when a set of indices are passed in. The positions of the elements to be retrieved can also be passed in via range descriptors. This is equivalent to subList

Take and drop  are functions that return the elements themselves.

take() and takeLast() work on the two ends of the list. If there are more number of elements specified than the current number, then they return the entire collection.

drop() returns elements not matching the given predicate.

chunked breaks the collection into parts of a given size, all parts are of equal size unless the remaining are smaller than the chunk size. chunks are short living lists that should be consumed right in that lambda.

Windowed retrieves all possible ranges of the collection elements of a given size starting from each collection element.


 

 

 
 

Monday, May 18, 2020

Kotlin vs java continued

It might be surprising that Kotlin objects are created twice in some cases. This is not really true. Kotlin class have primary and secondary constructors and it is the responsibility of the Kotlin developers to chain them where appropriate. The Language itself matches the constructor by the signature or the tag associated with the constructor during instantiation.
For example,
with the following classes described as 
Class TaskConfiguration @JsonCreator
constructor() {
     var groups = mutableListOf<GroupConfiguration>()
     var counter: CounterConfiguration ? = null
     :
}
Class GroupConfiguration @JsonCreator
constructor() {
     Var numMembers: Int = 0
}
And class
class CounterConfiguration {
    Val numCounters:Int = 0  
     @JsonCreator
     Constructor(@JsonProperty(“numCounters”) numCounters: Int = 100) {
           this.numCounters = numCounters
     }
}
will initialize the ‘groups’ mutableList with two members instead of 1 because the order of progression in the primary constructor is groups first before counter.
On the other hand, if the order is reversed with say:
     var counter: CounterConfiguration ? = null
     var groups = mutableListOf<GroupConfiguration>()
Then, the ‘groups’ is initialized with only one member. 
The CounterConfiguration can be declared differently with a primary constructor to avoid this duplication.
Also the secondary constructor can chain the primary constructor or other constructors with 
Constructor(Parameter parameter1) : this (Parameter parameter2) 
Where the parameters are different.

Sunday, May 17, 2020

Data import and export tool continued

Earlier, we described the data transfer to the stream store with the help of syntax similar to that of connectors for object store. Since the stream store is layered over files and blobs as tier2  storage which bring storage engineering best practice for durability, replication and geographical and web accessible distribution, it is not often recognized as a veritable store requring in participation in workflows outside analytics

The data that flows out of stream store is often pulled from various receivers. That usage continues to be mainstream for the stream store. However, we add additional usages where the appenders push the data to different data sinks. Previously there were in-house scripts for such data transfers. Instead we suggest making it part of the standard storage and provide users just the ability to configure it to their purpose. 
The ability to take the onerous routines of using stream store as a storage layer from the layer above across different data sinks enables a thinner upper layer and more convenience to the end user. The customizations in the upper layer are reduced and the value additions bubble up the stack.  
On-premise stream store is no more a standalone. The public cloud has moved towards embracing on-premise compute resources and their management via System Center integration. The same applies to on-premise stream store as well.  Consequently, the technologies behind the appenders are not only transparent but they are also setup for being monitored and reported via dashboards and charts This improves visibility into the data transfers while enabling cost accounting. 
The importer and exporter have the ability to append or read sections of the stream improving performance and speed.
The importer and exporter also make push and pull model easy by acting as a relay in the middle. The role of the importer and exporter then becomes an adapter between heterogeneous systems. The API for example, is a pull model. But most metrics and time series database are a push model relying on the agents like telegraf to transfer data. 
The importer and the exporter enable a stream store to participate in a data pipeline. This is a critical business value for the stream store because it adds value as co-inhabitant of a data ecosystem as opposed to competing with time-series database. 
The importer and exporter can also be customized for business needs. For example, the size of artifact and the number of artifacts to export are variables. Similarly, the type of event to transform the remote ByteBuffer can be determined before the importer runs.