Search in sources :

Example 1 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class CustomTimeBucketRegistry method initialize.

private int initialize(Int2ObjectMap<CustomTimeBucket> idToTimeBucket) {
    Preconditions.checkNotNull(idToTimeBucket);
    int tempId = Integer.MIN_VALUE;
    for (int timeBucketId : idToTimeBucket.keySet()) {
        tempId = Math.max(tempId, timeBucketId);
        CustomTimeBucket customTimeBucket = idToTimeBucket.get(timeBucketId);
        textToTimeBucket.put(customTimeBucket.getText(), customTimeBucket);
        Preconditions.checkNotNull(customTimeBucket);
        timeBucketToId.put(customTimeBucket, timeBucketId);
    }
    return tempId;
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket)

Example 2 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class DimensionsDescriptor method setTimeBucket.

/**
 * This is a helper method which sets and validates the {@link TimeBucket}.
 *
 * @param timeBucket
 *          The {@link TimeBucket} to set and validate.
 */
private void setTimeBucket(TimeBucket timeBucket) {
    Preconditions.checkNotNull(timeBucket);
    this.timeBucket = timeBucket;
    this.customTimeBucket = new CustomTimeBucket(timeBucket);
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket)

Example 3 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class DimensionsDescriptor method compareTo.

@Override
public int compareTo(DimensionsDescriptor other) {
    if (this == other) {
        return 0;
    }
    List<String> thisFieldList = this.getFields().getFieldsList();
    List<String> otherFieldList = other.getFields().getFieldsList();
    if (thisFieldList != otherFieldList) {
        int compare = thisFieldList.size() - otherFieldList.size();
        if (compare != 0) {
            return compare;
        }
        Collections.sort(thisFieldList);
        Collections.sort(otherFieldList);
        for (int index = 0; index < thisFieldList.size(); index++) {
            String thisField = thisFieldList.get(index);
            String otherField = otherFieldList.get(index);
            int fieldCompare = thisField.compareTo(otherField);
            if (fieldCompare != 0) {
                return fieldCompare;
            }
        }
    }
    CustomTimeBucket thisBucket = this.getCustomTimeBucket();
    CustomTimeBucket otherBucket = other.getCustomTimeBucket();
    if (thisBucket == null && otherBucket == null) {
        return 0;
    } else if (thisBucket != null && otherBucket == null) {
        return 1;
    } else if (thisBucket == null && otherBucket != null) {
        return -1;
    } else {
        return thisBucket.compareTo(otherBucket);
    }
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket)

Example 4 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class AbstractIncrementalAggregator method createEventKey.

/**
 * Creates an {@link EventKey} from the given {@link InputEvent}.
 *
 * @param inputEvent      The {@link InputEvent} to extract an {@link EventKey} from.
 * @param context         The conversion context required to extract the {@link EventKey} from
 *                        the given {@link InputEvent}.
 * @param aggregatorIndex The aggregatorIndex to assign to this {@link InputEvent}.
 * @return The {@link EventKey} extracted from the given {@link InputEvent}.
 */
public static EventKey createEventKey(InputEvent inputEvent, DimensionsConversionContext context, int aggregatorIndex) {
    GPOMutable keys = new GPOMutable(context.keyDescriptor);
    GPOUtils.indirectCopy(keys, inputEvent.getKeys(), context.indexSubsetKeys);
    if (context.outputTimebucketIndex >= 0) {
        CustomTimeBucket timeBucket = context.dd.getCustomTimeBucket();
        keys.getFieldsInteger()[context.outputTimebucketIndex] = context.customTimeBucketRegistry.getTimeBucketId(timeBucket);
        keys.getFieldsLong()[context.outputTimestampIndex] = timeBucket.roundDown(inputEvent.getKeys().getFieldsLong()[context.inputTimestampIndex]);
    }
    EventKey eventKey = new EventKey(context.schemaID, context.dimensionsDescriptorID, context.aggregatorID, keys);
    return eventKey;
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket) GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) EventKey(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey)

Example 5 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class DimensionsDescriptorTest method equalsAndHashCodeTest.

@Test
public void equalsAndHashCodeTest() {
    DimensionsDescriptor ddA = new DimensionsDescriptor(new CustomTimeBucket(TimeBucket.MINUTE, 5L), new Fields(Sets.newHashSet("a", "b")));
    DimensionsDescriptor ddB = new DimensionsDescriptor(new CustomTimeBucket(TimeBucket.MINUTE, 5L), new Fields(Sets.newHashSet("a", "b")));
    Assert.assertTrue(ddB.equals(ddA));
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket) Fields(org.apache.apex.malhar.lib.appdata.schemas.Fields) Test(org.junit.Test)

Aggregations

CustomTimeBucket (org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket)9 Test (org.junit.Test)5 CustomTimeBucketRegistry (org.apache.apex.malhar.lib.dimensions.CustomTimeBucketRegistry)2 GPOMutable (org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)1 Fields (org.apache.apex.malhar.lib.appdata.schemas.Fields)1 EventKey (org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey)1