private static void codegenDoIfNullOrNotPass(CodegenBlock block, Class evaluationType, CodegenExpression expression, boolean doContinue, boolean doBreakLoop, CodegenExpression returnValue) { if (evaluationType != boolean.class && evaluationType != Boolean.class) { throw new IllegalStateException("Invalid non-boolean expression"); } block.declareVar(evaluationType, PASS_NAME, expression); CodegenExpression passCheck = not(ref(PASS_NAME)); CodegenExpression condition; if (evaluationType.isPrimitive()) { condition = passCheck; } else { condition = or(equalsNull(ref(PASS_NAME)), passCheck); } if (doContinue) { block.ifCondition(condition).blockContinue(); } else if (doBreakLoop) { block.ifCondition(condition).breakLoop(); } else { block.ifCondition(condition).blockReturn(returnValue); } } }
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 CodegenExpression codegen(EnumForgeCodegenParams args, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { Class type = EPTypeHelper.getCodegenReturnType(resultType); CodegenMethod method = codegenMethodScope.makeChild(type, EnumFirstOfNoPredicateForge.class, codegenClassScope).addParam(EnumForgeCodegenNames.PARAMS).getBlock() .ifCondition(or(equalsNull(EnumForgeCodegenNames.REF_ENUMCOLL), exprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "isEmpty"))) .blockReturn(constantNull()) .methodReturn(cast(type, exprDotMethodChain(EnumForgeCodegenNames.REF_ENUMCOLL).add("iterator").add("next"))); return localMethod(method, args.getExpressions()); } }
public CodegenExpression codegen(EnumForgeCodegenParams args, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { CodegenBlock block = codegenMethodScope.makeChild(Collection.class, EnumOrderByAscDescScalarForge.class, codegenClassScope).addParam(EnumForgeCodegenNames.PARAMS).getBlock() .ifCondition(or(equalsNull(EnumForgeCodegenNames.REF_ENUMCOLL), exprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "isEmpty"))) .blockReturn(EnumForgeCodegenNames.REF_ENUMCOLL) .declareVar(List.class, "list", newInstance(ArrayList.class, EnumForgeCodegenNames.REF_ENUMCOLL)); if (descending) { block.staticMethod(Collections.class, "sort", ref("list"), staticMethod(Collections.class, "reverseOrder")); } else { block.staticMethod(Collections.class, "sort", ref("list")); } CodegenMethod method = block.methodReturn(ref("list")); return localMethod(method, args.getExpressions()); } }
public static void applyEnterCodegenSweep(CodegenMethod method, CodegenClassScope classScope, AggregationClassNames classNames) { CodegenExpressionField timeAbacus = classScope.addOrGetFieldSharable(TimeAbacusField.INSTANCE); method.getBlock().declareVar(long.class, "currentTime", exprDotMethodChain(REF_EXPREVALCONTEXT).add("getTimeProvider").add("getTime")) .ifCondition(or(equalsNull(REF_NEXTSWEEPTIME), relational(REF_NEXTSWEEPTIME, LE, ref("currentTime")))) .assignRef(REF_CURRENTMAXAGE, staticMethod(AggSvcGroupByReclaimAgedImpl.class, "computeTimeReclaimAgeFreq", REF_CURRENTMAXAGE, REF_EVALUATORFUNCTIONMAXAGE, timeAbacus)) .assignRef(REF_CURRENTRECLAIMFREQUENCY, staticMethod(AggSvcGroupByReclaimAgedImpl.class, "computeTimeReclaimAgeFreq", REF_CURRENTRECLAIMFREQUENCY, REF_EVALUATIONFUNCTIONFREQUENCY, timeAbacus)) .assignRef(REF_NEXTSWEEPTIME, op(ref("currentTime"), "+", REF_CURRENTRECLAIMFREQUENCY)) .localMethod(sweepCodegen(method, classScope, classNames), ref("currentTime"), REF_CURRENTMAXAGE); }
public static CodegenExpression evaluateCodegen(ExprEventIdentityEqualsNodeForge forge, CodegenMethodScope parent, ExprForgeCodegenSymbol symbols, CodegenClassScope classScope) { CodegenMethod method = parent.makeChild(Boolean.class, ExprEventIdentityEqualsNodeEval.class, classScope); method.getBlock() .declareVar(EventBean.class, "left", arrayAtIndex(symbols.getAddEPS(method), constant(forge.getUndLeft().getStreamId()))) .declareVar(EventBean.class, "right", arrayAtIndex(symbols.getAddEPS(method), constant(forge.getUndRight().getStreamId()))) .ifCondition(or(equalsNull(ref("left")), equalsNull(ref("right")))) .blockReturn(constantNull()) .methodReturn(exprDotMethod(ref("left"), "equals", ref("right"))); return localMethod(method); }
public CodegenMethod processCodegen(CodegenExpression resultEventType, CodegenExpression eventBeanFactory, CodegenMethodScope codegenMethodScope, SelectExprProcessorCodegenSymbol selectSymbol, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { CodegenMethod processMethod = codegenMethodScope.makeChild(EventBean.class, this.getClass(), codegenClassScope); CodegenExpressionRef isSythesize = selectSymbol.getAddSynthesize(processMethod); CodegenMethod syntheticMethod = syntheticProcessorForge.processCodegen(resultEventType, eventBeanFactory, processMethod, selectSymbol, exprSymbol, codegenClassScope); CodegenMethod bindMethod = bindProcessorForge.processCodegen(processMethod, exprSymbol, codegenClassScope); CodegenExpression isNewData = exprSymbol.getAddIsNewData(processMethod); CodegenExpression exprCtx = exprSymbol.getAddExprEvalCtx(processMethod); CodegenExpressionField stmtResultSvc = codegenClassScope.addFieldUnshared(true, StatementResultService.class, exprDotMethod(EPStatementInitServices.REF, GETSTATEMENTRESULTSERVICE)); processMethod.getBlock() .declareVar(boolean.class, "makeNatural", exprDotMethod(stmtResultSvc, "isMakeNatural")) .declareVar(boolean.class, "synthesize", or(exprDotMethod(stmtResultSvc, "isMakeSynthetic"), isSythesize)) .ifCondition(not(ref("makeNatural"))) .ifCondition(ref("synthesize")) .declareVar(EventBean.class, "synthetic", localMethod(syntheticMethod)) .blockReturn(ref("synthetic")) .blockReturn(constantNull()) .declareVar(EventBean.class, "syntheticEvent", constantNull()) .ifCondition(ref("synthesize")) .assignRef("syntheticEvent", localMethod(syntheticMethod)) .blockEnd() .declareVar(Object[].class, "parameters", localMethod(bindMethod)) .methodReturn(newInstance(NaturalEventBean.class, resultEventType, ref("parameters"), ref("syntheticEvent"))); return processMethod; } }
public void processCodegen(CodegenMethod method, CodegenClassScope classScope) { method.getBlock().apply(instblock(classScope, "qOutputProcessNonBufferedJoin", REF_NEWDATA, REF_OLDDATA)); generateRSPCall("processJoinResult", method, classScope); method.getBlock().ifRefNull("newOldEvents") .apply(instblock(classScope, "aOutputProcessNonBufferedJoin")) .blockReturnNoValue(); if (postProcess != null) { method.getBlock().expression(localMethod(postProcess.postProcessCodegenMayNullMayForce(classScope, method), constantFalse(), ref("newOldEvents"))); } else { CodegenBlock ifPairHasData = method.getBlock().ifCondition(or(notEqualsNull(exprDotMethod(ref("newOldEvents"), "getFirst")), notEqualsNull(exprDotMethod(ref("newOldEvents"), "getSecond")))); ifPairHasData.exprDotMethod(REF_CHILD, "newResult", ref("newOldEvents")) .ifElseIf(and(equalsNull(ref("newData")), equalsNull(ref("oldData")))) .exprDotMethod(REF_CHILD, "newResult", ref("newOldEvents")); } method.getBlock().apply(instblock(classScope, "aOutputProcessNonBufferedJoin")); }
public static CodegenExpression codegen(EnumUnionForge forge, EnumForgeCodegenParams args, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { ExprForgeCodegenSymbol scope = new ExprForgeCodegenSymbol(false, null); CodegenMethod methodNode = codegenMethodScope.makeChildWithScope(Collection.class, EnumUnionForgeEval.class, scope, codegenClassScope).addParam(EnumForgeCodegenNames.PARAMS); CodegenBlock block = methodNode.getBlock(); if (forge.scalar) { block.declareVar(Collection.class, "other", forge.evaluatorForge.evaluateGetROCollectionScalarCodegen(methodNode, scope, codegenClassScope)); } else { block.declareVar(Collection.class, "other", forge.evaluatorForge.evaluateGetROCollectionEventsCodegen(methodNode, scope, codegenClassScope)); } block.ifCondition(or(equalsNull(ref("other")), exprDotMethod(ref("other"), "isEmpty"))) .blockReturn(EnumForgeCodegenNames.REF_ENUMCOLL); block.declareVar(ArrayList.class, "result", newInstance(ArrayList.class, op(exprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "size"), "+", exprDotMethod(ref("other"), "size")))) .expression(exprDotMethod(ref("result"), "addAll", EnumForgeCodegenNames.REF_ENUMCOLL)) .expression(exprDotMethod(ref("result"), "addAll", ref("other"))) .methodReturn(ref("result")); return localMethod(methodNode, args.getEps(), args.getEnumcoll(), args.getIsNewData(), args.getExprCtx()); } }
public void updateCodegen(CodegenMethod method, CodegenClassScope classScope) { method.getBlock().apply(instblock(classScope, "qOutputProcessNonBuffered", REF_NEWDATA, REF_OLDDATA)); generateRSPCall("processViewResult", method, classScope); if (postProcess != null) { CodegenExpression newOldIsNull = and(equalsNull(exprDotMethod(ref("newOldEvents"), "getFirst")), equalsNull(exprDotMethod(ref("newOldEvents"), "getSecond"))); method.getBlock() .declareVar(boolean.class, "forceOutput", constant(false)) .ifCondition(and(equalsNull(REF_NEWDATA), equalsNull(REF_OLDDATA))) .ifCondition(or(equalsNull(ref("newOldEvents")), newOldIsNull)) .assignRef("forceOutput", constantTrue()); method.getBlock() .expression(localMethod(postProcess.postProcessCodegenMayNullMayForce(classScope, method), ref("forceOutput"), ref("newOldEvents"))) .apply(instblock(classScope, "aOutputProcessNonBuffered")); return; } CodegenBlock ifChild = method.getBlock().ifCondition(notEqualsNull(REF_CHILD)); CodegenBlock ifResultNotNull = ifChild.ifRefNotNull("newOldEvents"); CodegenBlock ifPairHasData = ifResultNotNull.ifCondition(or(notEqualsNull(exprDotMethod(ref("newOldEvents"), "getFirst")), notEqualsNull(exprDotMethod(ref("newOldEvents"), "getSecond")))); ifPairHasData.exprDotMethod(REF_CHILD, "newResult", ref("newOldEvents")) .ifElseIf(and(equalsNull(ref("newData")), equalsNull(ref("oldData")))) .exprDotMethod(REF_CHILD, "newResult", ref("newOldEvents")); CodegenBlock ifResultNull = ifResultNotNull.ifElse(); ifResultNull.ifCondition(and(equalsNull(ref("newData")), equalsNull(ref("oldData")))) .exprDotMethod(REF_CHILD, "newResult", ref("newOldEvents")) .blockEnd() .blockEnd() .apply(instblock(classScope, "aOutputProcessNonBuffered")); }
private static CodegenMethod generateGroupKeyArrayJoinTakingMapCodegen(ResultSetProcessorRowPerGroupForge forge, CodegenClassScope classScope, CodegenInstanceAux instance) { CodegenMethod key = generateGroupKeySingleCodegen(forge.getGroupKeyNodeExpressions(), classScope, instance); Consumer<CodegenMethod> code = methodNode -> { methodNode.getBlock().ifCondition(or(equalsNull(ref("resultSet")), exprDotMethod(ref("resultSet"), "isEmpty"))).blockReturn(constantNull()) .declareVar(Object[].class, "keys", newArrayByLength(Object.class, exprDotMethod(ref("resultSet"), "size"))) .declareVar(int.class, "count", constant(0)); { methodNode.getBlock().forEach(MultiKey.class, "eventsPerStream", ref("resultSet")) .declareVar(EventBean[].class, "eps", cast(EventBean[].class, exprDotMethod(ref("eventsPerStream"), "getArray"))) .assignArrayElement("keys", ref("count"), localMethod(key, ref("eps"), REF_ISNEWDATA)) .exprDotMethod(ref("eventPerKey"), "put", arrayAtIndex(ref("keys"), ref("count")), ref("eps")) .increment("count") .blockEnd(); } methodNode.getBlock().methodReturn(ref("keys")); }; return instance.getMethods().addMethod(Object[].class, "generateGroupKeyArrayJoinTakingMapCodegen", CodegenNamedParam.from(Set.class, "resultSet", Map.class, "eventPerKey", boolean.class, NAME_ISNEWDATA), ResultSetProcessorRowPerGroupImpl.class, classScope, code); }
.ifCondition(not(ref("hasRows"))) .blockReturn(constantFalse()) .ifCondition(or(not(ref("hasNonNullRow")), equalsNull(symbols.getAddLeftResult(method)))) .blockReturn(constantNull()) .methodReturn(constantFalse());
.ifCondition(or(equalsNull(ref("localMinMax")), relational(exprDotMethod(comparator, "compare", ref("localMinMax"), ref("sortKey")), GT, constant(0)))) .assignRef("localMinMax", ref("sortKey")) .assignRef("outgoingMinMaxBean", arrayAtIndex(REF_OUTGOINGEVENTS, ref("count"))) forEach.ifCondition(or(equalsNull(ref("localMinMax")), relational(exprDotMethod(comparator, "compare", ref("localMinMax"), ref("valuesMk")), GT, constant(0)))) .assignRef("localMinMax", ref("valuesMk")) .assignRef("values", newArrayByLength(Object.class, constant(elements.length)))
public static CodegenMethod getSelectJoinEventsHavingCodegen(CodegenClassScope classScope, CodegenInstanceAux instance) { Consumer<CodegenMethod> code = methodNode -> { methodNode.getBlock() .ifCondition(or(equalsNull(ref("events")), exprDotMethod(ref("events"), "isEmpty"))).blockReturn(constantNull()) .ifRefNullReturnNull("events") .declareVar(ArrayDeque.class, "result", constantNull()); { CodegenBlock forEach = methodNode.getBlock().forEach(MultiKey.class, "key", ref("events")); forEach.declareVar(EventBean[].class, NAME_EPS, cast(EventBean[].class, exprDotMethod(ref("key"), "getArray"))); forEach.ifCondition(not(localMethod(instance.getMethods().getMethod("evaluateHavingClause"), REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT))).blockContinue(); forEach.declareVar(EventBean.class, "generated", exprDotMethod(REF_SELECTEXPRNONMEMBER, "process", REF_EPS, REF_ISNEWDATA, REF_ISSYNTHESIZE, REF_EXPREVALCONTEXT)) .ifCondition(notEqualsNull(ref("generated"))) .ifCondition(equalsNull(ref("result"))) .assignRef("result", newInstance(ArrayDeque.class, exprDotMethod(ref("events"), "size"))).blockEnd() .exprDotMethod(ref("result"), "add", ref("generated")).blockEnd(); } methodNode.getBlock().methodReturn(staticMethod(CollectionUtil.class, METHOD_TOARRAYMAYNULL, ref("result"))); }; return instance.getMethods().addMethod(EventBean[].class, "getSelectJoinEventsHaving", CodegenNamedParam.from(SelectExprProcessor.class, NAME_SELECTEXPRPROCESSOR, Set.class, "events", boolean.class, NAME_ISNEWDATA, boolean.class, NAME_ISSYNTHESIZE, ExprEvaluatorContext.class, NAME_EXPREVALCONTEXT), ResultSetProcessorUtil.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 processViewResultCodegen(ResultSetProcessorRowPerGroupForge forge, CodegenClassScope classScope, CodegenMethod method, CodegenInstanceAux instance) { CodegenMethod generateGroupKeysKeepEvent = generateGroupKeysKeepEventCodegen(forge, classScope, instance); CodegenMethod generateOutputEventsView = generateOutputEventsViewCodegen(forge, classScope, instance); CodegenMethod processViewResultNewDepthOne = processViewResultNewDepthOneCodegen(forge, classScope, instance); CodegenMethod processViewResultPairDepthOneNoRStream = processViewResultPairDepthOneNoRStreamCodegen(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)); if (!forge.isSelectRStream()) { ifShortcut.ifCondition(equalsIdentity(arrayLength(REF_OLDDATA), constant(1))) .blockReturn(localMethod(processViewResultPairDepthOneNoRStream, REF_NEWDATA, REF_OLDDATA, REF_ISSYNTHESIZE)); } method.getBlock().declareVar(Map.class, "keysAndEvents", newInstance(HashMap.class)) .declareVar(EventBean[].class, "eventsPerStream", newArrayByLength(EventBean.class, constant(1))) .declareVar(Object[].class, "newDataMultiKey", localMethod(generateGroupKeysKeepEvent, REF_NEWDATA, ref("keysAndEvents"), constantTrue(), ref("eventsPerStream"))) .declareVar(Object[].class, "oldDataMultiKey", localMethod(generateGroupKeysKeepEvent, REF_OLDDATA, ref("keysAndEvents"), constantFalse(), ref("eventsPerStream"))) .declareVar(EventBean[].class, "selectOldEvents", forge.isSelectRStream() ? localMethod(generateOutputEventsView, ref("keysAndEvents"), constantFalse(), REF_ISSYNTHESIZE, ref("eventsPerStream")) : constantNull()) .staticMethod(ResultSetProcessorGroupedUtil.class, METHOD_APPLYAGGVIEWRESULTKEYEDVIEW, REF_AGGREGATIONSVC, REF_AGENTINSTANCECONTEXT, REF_NEWDATA, ref("newDataMultiKey"), REF_OLDDATA, ref("oldDataMultiKey"), ref("eventsPerStream")) .declareVar(EventBean[].class, "selectNewEvents", localMethod(generateOutputEventsView, ref("keysAndEvents"), constantTrue(), REF_ISSYNTHESIZE, ref("eventsPerStream"))) .methodReturn(staticMethod(ResultSetProcessorUtil.class, METHOD_TOPAIRNULLIFALLNULL, ref("selectNewEvents"), ref("selectOldEvents"))); }
private static CodegenMethod generateGroupKeysJoinCodegen(ResultSetProcessorRowPerGroupRollupForge forge, CodegenClassScope classScope, CodegenInstanceAux instance) { CodegenMethod generateGroupKeySingle = generateGroupKeySingleCodegen(forge.getGroupKeyNodeExpressions(), classScope, instance); Consumer<CodegenMethod> code = methodNode -> { methodNode.getBlock().ifCondition(or(equalsNull(ref("events")), exprDotMethod(ref("events"), "isEmpty"))).blockReturn(constantNull()) .declareVar(Object[][].class, "result", newArrayByLength(Object[].class, exprDotMethod(ref("events"), "size"))) .declareVar(AggregationGroupByRollupLevel[].class, "levels", exprDotMethodChain(ref("this")).add("getGroupByRollupDesc").add("getLevels")) .declareVar(int.class, "count", constant(-1)); { CodegenBlock forLoop = methodNode.getBlock().forEach(MultiKey.class, "eventrow", ref("events")); forLoop.increment("count") .declareVar(EventBean[].class, "eventsPerStream", cast(EventBean[].class, exprDotMethod(ref("eventrow"), "getArray"))) .declareVar(Object.class, "groupKeyComplete", localMethod(generateGroupKeySingle, ref("eventsPerStream"), REF_ISNEWDATA)) .assignArrayElement("result", ref("count"), newArrayByLength(Object.class, arrayLength(ref("levels")))); { forLoop.forLoopIntSimple("j", arrayLength(ref("levels"))) .declareVar(Object.class, "subkey", exprDotMethod(arrayAtIndex(ref("levels"), ref("j")), "computeSubkey", ref("groupKeyComplete"))) .assignArrayElement2Dim("result", ref("count"), ref("j"), ref("subkey")) .exprDotMethod(arrayAtIndex(ref("eventPerKey"), exprDotMethod(arrayAtIndex(ref("levels"), ref("j")), "getLevelNumber")), "put", ref("subkey"), ref("eventsPerStream")); } } methodNode.getBlock().methodReturn(ref("result")); }; return instance.getMethods().addMethod(Object[][].class, "generateGroupKeysJoin", CodegenNamedParam.from(Set.class, "events", Map[].class, "eventPerKey", boolean.class, NAME_ISNEWDATA), ResultSetProcessorRowPerGroupRollupImpl.class, classScope, code); }
public static CodegenMethod getSelectJoinEventsHavingWithOrderByCodegen(CodegenClassScope classScope, CodegenInstanceAux instance) { Consumer<CodegenMethod> code = methodNode -> { methodNode.getBlock() .ifCondition(or(equalsNull(ref("events")), exprDotMethod(ref("events"), "isEmpty"))).blockReturn(constantNull()) .ifRefNullReturnNull("events") .declareVar(ArrayDeque.class, "result", constantNull()) .declareVar(ArrayDeque.class, "eventGenerators", constantNull()); { CodegenBlock forEach = methodNode.getBlock().forEach(MultiKey.class, "key", ref("events")); forEach.declareVar(EventBean[].class, NAME_EPS, cast(EventBean[].class, exprDotMethod(ref("key"), "getArray"))); forEach.ifCondition(not(localMethod(instance.getMethods().getMethod("evaluateHavingClause"), REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT))).blockContinue(); forEach.declareVar(EventBean.class, "resultEvent", exprDotMethod(REF_SELECTEXPRNONMEMBER, "process", REF_EPS, REF_ISNEWDATA, REF_ISSYNTHESIZE, REF_EXPREVALCONTEXT)) .ifCondition(notEqualsNull(ref("resultEvent"))) .ifCondition(equalsNull(ref("result"))) .assignRef("result", newInstance(ArrayDeque.class, exprDotMethod(ref("events"), "size"))) .assignRef("eventGenerators", newInstance(ArrayDeque.class, exprDotMethod(ref("events"), "size"))) .blockEnd() .exprDotMethod(ref("result"), "add", ref("resultEvent")) .exprDotMethod(ref("eventGenerators"), "add", ref("eventsPerStream")) .blockEnd(); } methodNode.getBlock().ifRefNullReturnNull("result") .declareVar(EventBean[].class, "arr", staticMethod(CollectionUtil.class, METHOD_TOARRAYEVENTS, ref("result"))) .declareVar(EventBean[][].class, "gen", staticMethod(CollectionUtil.class, METHOD_TOARRAYEVENTSARRAY, ref("eventGenerators"))) .methodReturn(exprDotMethod(REF_ORDERBYPROCESSOR, "sortPlain", ref("arr"), ref("gen"), REF_ISNEWDATA, REF_EXPREVALCONTEXT, REF_AGGREGATIONSVC)); }; return instance.getMethods().addMethod(EventBean[].class, "getSelectJoinEventsHavingWithOrderBy", CodegenNamedParam.from(AggregationService.class, REF_AGGREGATIONSVC.getRef(), SelectExprProcessor.class, NAME_SELECTEXPRPROCESSOR, OrderByProcessor.class, NAME_ORDERBYPROCESSOR, Set.class, "events", boolean.class, NAME_ISNEWDATA, boolean.class, NAME_ISSYNTHESIZE, ExprEvaluatorContext.class, NAME_EXPREVALCONTEXT), ResultSetProcessorUtil.class, classScope, code); }
ifShortcut.ifCondition(or(equalsNull(REF_OLDDATA), equalsIdentity(arrayLength(REF_OLDDATA), constant(0)))) .blockReturn(localMethod(processViewResultNewDepthOneUnbound, REF_NEWDATA, REF_ISSYNTHESIZE));