Skip to content

Commit

Permalink
merge support for json event type
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardttom2 committed May 29, 2019
1 parent dbf59ae commit 5a8f6f0
Show file tree
Hide file tree
Showing 427 changed files with 29,269 additions and 1,091 deletions.
29 changes: 29 additions & 0 deletions checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,33 @@
<suppress files="SupportBean_IntAlphabetic.java" checks="[a-zA-Z0-9]*"/>
<suppress files="SupportBean_StringAlphabetic.java" checks="[a-zA-Z0-9]*"/>
<suppress files="EventInfraSuperType.java" checks="[a-zA-Z0-9]*"/>
<suppress files="Json.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonArray.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonHandler.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonLiteral.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonNumber.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonObject.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonParser.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonString.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonValue.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonWriter.java" checks="[a-zA-Z0-9]*"/>
<suppress files="Location.java" checks="[a-zA-Z0-9]*"/>
<suppress files="Member.java" checks="[a-zA-Z0-9]*"/>
<suppress files="ParseException.java" checks="[a-zA-Z0-9]*"/>
<suppress files="PrettyPrint.java" checks="[a-zA-Z0-9]*"/>
<suppress files="WriterConfig.java" checks="[a-zA-Z0-9]*"/>
<suppress files="WritingBuffer.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonArray_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonLiteral_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonNumber_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonObject_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonParser_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonString_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonValue_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="JsonWriter_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="Json_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="ParseException_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="PrettyPrint_Test.java" checks="[a-zA-Z0-9]*"/>
<suppress files="TestUtil.java" checks="[a-zA-Z0-9]*"/>
<suppress files="WritingBuffer_Test.java" checks="[a-zA-Z0-9]*"/>
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Object get(EventBean eventBean) throws PropertyAccessException {
}

public boolean isExistsProperty(EventBean eventBean) {
return true;
return isExistsPropertyAvro((GenericData.Record) eventBean.getUnderlying());
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand All @@ -59,7 +59,7 @@ public CodegenExpression eventBeanGetCodegen(CodegenExpression beanExpression, C
}

public CodegenExpression eventBeanExistsCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return underlyingExistsCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}

public CodegenExpression eventBeanFragmentCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand All @@ -71,7 +71,7 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return localMethod(getAvroFieldValuePolyExistsCodegen(codegenMethodScope, codegenClassScope, getters), underlyingExpression);
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ public static Object getAvroIndexedValue(Collection values, int index) {
return values.toArray()[index];
}

/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
*
* @param values coll
* @param index index
* @return value
*/
public static boolean getAvroIndexedExists(Collection values, int index) {
if (values == null) {
return false;
}
return values.size() > index;
}

