
com.espertech.esper.avro.selectexprrep.SelectExprProcessorEvalAvroMapToAvro Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esper-avro Show documentation
Show all versions of esper-avro Show documentation
Complex event processing and event series analysis component
/*
***************************************************************************************
* Copyright (C) 2006 EsperTech, Inc. All rights reserved. *
* http://www.espertech.com/esper *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
***************************************************************************************
*/
package com.espertech.esper.avro.selectexprrep;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.epl.expression.core.ExprEvaluator;
import com.espertech.esper.epl.expression.core.ExprEvaluatorContext;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import java.util.Map;
public class SelectExprProcessorEvalAvroMapToAvro implements ExprEvaluator {
private final ExprEvaluator eval;
private final Schema inner;
public SelectExprProcessorEvalAvroMapToAvro(ExprEvaluator eval, Schema schema, String columnName) {
this.eval = eval;
this.inner = schema.getField(columnName).schema();
if (!(inner.getType() == Schema.Type.RECORD)) {
throw new IllegalStateException("Column '" + columnName + "' is not a record but schema " + inner);
}
}
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) {
Map map = (Map) eval.evaluate(eventsPerStream, isNewData, context);
if (map == null) {
return null;
}
GenericData.Record record = new GenericData.Record(inner);
for (Map.Entry row : map.entrySet()) {
record.put(row.getKey(), row.getValue());
}
return record;
}
public Class getType() {
return GenericData.Record.class;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy