Search in sources :

Example 1 with ColName

use of com.qlangtech.tis.sql.parser.ColName in project tis by qlangtech.

the class StreamTransformVisitor method processIdentifier.

private void processIdentifier(Identifier express, ColRef colRef) {
    ColName colName;
    colName = new ColName(express.getValue());
    colRef.getColRefMap().put(colName, createTableTupleCreator(null, colRef));
}
Also used : ColName(com.qlangtech.tis.sql.parser.ColName)

Example 2 with ColName

use of com.qlangtech.tis.sql.parser.ColName in project tis by qlangtech.

the class StreamTransformVisitor method visitSelect.

@Override
protected NodeProcessResult<?> visitSelect(Select node, StackableAstVisitorContext<Integer> context) {
    context.processSelect = true;
    try {
        SingleColumn single = null;
        Expression express = null;
        DereferenceExpression dref = null;
        ColName colName = null;
        ColRef colRef = new ColRef();
        // Map<ColName /* colName */, IDataTupleCreator> colRefMap = Maps.newHashMap();
        // Map<String/* ref */, IDataTupleCreator> baseRefMap = Maps.newHashMap();
        NodeProcessResult<ColRef> result = new NodeProcessResult<ColRef>(colRef);
        IDataTupleCreator tupleCreator = null;
        for (SelectItem item : node.getSelectItems()) {
            if (item instanceof SingleColumn) {
                single = (SingleColumn) item;
                express = single.getExpression();
                if (express instanceof DereferenceExpression) {
                    dref = ((DereferenceExpression) express);
                    if (dref.getBase() instanceof Identifier) {
                        if (single.getAlias().isPresent()) {
                            colName = new ColName(dref.getField().getValue(), single.getAlias().get().getValue());
                        } else {
                            colName = new ColName(dref.getField().getValue());
                        }
                        tupleCreator = createTableTupleCreator(dref, colRef);
                        colRef.getColRefMap().put(colName, tupleCreator);
                    } else {
                        // this.process(dref.getBase(), context);
                        faild(dref.getBase());
                    }
                } else {
                    if (single.getAlias().isPresent()) {
                        String name = single.getAlias().get().getValue();
                        colName = new ColName(name);
                        if (express instanceof SearchedCaseExpression) {
                            colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
                            continue;
                        } else if (express instanceof CoalesceExpression) {
                            // COALESCE(a2.has_fetch, 0)
                            colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
                            continue;
                        } else if (express instanceof FunctionCall) {
                            // "concat_ws"(',', "collect_set"("split"(i.batch_msg, '[\\w\\W]*\\|')[1]))
                            colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
                            continue;
                        } else if (express instanceof SubscriptExpression) {
                            // "split"(i.batch_msg, '[\\w\\W]*\\|')[1]
                            colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
                            continue;
                        } else if (express instanceof Identifier) {
                            processIdentifier((Identifier) express, colRef);
                            continue;
                        } else if (express instanceof StringLiteral) {
                            /**
                             *                                 select 中存在以下使用常量作为列字段
                             *                                 SELECT
                             *                                 '' as num_unit_id,
                             *                                 '' as num_unit_name
                             *                                 FROM goods
                             */
                            colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
                            continue;
                        } else if (express instanceof IfExpression) {
                            /**
                             * IF((COALESCE("instr"(sl.logo_url, 'http'), 0) > 0), sl.logo_url, "concat"('http://', sl.logo_url))
                             */
                            colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
                            continue;
                        }
                        faild(express);
                    } else if (express instanceof Identifier) {
                        // 没有设置表应用,select里面的表应该只有一个
                        // 这种情况下from中只有一个原表
                        processIdentifier((Identifier) express, colRef);
                        continue;
                    }
                    faild(express);
                // process(express, context);
                // IDataTupleCreator tupleCreator = new IDataTupleCreator() {
                // 
                // @Override
                // public Object getVal(String name) {
                // return null;
                // }
                // };
                // 
                // ValueOperator.createGatherValueOperator(new
                // ColName(single.getAlias().get().getValue()),
                // express, params);
                }
            // single.getAlias();
            } else {
                throw new IllegalStateException("item type:" + item.getClass() + "" + item);
            }
        // visitSelectItem(item, context);
        }
        // System.out.println(MoreObjects.toStringHelper(colRefMap).add);
        return result;
    // return new NodeProcessResult<Map<ColName /* colName */, String /* base */
    // >>(colRefMap);
    } finally {
        context.processSelect = false;
    }
// return super.visitSelect(node, context);
}
Also used : FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator) ColName(com.qlangtech.tis.sql.parser.ColName) ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) NodeProcessResult(com.qlangtech.tis.sql.parser.NodeProcessResult) IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator)

