当前位置: 首页>>代码示例>>Java>>正文


Java IFunction.setColumnName方法代码示例

本文整理汇总了Java中com.taobao.tddl.optimizer.core.expression.IFunction.setColumnName方法的典型用法代码示例。如果您正苦于以下问题:Java IFunction.setColumnName方法的具体用法?Java IFunction.setColumnName怎么用?Java IFunction.setColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.taobao.tddl.optimizer.core.expression.IFunction的用法示例。


在下文中一共展示了IFunction.setColumnName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildRowFunction

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
private IFunction buildRowFunction(Collection values, boolean isColumn, CloneableRecord record) {
    IFunction func = ASTNodeFactory.getInstance().createFunction();
    func.setFunctionName("ROW");
    StringBuilder columnName = new StringBuilder();
    columnName.append('(').append(StringUtils.join(values, ',')).append(')');
    func.setColumnName(columnName.toString());
    if (isColumn) {
        List<IColumn> columns = new ArrayList<IColumn>(values.size());
        for (Object value : values) {
            IColumn col = ASTNodeFactory.getInstance()
                .createColumn()
                .setColumnName((String) value)
                .setDataType(record.getType((String) value));
            columns.add(col);
        }

        func.setArgs(columns);
    } else {
        func.setArgs(new ArrayList(values));
    }
    return func;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:23,代码来源:BlockNestedtLoopCursor.java

示例2: COUNT

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testQuery_orderBy加函数() throws Exception {
    String sql = "SELECT * FROM TABLE1 WHERE ID=1 ORDER BY COUNT(ID)";
    QueryTreeNode qn = query(sql);
    qn.build();

    TableNode table1 = new TableNode("TABLE1");
    IColumn c = ASTNodeFactory.getInstance().createColumn();
    c.setColumnName("ID");

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("COUNT");
    List args = new ArrayList();
    args.add(c);

    f.setArgs(args);

    f.setColumnName("COUNT(ID)");
    QueryTreeNode qnExpected = table1.query("ID=1").orderBy(f, true);
    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:23,代码来源:SqlParserTest.java

示例3: testFunction_noArgs

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction_noArgs() throws Exception {
    String sql = "SELECT * FROM TABLE1 T1 WHERE ID = NOW()";
    QueryTreeNode qn = query(sql);
    qn.build();
    TableNode table1 = new TableNode("TABLE1");

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("NOW");
    f.setColumnName("NOW()");

    IColumn c = ASTNodeFactory.getInstance().createColumn();
    c.setColumnName("ID");

    IFilter filter = ASTNodeFactory.getInstance().createBooleanFilter();
    filter.setOperation(OPERATION.EQ);
    ((IBooleanFilter) filter).setColumn(c);
    ((IBooleanFilter) filter).setValue(f);

    QueryTreeNode qnExpected = table1.alias("T1").query(filter);
    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:24,代码来源:SqlParserTest.java

示例4: handleArithmetric

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
private void handleArithmetric(BinaryOperatorExpression expr, String functionName) {
    IFunction func = ASTNodeFactory.getInstance().createFunction();
    func.setFunctionName(functionName);

    List<Object> args = new ArrayList<Object>(2);
    MySqlExprVisitor leftevi = new MySqlExprVisitor(parent);
    expr.getLeftOprand().accept(leftevi);
    args.add(leftevi.getColumnOrValue());

    MySqlExprVisitor rightevi = new MySqlExprVisitor(parent);
    expr.getRightOprand().accept(rightevi);
    args.add(rightevi.getColumnOrValue());

    func.setArgs(args); // 设置参数
    func.setColumnName(getSqlExprStr(expr));
    this.columnOrValue = func;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:MySqlExprVisitor.java

示例5: handleArithmetric

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
private void handleArithmetric(BinaryOperatorExpression expr, String functionName) {
    IFunction func = ASTNodeFactory.getInstance().createFunction();
    func.setFunctionName(functionName);

    List<Object> args = new ArrayList<Object>(2);
    MySqlExprVisitor leftevi = new MySqlExprVisitor();
    expr.getLeftOprand().accept(leftevi);
    args.add(leftevi.getColumnOrValue());

    MySqlExprVisitor rightevi = new MySqlExprVisitor();
    expr.getRightOprand().accept(rightevi);
    args.add(rightevi.getColumnOrValue());

    func.setArgs(args); // 设置参数
    func.setColumnName(getSqlExprStr(expr));
    this.columnOrValue = func;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:18,代码来源:MySqlExprVisitor.java

示例6: LENGTH

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testQuery_函数别名() throws SqlParserException {
    String sql = "SELECT T.ID , LENGTH(NAME) AS LEN FROM TABLE1 T  WHERE ID=1";
    QueryTreeNode qn = query(sql);
    qn.build();

    IFunction function = ASTNodeFactory.getInstance().createFunction();
    function.setColumnName("LENGTH(NAME)");
    function.setAlias("LEN");
    function.setFunctionName("LENGTH");

    QueryTreeNode qnExpected = new TableNode("TABLE1").alias("T").select("T.ID").query("ID=1");
    qnExpected.addColumnsSelected(function);
    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:17,代码来源:SqlParserTest.java

示例7: testFunction

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction() throws SqlParserException {
    String sql = "SELECT COUNT(*) FROM TABLE1 T1 WHERE ID = 1";
    QueryTreeNode qn = query(sql);
    qn.build();

    TableNode table1 = new TableNode("TABLE1");
    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("COUNT");
    IColumn c = ASTNodeFactory.getInstance().createColumn();
    c.setColumnName("*");

    List args = new ArrayList();
    args.add(c);

    f.setArgs(args);
    f.setTableName("TABLE1");
    f.setColumnName("COUNT(*)");
    QueryTreeNode qnExpected = table1.alias("T1").query("ID=1").select(f);
    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:23,代码来源:SqlParserTest.java

示例8: testFunction1

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction1() throws SqlParserException {
    String sql = "SELECT COUNT(ID) FROM TABLE1 T1 WHERE ID = 1";
    QueryTreeNode qn = query(sql);

    TableNode table1 = new TableNode("TABLE1");

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("COUNT");
    f.setColumnName("COUNT(ID)");
    IColumn c = ASTNodeFactory.getInstance().createColumn();
    c.setColumnName("ID");

    List args = new ArrayList();
    args.add(c);
    f.setArgs(args);
    QueryTreeNode qnExpected = table1.alias("T1").query("ID=1").select(f);
    assertEquals(qn, qnExpected);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:20,代码来源:SqlParserTest.java

示例9: visit

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public void visit(UnaryOperatorExpression node) {
    if (eval(node)) { // 计算出了结果
        return;
    }

    if (node instanceof BitInvertExpression) {
    } else if (node instanceof CastBinaryExpression) {
    } else if (node instanceof LogicalNotExpression) {
    } else if (node instanceof MinusExpression) {
    } else if (node instanceof NegativeValueExpression) {
        throw new NotSupportException("not support NegativeValueExpression");
    } else if (node instanceof SubqueryAllExpression) {
        throw new NotSupportException("not support SubqueryAllExpression");
    } else if (node instanceof SubqueryAnyExpression) {
        throw new NotSupportException("not support SubqueryAnyExpression");
    } else {
        throw new NotSupportException("not supported this UnaryOperatorExpression type " + node.getOperator());
    }

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    if (node instanceof MinusExpression) {
        f.setFunctionName(IFunction.BuiltInFunction.MINUS);
    } else {
        f.setFunctionName(node.getOperator());
    }
    MySqlExprVisitor ev = new MySqlExprVisitor();
    node.getOperand().accept(ev);
    Object arg = ev.getColumnOrValue();
    List args = new ArrayList(1);
    args.add(arg);
    f.setArgs(args);
    f.setColumnName(this.getSqlExprStr(node));
    columnOrValue = f;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:36,代码来源:MySqlExprVisitor.java

示例10: testFunction_twoArgs

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction_twoArgs() throws Exception {
    String sql = "SELECT * FROM TABLE1 T1 WHERE IFNULL(STR_TO_DATE(ID, '%d,%m,%y'),1) = '1'";
    QueryTreeNode qn = query(sql);
    qn.build();

    TableNode table1 = new TableNode("TABLE1");

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("STR_TO_DATE");

    IFunction f2 = ASTNodeFactory.getInstance().createFunction();
    f2.setFunctionName("IFNULL");
    f2.setColumnName("IFNULL(STR_TO_DATE(ID, '%d,%m,%y'), 1)");
    IColumn c = ASTNodeFactory.getInstance().createColumn();
    c.setColumnName("ID");

    List args = new ArrayList();
    args.add(c);
    args.add("%d,%m,%y");
    f.setArgs(args);

    f.setColumnName("STR_TO_DATE(id, '%d,%m,%Y')");
    args = new ArrayList();
    args.add(f);
    args.add(1);

    f2.setArgs(args);
    IFilter filter = ASTNodeFactory.getInstance().createBooleanFilter();
    filter.setOperation(OPERATION.EQ);
    ((IBooleanFilter) filter).setColumn(f2);
    ((IBooleanFilter) filter).setValue('1');

    QueryTreeNode qnExpected = table1.alias("T1").query(filter);
    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:38,代码来源:SqlParserTest.java

示例11: visit

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public void visit(Timestampadd node) {
    boolean argDistinct = isDistinct(node);
    IFunction ifunc = ASTNodeFactory.getInstance().createFunction();
    ifunc.setFunctionName(node.getFunctionName());
    List<Expression> expressions = node.getArguments();
    ArrayList<Object> args = new ArrayList<Object>();

    args.add(node.getUnit().toString());
    if (expressions != null) {
        for (Expression expr : expressions) {
            MySqlExprVisitor v = new MySqlExprVisitor(parent);
            expr.accept(v);
            Object cv = v.getColumnOrValue();
            if ((cv instanceof ISelectable)) {
                ((ISelectable) cv).setDistinct(argDistinct);
            }
            args.add(v.getColumnOrValue());
        }
        ifunc.setArgs(args);
    } else {
        ifunc.setArgs(new ArrayList());
    }

    ifunc.setColumnName(getSqlExprStr(node));
    columnOrValue = ifunc;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:28,代码来源:MySqlExprVisitor.java

示例12: testFunction_to_char

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction_to_char() throws Exception {
    String sql = "SELECT * FROM TABLE1 T1 WHERE DATE_ADD(ID, INTERVAL 1 SECOND)= '2012-11-11'";
    QueryTreeNode qn = query(sql);
    qn.build();

    TableNode table1 = new TableNode("TABLE1");

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("DATE_ADD");

    IColumn c = ASTNodeFactory.getInstance().createColumn();
    c.setColumnName("ID");
    List args = new ArrayList();
    args.add(c);
    args.add("INTERVAL 1 SECOND");
    f.setArgs(args);

    f.setColumnName("DATE_ADD(ID, INTERVAL 1 SECOND)");
    IFilter filter = ASTNodeFactory.getInstance().createBooleanFilter();
    filter.setOperation(OPERATION.EQ);
    ((IBooleanFilter) filter).setColumn(f);
    ((IBooleanFilter) filter).setValue("2012-11-11");

    QueryTreeNode qnExpected = table1.alias("T1").query(filter);
    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:29,代码来源:SqlParserTest.java

示例13: query

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testQuery_普通链接_函数() throws SqlParserException {
    String sql = "SELECT A.ID as AID,A.ID,COUNT(A.ID),COUNT(*) FROM TABLE1 A INNER JOIN TABLE2 B ON A.ID=B.ID AND A.NAME = B.NAME WHERE A.NAME=1";
    sql += " GROUP BY AID HAVING AID > 0 ORDER BY A.ID ASC ";
    QueryTreeNode qn = query(sql);
    qn.build();

    TableNode table1 = new TableNode("TABLE1");
    TableNode table2 = new TableNode("TABLE2");
    QueryTreeNode qnExpected = table1.alias("A")
        .join(table2.alias("B"))
        .addJoinKeys("A.ID", "B.ID")
        .addJoinKeys("A.NAME", "B.NAME")
        .query("A.NAME=1")
        .select("A.ID AS AID,A.ID")
        .groupBy("AID")
        .having("AID > 0")
        .orderBy("A.ID", true);
    IFunction function1 = ASTNodeFactory.getInstance().createFunction();
    function1.setColumnName("COUNT(A.ID)");
    function1.setFunctionName("COUNT");

    IFunction function2 = ASTNodeFactory.getInstance().createFunction();
    function2.setColumnName("COUNT(*)");
    function2.setFunctionName("COUNT");
    qnExpected.addColumnsSelected(function1);
    qnExpected.addColumnsSelected(function2);

    qnExpected.build();
    assertEquals(qn, qnExpected);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:32,代码来源:SqlParserTest.java

示例14: expendAvgFunction

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
/**
 * 将Avg函数展开为sum/count
 */
private void expendAvgFunction(IDataNodeExecutor sub) {
    if (sub instanceof IQuery || sub instanceof IJoin) {
        List<ISelectable> add = new ArrayList();
        List<ISelectable> remove = new ArrayList();
        for (Object sel : ((IQueryTree) sub).getColumns()) {
            ISelectable s = (ISelectable) sel;
            if (s instanceof IFunction) {
                if (s.getColumnName().startsWith("AVG(")) {
                    IFunction sum = (IFunction) s.copy();
                    sum.setExtraFunction(null);
                    sum.setFunctionName("SUM");
                    sum.setColumnName(s.getColumnName().replace("AVG(", "SUM("));
                    if (sum.getAlias() != null) {
                        sum.setAlias(sum.getAlias() + "1");// 加个后缀1
                    }

                    IFunction count = (IFunction) s.copy();
                    count.setExtraFunction(null);
                    count.setFunctionName("COUNT");
                    count.setColumnName(s.getColumnName().replace("AVG(", "COUNT("));
                    if (count.getAlias() != null) {
                        count.setAlias(count.getAlias() + "2");// 加个后缀2
                    }

                    add.add(count);
                    add.add(sum);

                    remove.add(s);
                } else {
                    // 删除底下AVG的相关函数,比如 1 + AVG(ID)
                    // 目前这个只能上层来进行计算
                    // 可能的风险:还未支持的Function计算
                    if (FunctionType.Scalar.equals(((IFunction) s).getFunctionType())
                        && hasArgsAvgFunction((IFunction) s)) {
                        remove.add(s);
                    }
                }
            }
        }

        if (!remove.isEmpty()) {
            ((IQueryTree) sub).getColumns().removeAll(remove);
            ((IQueryTree) sub).getColumns().addAll(add);
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:50,代码来源:FuckAvgOptimizer.java


注:本文中的com.taobao.tddl.optimizer.core.expression.IFunction.setColumnName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。