Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.util;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.datatorrent.api.Context.DAGContext;
import com.datatorrent.api.Context.OperatorContext;
import com.datatorrent.api.DefaultInputPort;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.annotation.InputPortFieldAnnotation;
import com.datatorrent.api.annotation.OutputPortFieldAnnotation;
import com.datatorrent.common.util.BaseOperator;
/**
* This is the base implementation of an operator.
* The operator consumes tuples which are maps from fields to objects.
* One field in each tuple is considered a "time" field,
* one or more fields are considered "dimensions",
* one or more fields are considered "value" fields.
* This operator outputs a map at the end of each window whose keys are a combination of the "time" and "dimension" fields.
* The value of the map is another map whose keys are "value" fields and whose values are a numeric metric.
* Subclasses must implement the methods used to process the time, dimension, and value fields.
*
* This operator takes in a Map of key value pairs, and output the expanded key value pairs from the dimensions.
* The user of this class is supposed to:
* - provide the time key name in the map by calling setTimeKeyName
* - provide the time bucket unit by calling setTimeBucketFlags
* - (optional) provide the value field keys by calling addValueKeyName.
* - provide the dimension keys by calling addDimensionKeyName
* - (optional) provide the combinations of the dimensions by calling addCombination (if not, it will expand to all possible combinations of the dimension keys
*
* Example:
* input is a map that represents a line in apache access log.
* "time" => the time
* "url" => the url
* "status" => the status code
* "ip" => the ip
* "bytes" => the number of bytes
*
* We set the time bucket to be just MINUTE, time key is "time", value field is "bytes", the dimension keys are "url", "status", and "ip"
*
* The output will be expanded into number_time_buckets * dimension_combinations * number_of_value_fields values. The key will be the combinations of the values in the dimension keys
*
* Note that in most cases, the dimensions are keys with DISCRETE values
* The value fields are keys with AGGREGATE-able values
*
* @displayName Abstract Dimension Time Bucket
* @category Algorithmic
* @tags count, key value, numeric
* @since 0.3.2
*/
public abstract class AbstractDimensionTimeBucketOperator extends BaseOperator
{
private static final Logger LOG = LoggerFactory.getLogger(AbstractDimensionTimeBucketOperator.class);
/**
* This is the input port which receives tuples that are maps from strings to objects.
*/
@InputPortFieldAnnotation(optional = false)
public final transient DefaultInputPort