public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return relational(arrayLength(underlyingExpression), GT, constant(index)); }
protected static CodegenMethod getBeanPropInternalCode(CodegenMethodScope codegenMethodScope, Method method, CodegenClassScope codegenClassScope) { return codegenMethodScope.makeChild(JavaClassHelper.getBoxedType(method.getReturnType().getComponentType()), ArrayMethodPropertyGetter.class, codegenClassScope).addParam(method.getDeclaringClass(), "obj").addParam(int.class, "index").getBlock() .declareVar(method.getReturnType(), "array", exprDotMethod(ref("obj"), method.getName())) .ifConditionReturnConst(relational(arrayLength(ref("array")), CodegenExpressionRelational.CodegenRelational.LE, ref("index")), null) .methodReturn(arrayAtIndex(ref("array"), ref("index"))); }
public CodegenExpression codegen(CodegenExpression inner, Class innerType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { CodegenMethod method = codegenMethodScope.makeChild(Integer.class, ExprDotForgeArraySize.class, codegenClassScope).addParam(innerType, "target").getBlock() .ifRefNullReturnNull("target") .methodReturn(arrayLength(ref("target"))); return localMethodBuild(method).pass(inner).call(); } }
public CodegenExpression evaluateCodegen(Class requiredType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { Class arrayType = JavaClassHelper.getArrayType(componentReturnType); CodegenMethod methodNode = codegenMethodScope.makeChild(arrayType, this.getClass(), codegenClassScope); methodNode.getBlock() .declareVar(EventBean[].class, "events", cast(EventBean[].class, inner.evaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope))) .ifRefNullReturnNull("events") .declareVar(arrayType, "values", newArrayByLength(componentReturnType, arrayLength(ref("events")))) .forLoopIntSimple("i", arrayLength(ref("events"))) .assignArrayElement("values", ref("i"), cast(componentReturnType, exprDotUnderlying(arrayAtIndex(ref("events"), ref("i"))))) .blockEnd() .methodReturn(ref("values")); return localMethod(methodNode); }
public static CodegenMethod getArrayPropertyAsUnderlyingsArrayCodegen(Class underlyingType, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return codegenMethodScope.makeChild(Object.class, BaseNestableEventUtil.class, codegenClassScope).addParam(EventBean[].class, "wrapper").getBlock() .ifRefNullReturnNull("wrapper") .declareVar(JavaClassHelper.getArrayType(underlyingType), "array", newArrayByLength(underlyingType, arrayLength(ref("wrapper")))) .forLoopIntSimple("i", arrayLength(ref("wrapper"))) .assignArrayElement("array", ref("i"), cast(underlyingType, exprDotMethod(arrayAtIndex(ref("wrapper"), ref("i")), "getUnderlying"))) .blockEnd() .methodReturn(ref("array")); }
static void sortWGroupKeysCodegen(OrderByProcessorForgeImpl forge, CodegenMethod method, CodegenClassScope classScope, CodegenNamedMethods namedMethods) { CodegenMethod sortWGroupKeysInternal = sortWGroupKeysInternalCodegen(forge, classScope, namedMethods); method.getBlock().ifCondition(or(equalsNull(REF_OUTGOINGEVENTS), relational(arrayLength(REF_OUTGOINGEVENTS), LT, constant(2)))) .blockReturn(REF_OUTGOINGEVENTS) .methodReturn(localMethod(sortWGroupKeysInternal, REF_OUTGOINGEVENTS, REF_GENERATINGEVENTS, REF_ORDERGROUPBYKEYS, REF_ISNEWDATA, REF_EXPREVALCONTEXT, REF_AGGREGATIONSVC)); }
static void sortPlainCodegen(OrderByProcessorForgeImpl forge, CodegenMethod method, CodegenClassScope classScope, CodegenNamedMethods namedMethods) { CodegenMethod node = sortWGroupKeysInternalCodegen(forge, classScope, namedMethods); method.getBlock().ifCondition(or(equalsNull(REF_OUTGOINGEVENTS), relational(arrayLength(REF_OUTGOINGEVENTS), LT, constant(2)))) .blockReturn(REF_OUTGOINGEVENTS); method.getBlock().methodReturn(localMethod(node, REF_OUTGOINGEVENTS, REF_GENERATINGEVENTS, constantNull(), REF_ISNEWDATA, REF_EXPREVALCONTEXT, REF_AGGREGATIONSVC)); }
public static CodegenExpression codegen(ExprDotForgeArrayGet forge, CodegenExpression inner, Class innerType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { CodegenMethod methodNode = codegenMethodScope.makeChild(EPTypeHelper.getNormalizedClass(forge.getTypeInfo()), ExprDotForgeArrayGetEval.class, codegenClassScope).addParam(innerType, "target"); CodegenBlock block = methodNode.getBlock(); if (!innerType.isPrimitive()) { block.ifRefNullReturnNull("target"); } block.declareVar(int.class, "index", forge.getIndexExpression().evaluateCodegen(int.class, methodNode, exprSymbol, codegenClassScope)); block.ifCondition(relational(arrayLength(ref("target")), LE, ref("index"))) .blockReturn(constantNull()) .methodReturn(arrayAtIndex(ref("target"), ref("index"))); return localMethod(methodNode, inner); } }
public static CodegenMethod getArrayPropertyFragmentCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope, int index, EventPropertyGetterSPI nestedGetter) { return codegenMethodScope.makeChild(Object.class, BaseNestableEventUtil.class, codegenClassScope).addParam(EventBean[].class, "wrapper").getBlock() .ifRefNullReturnNull("wrapper") .ifConditionReturnConst(relational(arrayLength(ref("wrapper")), LE, constant(index)), null) .declareVar(EventBean.class, "inner", arrayAtIndex(ref("wrapper"), constant(index))) .methodReturn(nestedGetter.eventBeanFragmentCodegen(ref("inner"), codegenMethodScope, codegenClassScope)); }
public static CodegenMethod generateGroupKeyArrayViewCodegen(ExprNode[] groupKeyExpressions, CodegenClassScope classScope, CodegenInstanceAux instance) { CodegenMethod generateGroupKeySingle = generateGroupKeySingleCodegen(groupKeyExpressions, classScope, instance); Consumer<CodegenMethod> code = method -> { method.getBlock().ifRefNullReturnNull("events") .declareVar(EventBean[].class, "eventsPerStream", newArrayByLength(EventBean.class, constant(1))) .declareVar(Object[].class, "keys", newArrayByLength(Object.class, arrayLength(ref("events")))); { CodegenBlock forLoop = method.getBlock().forLoopIntSimple("i", arrayLength(ref("events"))); forLoop.assignArrayElement("eventsPerStream", constant(0), arrayAtIndex(ref("events"), ref("i"))) .assignArrayElement("keys", ref("i"), localMethod(generateGroupKeySingle, ref("eventsPerStream"), REF_ISNEWDATA)); } method.getBlock().methodReturn(ref("keys")); }; return instance.getMethods().addMethod(Object[].class, "generateGroupKeyArrayView", CodegenNamedParam.from(EventBean[].class, "events", boolean.class, NAME_ISNEWDATA), ResultSetProcessorRowPerGroup.class, classScope, code); }
public static CodegenMethod getArrayPropertyValueCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope, int index, EventPropertyGetterSPI nestedGetter) { return codegenMethodScope.makeChild(Object.class, BaseNestableEventUtil.class, codegenClassScope).addParam(EventBean[].class, "wrapper").getBlock() .ifRefNullReturnNull("wrapper") .ifConditionReturnConst(relational(arrayLength(ref("wrapper")), LE, constant(index)), null) .declareVar(EventBean.class, "inner", arrayAtIndex(ref("wrapper"), constant(index))) .methodReturn(nestedGetter.eventBeanGetCodegen(ref("inner"), codegenMethodScope, codegenClassScope)); }
private static CodegenMethod generateGroupKeysRowCodegen(ResultSetProcessorRowPerGroupRollupForge forge, CodegenClassScope classScope, CodegenInstanceAux instance) { CodegenMethod generateGroupKeySingle = generateGroupKeySingleCodegen(forge.getGroupKeyNodeExpressions(), classScope, instance); Consumer<CodegenMethod> code = methodNode -> methodNode.getBlock().declareVar(Object.class, "groupKeyComplete", localMethod(generateGroupKeySingle, ref("eventsPerStream"), REF_ISNEWDATA)) .declareVar(AggregationGroupByRollupLevel[].class, "levels", exprDotMethodChain(ref("this")).add("getGroupByRollupDesc").add("getLevels")) .declareVar(Object[].class, "result", newArrayByLength(Object.class, arrayLength(ref("levels")))) .forLoopIntSimple("j", arrayLength(ref("levels"))) .declareVar(Object.class, "subkey", exprDotMethod(arrayAtIndex(ref("levels"), ref("j")), "computeSubkey", ref("groupKeyComplete"))) .assignArrayElement("result", ref("j"), ref("subkey")) .blockEnd() .methodReturn(ref("result")); return instance.getMethods().addMethod(Object[].class, "generateGroupKeysRow", CodegenNamedParam.from(EventBean[].class, "eventsPerStream", boolean.class, NAME_ISNEWDATA), ResultSetProcessorUtil.class, classScope, code); }
public CodegenExpression getLastValueCodegen(CodegenClassScope classScope, CodegenMethod parentMethod, CodegenNamedMethods namedMethods) { CodegenMethod initArray = initArrayCodegen(namedMethods, classScope); CodegenMethod method = parentMethod.makeChildWithScope(EventBean.class, AggregatorAccessLinearJoin.class, CodegenSymbolProviderEmpty.INSTANCE, classScope); method.getBlock().ifCondition(exprDotMethod(refSet, "isEmpty")).blockReturn(constantNull()) .ifCondition(equalsNull(array)).localMethod(initArray).blockEnd() .methodReturn(arrayAtIndex(array, op(arrayLength(array), "-", constant(1)))); return localMethod(method); }
public CodegenExpression evaluateCodegen(Class requiredType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { Class arrayType = JavaClassHelper.getArrayType(componentReturnType); CodegenMethod methodNode = codegenMethodScope.makeChild(arrayType, InstanceManufacturerForgeArray.class, codegenClassScope); methodNode.getBlock() .declareVar(Object.class, "result", innerForge.evaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope)) .ifCondition(not(instanceOf(ref("result"), EventBean[].class))) .blockReturn(constantNull()) .declareVar(EventBean[].class, "events", cast(EventBean[].class, ref("result"))) .declareVar(arrayType, "values", newArrayByLength(componentReturnType, arrayLength(ref("events")))) .forLoopIntSimple("i", arrayLength(ref("events"))) .assignArrayElement("values", ref("i"), cast(componentReturnType, exprDotMethod(arrayAtIndex(ref("events"), ref("i")), "getUnderlying"))) .blockEnd() .methodReturn(ref("values")); return localMethod(methodNode); }
private CodegenMethod handleRemovedKeysCodegen(CodegenMethod scope, CodegenClassScope classScope) { CodegenMethod method = scope.makeChild(void.class, this.getClass(), classScope); method.getBlock().ifCondition(not(REF_HASREMOVEDKEY)) .blockReturnNoValue() .assignRef(REF_HASREMOVEDKEY, constantFalse()) .forLoopIntSimple("i", arrayLength(REF_REMOVEDKEYS)) .ifCondition(exprDotMethod(arrayAtIndex(REF_REMOVEDKEYS, ref("i")), "isEmpty")) .blockContinue() .forEach(Object.class, "removedKey", arrayAtIndex(REF_REMOVEDKEYS, ref("i"))) .exprDotMethod(arrayAtIndex(REF_AGGREGATORSPERGROUP, ref("i")), "remove", ref("removedKey")) .blockEnd() .exprDotMethod(arrayAtIndex(REF_REMOVEDKEYS, ref("i")), "clear"); return method; } }
static CodegenMethod generateGroupKeysKeepEventCodegen(ResultSetProcessorRowPerGroupForge forge, CodegenClassScope classScope, CodegenInstanceAux instance) { CodegenMethod key = generateGroupKeySingleCodegen(forge.getGroupKeyNodeExpressions(), classScope, instance); Consumer<CodegenMethod> code = methodNode -> { methodNode.getBlock().ifRefNullReturnNull("events") .declareVar(Object[].class, "keys", newArrayByLength(Object.class, arrayLength(ref("events")))); { methodNode.getBlock().forLoopIntSimple("i", arrayLength(ref("events"))) .assignArrayElement(REF_EPS, constant(0), arrayAtIndex(ref("events"), ref("i"))) .assignArrayElement("keys", ref("i"), localMethod(key, REF_EPS, REF_ISNEWDATA)) .exprDotMethod(ref("eventPerKey"), "put", arrayAtIndex(ref("keys"), ref("i")), arrayAtIndex(ref("events"), ref("i"))) .blockEnd(); } methodNode.getBlock().methodReturn(ref("keys")); }; return instance.getMethods().addMethod(Object[].class, "generateGroupKeysKeepEvent", CodegenNamedParam.from(EventBean[].class, "events", Map.class, "eventPerKey", boolean.class, NAME_ISNEWDATA, EventBean[].class, NAME_EPS), ResultSetProcessorRowPerGroupImpl.class, classScope, code); }
public static void processViewResultCodegen(ResultSetProcessorAggregateGroupedForge forge, CodegenClassScope classScope, CodegenMethod method, CodegenInstanceAux instance) { CodegenMethod generateGroupKeyArrayView = generateGroupKeyArrayViewCodegen(forge.getGroupKeyNodeExpressions(), classScope, instance); CodegenMethod generateOutputEventsView = generateOutputEventsViewCodegen(forge, classScope, instance); CodegenMethod processViewResultNewDepthOne = processViewResultNewDepthOneCodegen(forge, classScope, instance); CodegenMethod processViewResultPairDepthOneNoRStream = processViewResultPairDepthOneCodegen(forge, classScope, instance); CodegenBlock ifShortcut = method.getBlock().ifCondition(and(notEqualsNull(REF_NEWDATA), equalsIdentity(arrayLength(REF_NEWDATA), constant(1)))); ifShortcut.ifCondition(or(equalsNull(REF_OLDDATA), equalsIdentity(arrayLength(REF_OLDDATA), constant(0)))) .blockReturn(localMethod(processViewResultNewDepthOne, REF_NEWDATA, REF_ISSYNTHESIZE)) .ifCondition(equalsIdentity(arrayLength(REF_OLDDATA), constant(1))) .blockReturn(localMethod(processViewResultPairDepthOneNoRStream, REF_NEWDATA, REF_OLDDATA, REF_ISSYNTHESIZE)); method.getBlock().declareVar(Object[].class, "newDataGroupByKeys", localMethod(generateGroupKeyArrayView, REF_NEWDATA, constantTrue())) .declareVar(Object[].class, "oldDataGroupByKeys", localMethod(generateGroupKeyArrayView, REF_OLDDATA, constantFalse())) .declareVar(EventBean[].class, "eventsPerStream", newArrayByLength(EventBean.class, constant(1))) .staticMethod(ResultSetProcessorGroupedUtil.class, METHOD_APPLYAGGVIEWRESULTKEYEDVIEW, REF_AGGREGATIONSVC, REF_AGENTINSTANCECONTEXT, REF_NEWDATA, ref("newDataGroupByKeys"), REF_OLDDATA, ref("oldDataGroupByKeys"), ref("eventsPerStream")); method.getBlock().declareVar(EventBean[].class, "selectOldEvents", forge.isSelectRStream() ? localMethod(generateOutputEventsView, REF_OLDDATA, ref("oldDataGroupByKeys"), constantFalse(), REF_ISSYNTHESIZE, ref("eventsPerStream")) : constantNull()) .declareVar(EventBean[].class, "selectNewEvents", localMethod(generateOutputEventsView, REF_NEWDATA, ref("newDataGroupByKeys"), constantTrue(), REF_ISSYNTHESIZE, ref("eventsPerStream"))) .methodReturn(staticMethod(ResultSetProcessorUtil.class, METHOD_TOPAIRNULLIFALLNULL, ref("selectNewEvents"), ref("selectOldEvents"))); }
public static void outputFromCountMaySortCodegen(CodegenBlock block, CodegenExpressionRef count, CodegenExpressionRef events, CodegenExpressionRef keys, CodegenExpressionRef currentGenerators, boolean hasOrderBy) { CodegenBlock resize = block.ifCondition(not(equalsIdentity(count, arrayLength(events)))); resize.ifCondition(equalsIdentity(count, constant(0))).blockReturn(constantNull()) .assignRef(events.getRef(), staticMethod(CollectionUtil.class, METHOD_SHRINKARRAYEVENTS, count, events)); if (hasOrderBy) { resize.assignRef(keys.getRef(), staticMethod(CollectionUtil.class, METHOD_SHRINKARRAYOBJECTS, count, keys)) .assignRef(currentGenerators.getRef(), staticMethod(CollectionUtil.class, METHOD_SHRINKARRAYEVENTARRAY, count, currentGenerators)); } if (hasOrderBy) { block.assignRef(events.getRef(), exprDotMethod(REF_ORDERBYPROCESSOR, "sortWGroupKeys", events, currentGenerators, keys, REF_ISNEWDATA, REF_AGENTINSTANCECONTEXT, REF_AGGREGATIONSVC)); } block.methodReturn(events); }
public CodegenExpression getLastNthValueCodegen(CodegenExpressionRef index, CodegenMethod parentMethod, CodegenClassScope classScope, CodegenNamedMethods namedMethods) { CodegenMethod initArray = initArrayCodegen(namedMethods, classScope); CodegenMethod method = parentMethod.makeChildWithScope(EventBean.class, AggregatorAccessLinearJoin.class, CodegenSymbolProviderEmpty.INSTANCE, classScope).addParam(int.class, "index"); method.getBlock().ifCondition(relational(ref("index"), LT, constant(0))).blockReturn(constantNull()) .ifCondition(exprDotMethod(refSet, "isEmpty")).blockReturn(constantNull()) .ifCondition(relational(ref("index"), GE, exprDotMethod(refSet, "size"))).blockReturn(constantNull()) .ifCondition(equalsNull(array)).localMethod(initArray).blockEnd() .methodReturn(arrayAtIndex(array, op(op(arrayLength(array), "-", ref("index")), "-", constant(1)))); return localMethod(method, index); }
static void sortPlainCodegenCodegen(OrderByProcessorOrderedLimitForge forge, CodegenMethod method, CodegenClassScope classScope, CodegenNamedMethods namedMethods) { CodegenExpression limit1 = equalsIdentity(exprDotMethod(REF_ROWLIMITPROCESSOR, "getCurrentRowLimit"), constant(1)); CodegenExpression offset0 = equalsIdentity(exprDotMethod(REF_ROWLIMITPROCESSOR, "getCurrentOffset"), constant(0)); CodegenExpression haveOutgoing = and(notEqualsNull(REF_OUTGOINGEVENTS), relational(arrayLength(REF_OUTGOINGEVENTS), GT, constant(1))); CodegenMethod determineLocalMinMax = OrderByProcessorImpl.determineLocalMinMaxCodegen(forge.getOrderByProcessorForge(), classScope, namedMethods); CodegenMethod sortPlain = method.makeChild(EventBean[].class, OrderByProcessorOrderedLimit.class, classScope).addParam(SORTPLAIN_PARAMS); OrderByProcessorImpl.sortPlainCodegen(forge.getOrderByProcessorForge(), sortPlain, classScope, namedMethods); method.getBlock().exprDotMethod(REF_ROWLIMITPROCESSOR, "determineCurrentLimit") .ifCondition(and(limit1, offset0, haveOutgoing)) .declareVar(EventBean.class, "minmax", localMethod(determineLocalMinMax, REF_OUTGOINGEVENTS, REF_GENERATINGEVENTS, REF_ISNEWDATA, REF_EXPREVALCONTEXT, REF_AGGREGATIONSVC)) .blockReturn(newArrayWithInit(EventBean.class, ref("minmax"))) .declareVar(EventBean[].class, "sorted", localMethod(sortPlain, REF_OUTGOINGEVENTS, REF_GENERATINGEVENTS, REF_ISNEWDATA, REF_EXPREVALCONTEXT, REF_AGGREGATIONSVC)) .methodReturn(exprDotMethod(REF_ROWLIMITPROCESSOR, "applyLimit", ref("sorted"))); }