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;
}
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);
}
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);
}
}
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;
}
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));
}
Aggregations