use of io.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class IncrementalDataPurger method init.
public void init(AggregationDefinition aggregationDefinition, StreamEventFactory streamEventFactory, Map<TimePeriod.Duration, Table> aggregationTables, Boolean isProcessingOnExternalTime, SiddhiQueryContext siddhiQueryContext, List<TimePeriod.Duration> activeIncrementalDurations, String timeZone, Map<String, Window> windowMap, Map<String, AggregationRuntime> aggregationMap) {
this.siddhiQueryContext = siddhiQueryContext;
this.aggregationDefinition = aggregationDefinition;
List<Annotation> annotations = aggregationDefinition.getAnnotations();
this.streamEventFactory = streamEventFactory;
this.aggregationTables = aggregationTables;
this.activeIncrementalDurations = activeIncrementalDurations;
this.windowMap = windowMap;
this.aggregationMap = aggregationMap;
if (isProcessingOnExternalTime) {
purgingTimestampField = AGG_EXTERNAL_TIMESTAMP_COL;
} else {
purgingTimestampField = AGG_START_TIMESTAMP_COL;
}
aggregatedTimestampAttribute = new Attribute(purgingTimestampField, Attribute.Type.LONG);
VariableExpressionExecutor variableExpressionExecutor = new VariableExpressionExecutor(aggregatedTimestampAttribute, 0, 1);
variableExpressionExecutorList.add(variableExpressionExecutor);
for (Map.Entry<TimePeriod.Duration, Table> entry : aggregationTables.entrySet()) {
this.tableMap.put(entry.getValue().getTableDefinition().getId(), entry.getValue());
switch(entry.getKey()) {
case SECONDS:
retentionPeriods.put(entry.getKey(), Expression.Time.sec(120).value());
minimumDurationMap.put(entry.getKey(), Expression.Time.sec(120).value());
break;
case MINUTES:
retentionPeriods.put(entry.getKey(), Expression.Time.hour(24).value());
minimumDurationMap.put(entry.getKey(), Expression.Time.minute(120).value());
break;
case HOURS:
retentionPeriods.put(entry.getKey(), Expression.Time.day(30).value());
minimumDurationMap.put(entry.getKey(), Expression.Time.hour(25).value());
break;
case DAYS:
retentionPeriods.put(entry.getKey(), Expression.Time.year(1).value());
minimumDurationMap.put(entry.getKey(), Expression.Time.day(32).value());
break;
case MONTHS:
retentionPeriods.put(entry.getKey(), RETAIN_ALL);
minimumDurationMap.put(entry.getKey(), Expression.Time.month(13).value());
break;
case YEARS:
retentionPeriods.put(entry.getKey(), RETAIN_ALL);
minimumDurationMap.put(entry.getKey(), 0L);
}
}
this.timeZone = timeZone;
Map<String, Annotation> annotationTypes = new HashMap<>();
for (Annotation annotation : annotations) {
annotationTypes.put(annotation.getName().toLowerCase(), annotation);
}
Annotation purge = annotationTypes.get(SiddhiConstants.NAMESPACE_PURGE);
if (purge != null) {
if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_ENABLE) != null) {
String purgeEnable = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_ENABLE);
if (!("true".equalsIgnoreCase(purgeEnable) || "false".equalsIgnoreCase(purgeEnable))) {
throw new SiddhiAppCreationException("Invalid value for enable: " + purgeEnable + "." + " Please use true or false");
} else {
purgingEnabled = Boolean.parseBoolean(purgeEnable);
}
}
if (purgingEnabled) {
// If interval is defined, default value of 15 min will be replaced by user input value
if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_INTERVAL) != null) {
String interval = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_INTERVAL);
purgeExecutionInterval = timeToLong(interval);
}
List<Annotation> retentions = purge.getAnnotations(SiddhiConstants.NAMESPACE_RETENTION_PERIOD);
if (retentions != null && !retentions.isEmpty()) {
Annotation retention = retentions.get(0);
List<Element> elements = retention.getElements();
for (Element element : elements) {
TimePeriod.Duration duration = normalizeDuration(element.getKey());
if (!activeIncrementalDurations.contains(duration)) {
throw new SiddhiAppCreationException(duration + " granularity cannot be purged since " + "aggregation has not performed in " + duration + " granularity");
}
if (element.getValue().equalsIgnoreCase(RETAIN_ALL_VALUES)) {
retentionPeriods.put(duration, RETAIN_ALL);
} else {
if (timeToLong(element.getValue()) >= minimumDurationMap.get(duration)) {
retentionPeriods.put(duration, timeToLong(element.getValue()));
} else {
throw new SiddhiAppCreationException(duration + " granularity cannot be purge" + " with a retention of '" + element.getValue() + "', minimum retention" + " should be greater than " + TimeUnit.MILLISECONDS.toMinutes(minimumDurationMap.get(duration)) + " minutes");
}
}
}
}
}
}
compiledConditionsHolder = createCompileConditions(aggregationTables, tableMap);
}
use of io.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class SiddhiAppRuntimeImpl method collectDeprecateWarnings.
private void collectDeprecateWarnings() {
Map<String, Class> deprecatedExtensions = siddhiAppContext.getSiddhiContext().getDeprecatedSiddhiExtensions();
List<AbstractDefinition> extensionsInUse = new ArrayList<>();
extensionsInUse.addAll(streamDefinitionMap.values());
extensionsInUse.addAll(tableDefinitionMap.values());
extensionsInUse.addAll(windowDefinitionMap.values());
extensionsInUse.addAll(aggregationDefinitionMap.values());
for (AbstractDefinition extDefinition : extensionsInUse) {
for (Annotation annotation : extDefinition.getAnnotations()) {
String type = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
if (annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_SOURCE)) {
type = "source:" + type;
}
if (annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_SINK)) {
type = "sink:" + type;
}
if (annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_STORE)) {
type = "store:" + type;
}
if (type != null && deprecatedExtensions.containsKey(type)) {
Class ext = deprecatedExtensions.get(type);
Extension extAnnotation = (Extension) ext.getAnnotation(Extension.class);
String warning = extAnnotation.deprecationNotice().isEmpty() ? type + " is being deprecated." : extAnnotation.deprecationNotice();
warnings.add(warning);
log.warn(warning);
}
}
}
}
use of io.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class AggregationParser method initDefaultTables.
private static HashMap<TimePeriod.Duration, Table> initDefaultTables(String aggregatorName, List<TimePeriod.Duration> aggregationDurations, StreamDefinition streamDefinition, SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder, List<Annotation> annotations, List<Variable> groupByVariableList, boolean isProcessingOnExternalTime, boolean enablePartitioning) {
HashMap<TimePeriod.Duration, Table> aggregationTableMap = new HashMap<>();
// Create annotations for primary key
Annotation primaryKeyAnnotation = new Annotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY);
primaryKeyAnnotation.element(null, AGG_START_TIMESTAMP_COL);
if (enablePartitioning) {
primaryKeyAnnotation.element(null, AGG_SHARD_ID_COL);
}
if (isProcessingOnExternalTime) {
primaryKeyAnnotation.element(null, AGG_EXTERNAL_TIMESTAMP_COL);
}
for (Variable groupByVariable : groupByVariableList) {
primaryKeyAnnotation.element(null, groupByVariable.getAttributeName());
}
if (streamDefinition.getAttributeList().contains(new Attribute(AGG_LAST_TIMESTAMP_COL, Attribute.Type.LONG))) {
Annotation indexAnnotation = new Annotation(SiddhiConstants.ANNOTATION_INDEX);
indexAnnotation.element(null, AGG_LAST_TIMESTAMP_COL);
annotations.add(indexAnnotation);
}
annotations.add(primaryKeyAnnotation);
for (TimePeriod.Duration duration : aggregationDurations) {
String tableId = aggregatorName + "_" + duration.toString();
TableDefinition tableDefinition = TableDefinition.id(tableId);
for (Attribute attribute : streamDefinition.getAttributeList()) {
tableDefinition.attribute(attribute.getName(), attribute.getType());
}
annotations.forEach(tableDefinition::annotation);
siddhiAppRuntimeBuilder.defineTable(tableDefinition);
aggregationTableMap.put(duration, siddhiAppRuntimeBuilder.getTableMap().get(tableId));
}
return aggregationTableMap;
}
use of io.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class TestStoreForCacheMiss method init.
@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
inMemoryTable = new InMemoryTable();
MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
cacheTableMetaStreamEvent.addOutputData(attribute);
}
StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
for (Attribute attribute : tableDefinition.getAttributeList()) {
testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
}
for (Annotation annotation : tableDefinition.getAnnotations()) {
if (!annotation.getName().equalsIgnoreCase("Store")) {
testStoreContainingIMTableDefinition.annotation(annotation);
}
}
inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
use of io.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class TestStoreForCachePreLoading method init.
@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
inMemoryTable = new InMemoryTable();
MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
cacheTableMetaStreamEvent.addOutputData(attribute);
}
StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
for (Attribute attribute : tableDefinition.getAttributeList()) {
testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
}
for (Annotation annotation : tableDefinition.getAnnotations()) {
if (!annotation.getName().equalsIgnoreCase("Store")) {
testStoreContainingIMTableDefinition.annotation(annotation);
}
}
inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
ComplexEventChunk<StreamEvent> originalData = new ComplexEventChunk<>();
StreamEvent data1 = new StreamEvent(0, 0, 3);
data1.setOutputData(new Object[] { "WSO2", 55.6f, 100L });
originalData.add(data1);
StreamEvent data2 = new StreamEvent(0, 0, 3);
data2.setOutputData(new Object[] { "IBM", 75.6f, 100L });
originalData.add(data2);
inMemoryTable.add(originalData);
}
Aggregations