public AvroEventBeanGetterIndexed(int pos, int index, EventType fragmentEventType, EventBeanTypedEventFactory eventAdapterService) {
this.pos = pos;
this.index = index;
Expand All @@ -73,11 +87,12 @@ public Object getAvroFieldValue(GenericData.Record record) {
}

public boolean isExistsProperty(EventBean eventBean) {
return true;
return isExistsPropertyAvro((GenericData.Record) eventBean.getUnderlying());
}

public boolean isExistsPropertyAvro(GenericData.Record record) {
return true;
Collection values = (Collection) record.get(pos);
return getAvroIndexedExists(values, index);
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand Down Expand Up @@ -109,7 +124,7 @@ public CodegenExpression eventBeanGetCodegen(CodegenExpression beanExpression, C
}

public CodegenExpression eventBeanExistsCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return underlyingExistsCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}

public CodegenExpression eventBeanFragmentCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand All @@ -122,7 +137,8 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
CodegenExpression values = cast(Collection.class, exprDotMethod(underlyingExpression, "get", constant(pos)));
return staticMethod(this.getClass(), "getAvroIndexedExists", values, constant(index));
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean isExistsProperty(EventBean eventBean) {
}

public boolean isExistsPropertyAvro(GenericData.Record record) {
return isAvroFieldExists(record, propertyName);
return isExistsPropertyAvro(record, propertyName, index);
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand Down Expand Up @@ -106,10 +106,26 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return staticMethod(this.getClass(), "isAvroFieldExists", underlyingExpression, constant(propertyName));
return staticMethod(this.getClass(), "isExistsPropertyAvro", underlyingExpression, constant(propertyName), constant(index));
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantNull();
}

/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
* @param record row
* @param propertyName property
* @param index index
* @return flag
*/
public static boolean isExistsPropertyAvro(GenericData.Record record, String propertyName, int index) {
Object value = record.get(propertyName);
if (!(value instanceof Collection)) {
return false;
}
Collection collection = (Collection) value;
return index < collection.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ private CodegenMethod getAvroFieldValueCodegen(CodegenMethodScope codegenMethodS
.methodReturn(exprDotMethod(ref("values"), "get", constant(key)));
}

private CodegenMethod getAvroFieldExistsCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock()
.declareVar(Map.class, "values", cast(Map.class, exprDotMethod(ref("record"), "get", constant(pos))))
.ifRefNullReturnFalse("values")
.methodReturn(exprDotMethod(ref("values"), "containsKey", constant(key)));
}

public boolean isExistsProperty(EventBean eventBean) {
return true;
return isExistsPropertyAvro((GenericData.Record) eventBean.getUnderlying());
}

public boolean isExistsPropertyAvro(GenericData.Record record) {
return true;
Map values = (Map) record.get(pos);
return values == null ? false : values.containsKey(key);
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand All @@ -71,7 +79,7 @@ public CodegenExpression eventBeanGetCodegen(CodegenExpression beanExpression, C
}

public CodegenExpression eventBeanExistsCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return underlyingExistsCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}

public CodegenExpression eventBeanFragmentCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand All @@ -83,7 +91,7 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return localMethod(getAvroFieldExistsCodegen(codegenMethodScope, codegenClassScope), underlyingExpression);
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean isExistsProperty(EventBean eventBean) {
}

public boolean isExistsPropertyAvro(GenericData.Record record) {
return isAvroFieldExists(record, propertyName);
return isExistsPropertyAvro(record, propertyName, key);
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand Down Expand Up @@ -110,10 +110,26 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return staticMethod(this.getClass(), "isAvroFieldExists", underlyingExpression, constant(propertyName));
return staticMethod(this.getClass(), "isExistsPropertyAvro", underlyingExpression, constant(propertyName), constant(key));
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantNull();
}

/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
* @param record row
* @param propertyName property
* @param key key
* @return flag
*/
public static boolean isExistsPropertyAvro(GenericData.Record record, String propertyName, String key) {
Object value = record.get(propertyName);
if (!(value instanceof Map)) {
return false;
}
return ((Map) value).containsKey(key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ private CodegenMethod getCodegen(CodegenMethodScope codegenMethodScope, CodegenC
.methodReturn(conditional(equalsNull(ref("inner")), constantNull(), getter.underlyingGetCodegen(ref("inner"), codegenMethodScope, codegenClassScope)));
}

private CodegenMethod existsCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock()
.declareVar(GenericData.Record.class, "inner", cast(GenericData.Record.class, exprDotMethod(ref("record"), "get", constant(fieldTop))))
.methodReturn(conditional(equalsNull(ref("inner")), constantFalse(), getter.underlyingExistsCodegen(ref("inner"), codegenMethodScope, codegenClassScope)));
}

private boolean isExistsProperty(GenericData.Record record) {
Schema.Field field = record.getSchema().getField(fieldTop);
if (field == null) {
Expand All @@ -64,15 +70,6 @@ private boolean isExistsProperty(GenericData.Record record) {
return getter.isExistsPropertyAvro((GenericData.Record) inner);
}

private CodegenMethod isExistsPropertyCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock()
.declareVar(Schema.Field.class, "field", exprDotMethodChain(ref("record")).add("getSchema").add("getField", constant(fieldTop)))
.ifRefNullReturnFalse("field")
.declareVar(Object.class, "inner", exprDotMethod(ref("record"), "get", constant(fieldTop)))
.ifRefNotTypeReturnConst("inner", GenericData.Record.class, false)
.methodReturn(getter.underlyingExistsCodegen(cast(GenericData.Record.class, ref("inner")), codegenMethodScope, codegenClassScope));
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
return null;
}
Expand All @@ -94,7 +91,7 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return localMethod(isExistsPropertyCodegen(codegenMethodScope, codegenClassScope), underlyingExpression);
return localMethod(existsCodegen(codegenMethodScope, codegenClassScope), underlyingExpression);
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,17 @@ private CodegenMethod getCodegen(CodegenMethodScope codegenMethodScope, CodegenC
.methodReturn(nested.underlyingGetCodegen(ref("inner"), codegenMethodScope, codegenClassScope));
}

private CodegenMethod existsCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock()
.declareVar(GenericData.Record.class, "inner", staticMethod(this.getClass(), "getAtIndex", ref("record"), constant(posTop), constant(index)))
.ifRefNullReturnFalse("inner")
.methodReturn(nested.underlyingExistsCodegen(ref("inner"), codegenMethodScope, codegenClassScope));
}

public boolean isExistsProperty(EventBean eventBean) {
return true;
GenericData.Record record = (GenericData.Record) eventBean.getUnderlying();
Collection values = (Collection) record.get(posTop);
return AvroEventBeanGetterIndexed.getAvroIndexedExists(values, index);
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand All @@ -94,7 +103,7 @@ public CodegenExpression eventBeanGetCodegen(CodegenExpression beanExpression, C
}

public CodegenExpression eventBeanExistsCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return underlyingExistsCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}

public CodegenExpression eventBeanFragmentCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand All @@ -106,7 +115,7 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return localMethod(existsCodegen(codegenMethodScope, codegenClassScope), underlyingExpression);
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ public static Object getRecordValueTopWPath(GenericData.Record record, int top,
return inner.get(path[path.length - 1]);
}

/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
*
* @param record record
* @param top top index
* @param path path of indexes
* @return value
* @throws PropertyAccessException property access problem
*/
public static boolean existsRecordValueTopWPath(GenericData.Record record, int top, int[] path) throws PropertyAccessException {
GenericData.Record inner = (GenericData.Record) record.get(top);
if (inner == null) {
return false;
}
for (int i = 0; i < path.length - 1; i++) {
inner = (GenericData.Record) inner.get(path[i]);
if (inner == null) {
return false;
}
}
return true;
}

public AvroEventBeanGetterNestedMultiLevel(int top, int[] path, EventType fragmentEventType, EventBeanTypedEventFactory eventAdapterService) {
this.top = top;
this.path = path;
Expand All @@ -68,7 +91,7 @@ public Object get(EventBean eventBean) throws PropertyAccessException {
}

public boolean isExistsProperty(EventBean eventBean) {
return true;
return existsRecordValueTopWPath((GenericData.Record) eventBean.getUnderlying(), top, path);
}

public Object getFragment(EventBean eventBean) throws PropertyAccessException {
Expand Down Expand Up @@ -96,7 +119,7 @@ public CodegenExpression eventBeanGetCodegen(CodegenExpression beanExpression, C
}

public CodegenExpression eventBeanExistsCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return underlyingExistsCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}

public CodegenExpression eventBeanFragmentCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand All @@ -108,7 +131,7 @@ public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpres
}

public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
return staticMethod(AvroEventBeanGetterNestedMultiLevel.class, "existsRecordValueTopWPath", underlyingExpression, constant(top), constant(path));
}

public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
Expand Down
Loading

0 comments on commit 5a8f6f0

Please sign in to comment.