Skip to content

Commit

Permalink
merge FPC-403-64638 support for generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardttom2 committed Jun 30, 2020
1 parent 579e61f commit 8dd0c24
Show file tree
Hide file tree
Showing 2,707 changed files with 29,555 additions and 18,770 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
*/
package com.espertech.esper.common.internal.avro.core;

import com.espertech.esper.common.client.type.EPTypeClass;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericEnumSymbol;
import org.apache.avro.generic.GenericFixed;

public class AvroConstant {
public final static String PROP_JAVA_STRING_KEY = "avro.java.string";
public final static String PROP_JAVA_STRING_VALUE = "String";

public final static EPTypeClass EPTYPE_SCHEMA = new EPTypeClass(Schema.class);
public final static EPTypeClass EPTYPE_RECORD = new EPTypeClass(GenericData.Record.class);
public final static EPTypeClass EPTYPE_SCHEMAPARSER = new EPTypeClass(Schema.Parser.class);
public static final EPTypeClass EPTYPE_GENERICFIXED = new EPTypeClass(GenericFixed.class);
public static final EPTypeClass EPTYPE_GENERICENUMSYMBOL = new EPTypeClass(GenericEnumSymbol.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.espertech.esper.common.internal.avro.core;

import com.espertech.esper.common.client.EventBean;
import com.espertech.esper.common.client.type.EPTypeClass;
import com.espertech.esper.common.internal.event.core.EventBeanCopyMethod;
import com.espertech.esper.common.internal.event.core.EventBeanTypedEventFactory;
import org.apache.avro.Schema;
Expand All @@ -22,6 +23,7 @@
* Copy method for Map-underlying events.
*/
public class AvroEventBeanCopyMethod implements EventBeanCopyMethod {
public final static EPTypeClass EPTYPE = new EPTypeClass(AvroEventBeanCopyMethod.class);
private final AvroEventType avroEventType;
private final EventBeanTypedEventFactory eventAdapterService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public AvroEventBeanCopyMethodForge(AvroEventType avroEventType) {

public CodegenExpression makeCopyMethodClassScoped(CodegenClassScope classScope) {
CodegenExpressionField factory = classScope.addOrGetFieldSharable(EventBeanTypedEventFactoryCodegenField.INSTANCE);
return newInstance(AvroEventBeanCopyMethod.class,
cast(AvroEventType.class, EventTypeUtility.resolveTypeCodegen(avroEventType, EPStatementInitServices.REF)),
return newInstance(AvroEventBeanCopyMethod.EPTYPE,
cast(AvroEventType.EPTYPE, EventTypeUtility.resolveTypeCodegen(avroEventType, EPStatementInitServices.REF)),
factory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import com.espertech.esper.common.client.*;
import com.espertech.esper.common.client.meta.EventTypeMetadata;
import com.espertech.esper.common.client.type.EPType;
import com.espertech.esper.common.client.type.EPTypeClass;
import com.espertech.esper.common.client.type.EPTypePremade;
import com.espertech.esper.common.internal.avro.getter.AvroEventBeanGetterIndexedRuntimeKeyed;
import com.espertech.esper.common.internal.avro.getter.AvroEventBeanGetterMappedRuntimeKeyed;
import com.espertech.esper.common.internal.avro.getter.AvroEventBeanGetterSimple;
Expand All @@ -31,9 +34,12 @@

import java.util.*;

import static com.espertech.esper.common.internal.event.core.EventTypeUtility.getPropertyTypeAsClass;
import static com.espertech.esper.common.internal.avro.core.AvroFragmentTypeUtil.getFragmentEventTypeForField;

public class AvroEventType implements AvroSchemaEventType, EventTypeSPI {
public final static EPTypeClass EPTYPE = new EPTypeClass(AvroEventType.class);

private EventTypeMetadata metadata;
private final Schema avroSchema;
private final Map<String, PropertySetDescriptorItem> propertyItems;
Expand Down Expand Up @@ -81,10 +87,18 @@ public Class getUnderlyingType() {
return GenericData.Record.class;
}

public Class getPropertyType(String propertyName) {
public EPTypeClass getUnderlyingEPType() {
return AvroConstant.EPTYPE_RECORD;
}

public final Class getPropertyType(String propertyName) {
return getPropertyTypeAsClass(getPropertyEPType(propertyName));
}

public EPType getPropertyEPType(String propertyName) {
PropertySetDescriptorItem item = propertyItems.get(StringValue.unescapeDot(propertyName));
if (item != null) {
return item.getSimplePropertyType();
return item.getPropertyDescriptor().getPropertyEPType();
}

Property property = PropertyParser.parseAndWalkLaxToSimple(propertyName);
Expand Down Expand Up @@ -243,15 +257,15 @@ public EventPropertyDescriptor getWritableProperty(String propertyName) {
return null;
}
MappedProperty mapProp = (MappedProperty) property;
return new EventPropertyDescriptor(mapProp.getPropertyNameAtomic(), Object.class, null, false, true, false, true, false);
return new EventPropertyDescriptor(mapProp.getPropertyNameAtomic(), EPTypePremade.OBJECT.getEPType(), false, true, false, true, false);
}
if (property instanceof IndexedProperty) {
EventPropertyWriter writer = getWriter(propertyName);
if (writer == null) {
return null;
}
IndexedProperty indexedProp = (IndexedProperty) property;
return new EventPropertyDescriptor(indexedProp.getPropertyNameAtomic(), Object.class, null, true, false, true, false, false);
return new EventPropertyDescriptor(indexedProp.getPropertyNameAtomic(), EPTypePremade.OBJECT.getEPType(), true, false, true, false, false);
}
return null;
}
Expand Down Expand Up @@ -321,28 +335,25 @@ private void init() {
for (Schema.Field field : avroSchema.getFields()) {
propertyNames[fieldNum] = field.name();

Class propertyType = AvroTypeUtil.propertyType(field.schema());
Class componentType = null;
EPType propertyType = AvroTypeUtil.propertyType(field.schema());
boolean indexed = false;
boolean mapped = false;
FragmentEventType fragmentEventType = null;

if (field.schema().getType() == Schema.Type.ARRAY) {
componentType = AvroTypeUtil.propertyType(field.schema().getElementType());
indexed = true;
if (field.schema().getElementType().getType() == Schema.Type.RECORD) {
fragmentEventType = getFragmentEventTypeForField(field.schema(), metadata.getModuleName(), eventBeanTypedEventFactory, eventTypeAvroHandler, fragmentTypeCache);
}
} else if (field.schema().getType() == Schema.Type.MAP) {
mapped = true;
componentType = AvroTypeUtil.propertyType(field.schema().getValueType());
} else {
fragmentEventType = getFragmentEventTypeForField(field.schema(), metadata.getModuleName(), eventBeanTypedEventFactory, eventTypeAvroHandler, fragmentTypeCache);
}
AvroEventBeanGetterSimple getter = new AvroEventBeanGetterSimple(field.pos(), fragmentEventType == null ? null : fragmentEventType.getFragmentType(), eventBeanTypedEventFactory, propertyType);

EventPropertyDescriptor descriptor = new EventPropertyDescriptor(field.name(), propertyType, componentType, false, false, indexed, mapped, fragmentEventType != null);
PropertySetDescriptorItem item = new PropertySetDescriptorItem(descriptor, propertyType, getter, fragmentEventType);
EventPropertyDescriptor descriptor = new EventPropertyDescriptor(field.name(), propertyType, false, false, indexed, mapped, fragmentEventType != null);
PropertySetDescriptorItem item = new PropertySetDescriptorItem(descriptor, getter, fragmentEventType);
propertyItems.put(field.name(), item);
propertyDescriptors[fieldNum] = descriptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
package com.espertech.esper.common.internal.avro.core;

import com.espertech.esper.common.client.EventBean;
import com.espertech.esper.common.client.type.EPTypeClass;
import com.espertech.esper.common.internal.event.core.AvroBackedBean;
import org.apache.avro.generic.GenericData;

/**
* For events that are array of properties.
*/
public interface AvroGenericDataBackedEventBean extends EventBean, AvroBackedBean {
EPTypeClass EPTYPE = new EPTypeClass(AvroGenericDataBackedEventBean.class);

GenericData.Record getProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

import com.espertech.esper.common.client.EventType;
import com.espertech.esper.common.client.FragmentEventType;
import com.espertech.esper.common.client.type.EPType;
import com.espertech.esper.common.client.type.EPTypeClass;
import com.espertech.esper.common.client.type.EPTypeNull;
import com.espertech.esper.common.client.type.EPTypePremade;
import com.espertech.esper.common.internal.avro.getter.*;
import com.espertech.esper.common.internal.event.avro.EventTypeAvroHandler;
import com.espertech.esper.common.internal.event.core.EventBeanTypedEventFactory;
Expand All @@ -27,13 +31,13 @@
import static com.espertech.esper.common.internal.avro.core.AvroFragmentTypeUtil.getFragmentEventTypeForField;

public class AvroPropertyUtil {
protected static Class propertyType(Schema fieldSchema, Property property) {
protected static EPType propertyType(Schema fieldSchema, Property property) {
AvroFieldDescriptor desc = AvroFieldUtil.fieldForProperty(fieldSchema, property);
if (desc == null) {
return null;
}
if (desc.isDynamic()) {
return Object.class;
return EPTypePremade.OBJECT.getEPType();
}
Schema typeSchema = desc.getField().schema();
if (desc.isAccessedByIndex()) {
Expand Down Expand Up @@ -151,7 +155,8 @@ private static EventPropertyGetterSPI propertyGetterNested(GetterNestedFactory f
return null;
}
FragmentEventType fragmentEventType = AvroFragmentTypeUtil.getFragmentEventTypeForField(fieldNested.schema(), moduleName, eventAdapterService, eventTypeAvroHandler, fragmentTypeCache);
return factory.makeSimple(fieldNested.pos(), fragmentEventType == null ? null : fragmentEventType.getFragmentType(), AvroTypeUtil.propertyType(fieldNested.schema()));
EPType type = AvroTypeUtil.propertyType(fieldNested.schema());
return factory.makeSimple(fieldNested.pos(), fragmentEventType == null ? null : fragmentEventType.getFragmentType(), type);
}

if (property instanceof IndexedProperty) {
Expand Down Expand Up @@ -192,7 +197,7 @@ private static EventPropertyGetterSPI propertyGetterNested(GetterNestedFactory f
Schema currentSchema = fieldSchema;
int count = 0;
int[] path = new int[nested.getProperties().size()];
Class[] types = new Class[nested.getProperties().size()];
EPTypeClass[] types = new EPTypeClass[nested.getProperties().size()];
for (Property levelProperty : nested.getProperties()) {
if (currentSchema.getType() != Schema.Type.RECORD) {
return null;
Expand All @@ -203,7 +208,11 @@ private static EventPropertyGetterSPI propertyGetterNested(GetterNestedFactory f
}
currentSchema = fieldNested.schema();
path[count] = fieldNested.pos();
types[count] = AvroTypeUtil.propertyType(currentSchema);
EPType type = AvroTypeUtil.propertyType(currentSchema);
if (type == EPTypeNull.INSTANCE) {
return null;
}
types[count] = (EPTypeClass) type;
count++;
}
FragmentEventType fragmentEventType = AvroFragmentTypeUtil.getFragmentEventTypeForField(currentSchema, moduleName, eventAdapterService, eventTypeAvroHandler, fragmentTypeCache);
Expand All @@ -224,7 +233,7 @@ private static EventPropertyGetterSPI propertyGetterNested(GetterNestedFactory f
return null;
}
FragmentEventType fragmentEventType = getFragmentEventTypeForField(fieldNested.schema(), moduleName, eventAdapterService, eventTypeAvroHandler, fragmentTypeCache);
Class propertyType = AvroTypeUtil.propertyType(fieldNested.schema());
EPType propertyType = AvroTypeUtil.propertyType(fieldNested.schema());
getters[count] = new AvroEventBeanGetterSimple(fieldNested.pos(), fragmentEventType == null ? null : fragmentEventType.getFragmentType(), eventAdapterService, propertyType);
currentSchema = fieldNested.schema();
} else if (levelProperty instanceof IndexedProperty) {
Expand Down Expand Up @@ -292,15 +301,15 @@ private static void mayAddToGetterCache(String propertyName, HashMap<String, Eve
}

private interface GetterNestedFactory {
EventPropertyGetterSPI makeSimple(int posNested, EventType fragmentEventType, Class propertyType);
EventPropertyGetterSPI makeSimple(int posNested, EventType fragmentEventType, EPType propertyType);

EventPropertyGetterSPI makeIndexed(int posNested, int index, EventType fragmentEventType);

EventPropertyGetterSPI makeMapped(int posNested, String key);

EventPropertyGetterSPI makeDynamicSimple(String propertyName);

EventPropertyGetterSPI makeNestedSimpleMultiLevel(int[] path, Class[] propertyTypes, EventType fragmentEventType);
EventPropertyGetterSPI makeNestedSimpleMultiLevel(int[] path, EPTypeClass[] propertyTypes, EventType fragmentEventType);

EventPropertyGetterSPI makeNestedPolyMultiLevel(AvroEventPropertyGetter[] getters);
}
Expand All @@ -314,7 +323,7 @@ public GetterNestedFactoryRootedSimple(EventBeanTypedEventFactory eventAdapterSe
this.posTop = posTop;
}

public EventPropertyGetterSPI makeSimple(int posNested, EventType fragmentEventType, Class propertyType) {
public EventPropertyGetterSPI makeSimple(int posNested, EventType fragmentEventType, EPType propertyType) {
return new AvroEventBeanGetterNestedSimple(posTop, posNested, fragmentEventType, eventAdapterService);
}

Expand All @@ -330,7 +339,7 @@ public EventPropertyGetterSPI makeDynamicSimple(String propertyName) {
return new AvroEventBeanGetterNestedDynamicSimple(posTop, propertyName);
}

public EventPropertyGetterSPI makeNestedSimpleMultiLevel(int[] path, Class[] propertyTypes, EventType fragmentEventType) {
public EventPropertyGetterSPI makeNestedSimpleMultiLevel(int[] path, EPTypeClass[] propertyTypes, EventType fragmentEventType) {
return new AvroEventBeanGetterNestedMultiLevel(posTop, path, fragmentEventType, eventAdapterService);
}

Expand All @@ -350,7 +359,7 @@ public GetterNestedFactoryRootedIndexed(EventBeanTypedEventFactory eventAdapterS
this.index = index;
}

public EventPropertyGetterSPI makeSimple(int posNested, EventType fragmentEventType, Class propertyType) {
public EventPropertyGetterSPI makeSimple(int posNested, EventType fragmentEventType, EPType propertyType) {
return new AvroEventBeanGetterNestedIndexRooted(pos, index, new AvroEventBeanGetterSimple(posNested, fragmentEventType, eventAdapterService, propertyType));
}

Expand All @@ -366,7 +375,7 @@ public EventPropertyGetterSPI makeDynamicSimple(String propertyName) {
return new AvroEventBeanGetterNestedIndexRooted(pos, index, new AvroEventBeanGetterSimpleDynamic(propertyName));
}

public EventPropertyGetterSPI makeNestedSimpleMultiLevel(int[] path, Class[] propertyTypes, EventType fragmentEventType) {
public EventPropertyGetterSPI makeNestedSimpleMultiLevel(int[] path, EPTypeClass[] propertyTypes, EventType fragmentEventType) {
AvroEventPropertyGetter[] getters = new AvroEventPropertyGetter[path.length];
for (int i = 0; i < path.length; i++) {
getters[i] = new AvroEventBeanGetterSimple(path[i], fragmentEventType, eventAdapterService, propertyTypes[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package com.espertech.esper.common.internal.avro.core;

import com.espertech.esper.common.client.type.EPTypeClass;
import com.espertech.esper.common.internal.bytecodemodel.base.CodegenFieldSharable;
import com.espertech.esper.common.internal.bytecodemodel.model.expression.CodegenExpression;
import org.apache.avro.Schema;
Expand All @@ -23,11 +24,11 @@ public AvroSchemaFieldSharable(Schema schema) {
this.schema = schema;
}

public Class type() {
return Schema.class;
public EPTypeClass type() {
return AvroConstant.EPTYPE_SCHEMA;
}

public CodegenExpression initCtorScoped() {
return exprDotMethod(newInstance(Schema.Parser.class), "parse", constant(schema.toString()));
return exprDotMethod(newInstance(AvroConstant.EPTYPE_SCHEMAPARSER), "parse", constant(schema.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.espertech.esper.common.client.configuration.common.ConfigurationCommonEventTypeMeta;
import com.espertech.esper.common.client.hook.type.TypeRepresentationMapper;
import com.espertech.esper.common.client.hook.type.TypeRepresentationMapperContext;
import com.espertech.esper.common.client.type.EPTypeClass;
import com.espertech.esper.common.internal.event.core.EventTypeNameResolver;
import com.espertech.esper.common.internal.event.core.EventTypeUtility;
import com.espertech.esper.common.internal.event.map.MapEventType;
Expand Down Expand Up @@ -79,8 +80,8 @@ public static void assembleField(String propertyName, Object propertyType, Schem
return;
}

if (optionalMapper != null && propertyType instanceof Class) {
Schema result = (Schema) optionalMapper.map(new TypeRepresentationMapperContext((Class) propertyType, propertyName, statementName));
if (optionalMapper != null && propertyType instanceof EPTypeClass) {
Schema result = (Schema) optionalMapper.map(new TypeRepresentationMapperContext(((EPTypeClass) propertyType).getType(), propertyName, statementName));
if (result != null) {
assembler.name(propertyName).type(result).noDefault();
return;
Expand Down Expand Up @@ -135,8 +136,8 @@ public static void assembleField(String propertyName, Object propertyType, Schem
} else {
throw new IllegalStateException("Unrecognized event type " + eventType);
}
} else if (propertyType instanceof Class) {
Class propertyClass = (Class) propertyType;
} else if (propertyType instanceof EPTypeClass) {
Class propertyClass = ((EPTypeClass) propertyType).getType();
Class propertyClassBoxed = JavaClassHelper.getBoxedType(propertyClass);
boolean nullable = propertyClass == propertyClassBoxed;
boolean preferNonNull = avroSettings.isEnableSchemaDefaultNonNull();
Expand Down
Loading

0 comments on commit 8dd0c24

Please sign in to comment.