Example 3 with ColName

use of com.qlangtech.tis.sql.parser.ColName in project tis by qlangtech.

the class TaskNodeTraversesCreatorVisitor method visit.

@Override
public void visit(FunctionDataTupleCreator function) {
    PropGetter peek = getPeek();
    if (peek == null) {
        throw new IllegalStateException("peek can not be null");
    }
    function.getParams().entrySet().stream().forEach((r) -> /**
     * Map<ColName, IDataTupleCreator>
     */
    {
        // function
        // function
        this.pushPropGetter(// function
        new ColName(r.getKey().getName(), peek.getOutputColName().getAliasName()), peek.getTupleCreator().getEntityName(), r.getValue());
        try {
            r.getValue().accept(TaskNodeTraversesCreatorVisitor.this);
        } finally {
            propStack.pop();
        }
    });
}
Also used : ColName(com.qlangtech.tis.sql.parser.ColName)

Example 4 with ColName

use of com.qlangtech.tis.sql.parser.ColName in project tis by qlangtech.

the class FunctionVisitor method visitDereferenceExpression.

@Override
protected Void visitDereferenceExpression(DereferenceExpression node, Void context) {
    ColName col = new ColName(node.getField().getValue());
    IDataTupleCreator tupleCreator = StreamTransformVisitor.createTableTupleCreator(node, this.colRef);
    this.functionParams.put(col, tupleCreator);
    boolean isAggregateNumerica = this.isAggregateNumerica();
    boolean isAggregateFunc = this.isAggregateFunc();
    // =============================================
    if (isAggregateNumerica) {
    // this.funcFormat.append("Double.parseDouble(");
    }
    if (generateContext.isJoinPoint()) {
        this.processJoinPointPram(col);
        if (!this.operatorResultTypeStack.isEmpty()) {
            OperatorResultTypeEnum opResultTypeEnum = this.operatorResultTypeStack.peek();
        // TODO: 暂时先注释掉
        // this.funcFormat.append("(").append(opResultTypeEnum.getLiteria()).append(")");
        }
        this.funcFormat.append("getMediaResult(\"" + col.getName() + "\",row)");
    } else {
        if (generateContext.isNextGroupByFunction() && !generateContext.isGroupByFunction()) {
            this.funcFormat.startLine("v.getMediaProp(\"" + col.getName() + "\")");
        } else if (this.processAggregationResult && !isAggregateFunc) {
            this.funcFormat.append("k.getKeyVal(\"").append(col.getName()).append("\")");
        } else {
            this.funcFormat.append(isAggregateFunc ? "r" : ROW_KEY);
            this.funcFormat.append(".getColumn(\"").append(col.getName()).append("\")");
        }
    }
    if (isAggregateNumerica) {
    // this.funcFormat.append(")");
    }
    // =============================================
    return null;
}
Also used : IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator) ColName(com.qlangtech.tis.sql.parser.ColName)

Aggregations

ColName (com.qlangtech.tis.sql.parser.ColName)4 IDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator)2 NodeProcessResult (com.qlangtech.tis.sql.parser.NodeProcessResult)1 ColRef (com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef)1 FunctionDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator)1