com.datatorrent.lib.algo.TopNUnique Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.datatorrent.lib.algo;
import java.util.ArrayList;
import java.util.HashMap;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.annotation.OperatorAnnotation;
import com.datatorrent.lib.util.AbstractBaseNUniqueOperatorMap;
/**
* This operator orders tuples per key and emits the top N unique values per key at the end of the window.
*
* Orders tuples per key and emits top N unique tuples per key on end of window.
*
*
* This is an end of window module
* At the end of window all data is flushed. Thus the data set is windowed and no history is kept of previous windows
*
* Ports:
* data: Input data port expects HashMap<K,V>
* top: Output data port, emits HashMap<K, ArrayList<V>>
*
* Properties:
* N: The number of top values to be emitted per key
*
* Specific compile time checks are:
* N: Has to be >= 1
*
* Specific run time checks are: None
*
*
*
* @displayName Top N Unique Values Per Key
* @category Stats and Aggregations
* @tags filter, rank
*
* @since 0.3.2
*/
@OperatorAnnotation(partitionable = false)
public class TopNUnique extends AbstractBaseNUniqueOperatorMap
{
/**
* The output port which emits the top N unique values per key.
*/
public final transient DefaultOutputPort>>> top = new DefaultOutputPort>>>();
/**
* returns true
* @return true
*/
@Override
public boolean isAscending()
{
return true;
}
/**
* Emits tuple on port "top"
* @param tuple
*/
@Override
public void emit(HashMap>> tuple)
{
top.emit(tuple);
}
/**
* Top N unique tuples per key
* @param val
*/
@Override
public void setN(int val)
{
super.setN(val);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy