Search in sources :

Example 1 with IBlockToString

use of com.qlangtech.tis.sql.parser.visitor.IBlockToString in project tis by qlangtech.

the class StreamComponentCodeGeneratorFlink method generateCreateGroupResultScript.

private void generateCreateGroupResultScript(FuncFormat rr, final PropGetter propGetter, TisGroupBy groups) {
    if (propGetter.isLastFunctInChain()) {
        rr.startLine("var result:Any = null");
    }
    final AtomicBoolean hasBreak = new AtomicBoolean();
    rr.startLine(new IBlockToString() {

        public String toString() {
            return hasBreak.get() ? "breakable {" : StringUtils.EMPTY;
        }
    });
    rr.methodBody("for ((k:GroupKey, v:GroupValues)  <- " + groups.getGroupAggrgationName() + ")", (r) -> {
        final PropGetter pgetter = propGetter;
        if (propGetter.isLastFunctInChain()) {
            rr.startLine("result = ");
            hasBreak.set(true);
            propGetter.getGroovyScript(rr, true);
            rr.startLine("break");
            rr.returnLine();
        } else {
            PropGetter prev = propGetter.getPrev();
            while (prev != null) {
                if (prev.getTupleCreator() instanceof FunctionDataTupleCreator) {
                    break;
                }
                prev = prev.getPrev();
            }
            boolean shallCallableProcess = (prev != null && prev.shallCallableProcess());
            if (shallCallableProcess) {
                rr.startLine("putMediaResult(\"" + pgetter.getOutputColName().getAliasName() + "\", //");
            } else {
                rr.startLine("v.putMediaData( // \n");
                rr.startLine("\"").append(propGetter.getOutputColName().getAliasName()).append("\" // \n");
                rr.startLine(", //\n");
            }
            // );
            propGetter.getGroovyScript(rr, true);
            if (shallCallableProcess) {
                rr.startLine(") // end putMediaResult");
                hasBreak.set(true);
                rr.startLine("break");
            } else {
                rr.startLine(") // end putMediaData\n");
            }
        }
    });
    rr.startLine(new IBlockToString() {

        public String toString() {
            return hasBreak.get() ? "} //end breakable" : StringUtils.EMPTY;
        }
    });
    if (propGetter.isLastFunctInChain()) {
        rr.startLine(" result //return");
    }
    rr.returnLine();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IBlockToString(com.qlangtech.tis.sql.parser.visitor.IBlockToString) FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator) PropGetter(com.qlangtech.tis.sql.parser.tuple.creator.impl.PropGetter) IBlockToString(com.qlangtech.tis.sql.parser.visitor.IBlockToString)

Example 2 with IBlockToString

use of com.qlangtech.tis.sql.parser.visitor.IBlockToString in project tis by qlangtech.

the class StreamComponentCodeGenerator method generateFunctionCallScript.

private void generateFunctionCallScript(FuncFormat rr, final PropGetter propGetter) {
    rr.startLine("//===================================");
    final AtomicBoolean isFirstReturn = new AtomicBoolean(true);
    final IBlockToString returnVal = new IBlockToString() {

        @Override
        public String toString() {
            // return isFirstReturn.get() ? "return " : StringUtils.EMPTY;
            return StringUtils.EMPTY;
        }
    };
    try {
        if (propGetter.isLastFunctInChain()) {
            rr.startLine(returnVal);
        } else {
            rr.startLine("putMediaResult(\"" + propGetter.getOutputColName().getAliasName() + "\", //");
            propGetter.getGroovyScript(rr, false);
            rr.startLine(")");
            return;
        }
        // 既要是最后一个Func节点 且 要是多源节点
        if (propGetter.shallCallableProcess()) {
            propGetter.getGroovyScript(rr, false);
        } else {
            if (propGetter.isLastFunctInChain() && !propGetter.isGroupByFunction() && propGetter.isNextGroupByFunction()) {
                isFirstReturn.set(false);
                final PropGetter nextGroup = propGetter.getNextGroupByPropGetter();
                if (nextGroup == null) {
                    throw new IllegalStateException("NextGroupByPropGetter can not be null");
                }
                rr.startLine("var result:Any = null");
                rr.startLine("breakable {");
                rr.methodBody("for((k:GroupKey, v:GroupValues) <- " + nextGroup.getFunctionDataTuple().getGroupBy().get().getGroupAggrgationName() + ")", (r) -> {
                    r.append("result = ");
                    propGetter.getGroovyScript(r, true);
                    rr.startLine("break");
                });
                rr.startLine(" }");
                rr.startLine("result");
            } else {
                propGetter.getGroovyScript(rr, false);
            }
        }
    } finally {
        rr.startLine("//===================================");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IBlockToString(com.qlangtech.tis.sql.parser.visitor.IBlockToString) PropGetter(com.qlangtech.tis.sql.parser.tuple.creator.impl.PropGetter)

Example 3 with IBlockToString

use of com.qlangtech.tis.sql.parser.visitor.IBlockToString in project tis by qlangtech.

the class StreamComponentCodeGenerator method generateCreateGroupResultScript.

private void generateCreateGroupResultScript(FuncFormat rr, final PropGetter propGetter, TisGroupBy groups) {
    if (propGetter.isLastFunctInChain()) {
        rr.startLine("var result:Any = null");
    }
    final AtomicBoolean hasBreak = new AtomicBoolean();
    rr.startLine(new IBlockToString() {

        public String toString() {
            return hasBreak.get() ? "breakable {" : StringUtils.EMPTY;
        }
    });
    rr.methodBody("for ((k:GroupKey, v:GroupValues)  <- " + groups.getGroupAggrgationName() + ")", (r) -> {
        final PropGetter pgetter = propGetter;
        if (propGetter.isLastFunctInChain()) {
            rr.startLine("result = ");
            hasBreak.set(true);
            propGetter.getGroovyScript(rr, true);
            rr.startLine("break");
            rr.returnLine();
        } else {
            PropGetter prev = propGetter.getPrev();
            while (prev != null) {
                if (prev.getTupleCreator() instanceof FunctionDataTupleCreator) {
                    break;
                }
                prev = prev.getPrev();
            }
            boolean shallCallableProcess = (prev != null && prev.shallCallableProcess());
            if (shallCallableProcess) {
                rr.startLine("putMediaResult(\"" + pgetter.getOutputColName().getAliasName() + "\", //");
            } else {
                rr.startLine("v.putMediaData( // \n");
                rr.startLine("\"").append(propGetter.getOutputColName().getAliasName()).append("\" // \n");
                rr.startLine(", //\n");
            }
            // );
            propGetter.getGroovyScript(rr, true);
            if (shallCallableProcess) {
                rr.startLine(") // end putMediaResult");
                hasBreak.set(true);
                rr.startLine("break");
            } else {
                rr.startLine(") // end putMediaData\n");
            }
        }
    });
    rr.startLine(new IBlockToString() {

        public String toString() {
            return hasBreak.get() ? "} //end breakable" : StringUtils.EMPTY;
        }
    });
    if (propGetter.isLastFunctInChain()) {
        rr.startLine(" result //return");
    }
    rr.returnLine();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IBlockToString(com.qlangtech.tis.sql.parser.visitor.IBlockToString) FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator) PropGetter(com.qlangtech.tis.sql.parser.tuple.creator.impl.PropGetter) IBlockToString(com.qlangtech.tis.sql.parser.visitor.IBlockToString)

Aggregations

PropGetter (com.qlangtech.tis.sql.parser.tuple.creator.impl.PropGetter)3 IBlockToString (com.qlangtech.tis.sql.parser.visitor.IBlockToString)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 FunctionDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator)2