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


Java IFunction类代码示例

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


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

示例1: ALL

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Test
public void testQuery_子查询_all模式() throws SqlParserException {
    String sql = "SELECT * FROM TABLE1 WHERE ID > ALL (SELECT ID FROM TABLE2 WHERE TABLE2.NAME = TABLE1.NAME)";
    IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(sql, null, extraCmd, true);
    Assert.assertTrue(qc instanceof IMerge);

    IQuery query1 = (IQuery) ((IMerge) qc).getSubNodes().get(0);
    IQuery query2 = (IQuery) ((IMerge) qc).getSubNodes().get(1);

    IFunction subquery1 = (IFunction) query1.getSubqueryFilter().getArgs().get(1);
    IFunction subquery2 = (IFunction) query2.getSubqueryFilter().getArgs().get(1);
    Assert.assertTrue(subquery1 == subquery2);
    Assert.assertTrue(subquery1.getArgs().get(0) instanceof IQuery);
    IQuery merge = (IQuery) subquery1.getArgs().get(0);
    IFunction func = (IFunction) merge.getColumns().get(0);
    Assert.assertEquals("MAX", func.getFunctionName());
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:OptimizerTest.java

示例2: testDistinct

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

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

    IFunction f = ASTNodeFactory.getInstance().createFunction();
    f.setFunctionName("COUNT");
    f.setColumnName("COUNT(DISTINCT ID)");

    List args = new ArrayList();
    args.add(c);
    f.setArgs(args);
    qn.build();

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

示例3: 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

示例4: buildFunction

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
protected void buildFunction(IFunction f, boolean findInSelectList) {
    if (FunctionType.Aggregate == f.getFunctionType()) {
        setExistAggregate();
    }

    if (f.getArgs().size() == 0) {
        return;
    }

    List<Object> args = f.getArgs();
    for (int i = 0; i < args.size(); i++) {
        if (args.get(i) instanceof ISelectable) {
            args.set(i, this.buildSelectable((ISelectable) args.get(i), findInSelectList));
        } else if (args.get(i) instanceof ISequenceVal) {
            setExistSequenceVal();
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:QueryTreeNodeBuilder.java

示例5: constructColumnNameForFunction

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Override
public String constructColumnNameForFunction(IDataNodeExecutor query, boolean bindVal,
                                             AtomicInteger bindValSequence,
                                             Map<Integer, ParameterContext> paramMap, IFunction func,
                                             MysqlPlanVisitorImpl parentVisitor) {
    StringBuilder sb = new StringBuilder();

    sb.append("TRIM").append("(");

    if (func.getArgs().size() == 2) {
        sb.append(parentVisitor.getNewVisitor(func.getArgs().get(0)).getString());
    } else {
        sb.append(func.getArgs().get(2)).append(" ");
        sb.append(parentVisitor.getNewVisitor(func.getArgs().get(1)).getString());
        sb.append(" FROM ");
        sb.append(parentVisitor.getNewVisitor(func.getArgs().get(0)).getString());
    }

    sb.append(")");

    return sb.toString();

}
 
开发者ID:loye168,项目名称:tddl5,代码行数:24,代码来源:Trim.java

示例6: constructColumnNameForFunction

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Override
public String constructColumnNameForFunction(IDataNodeExecutor query, boolean bindVal,
                                             AtomicInteger bindValSequence,
                                             Map<Integer, ParameterContext> paramMap, IFunction func,
                                             MysqlPlanVisitorImpl parentVisitor) {
    StringBuilder sb = new StringBuilder();

    sb.append(parentVisitor.getNewVisitor(func.getArgs().get(0)).getString());

    Object right = func.getArgs().get(1);

    // 右边被提前计算过了,直接用not in
    if (right instanceof List) {
        sb.append(" not in ");
        sb.append(parentVisitor.getNewVisitor(func.getArgs().get(1)).getString());
    } else {
        // 右边没进行计算,还是个子查询,理论上不会发生
        sb.append(" != all (");
        sb.append(parentVisitor.getNewVisitor(func.getArgs().get(1)).getString());
        sb.append(")");
    }

    return sb.toString();

}
 
开发者ID:loye168,项目名称:tddl5,代码行数:26,代码来源:NotEqualAll.java

示例7: WHERE

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Test
public void testQuery_子查询_in模式() throws SqlParserException {
    String sql = "SELECT * FROM TABLE1 WHERE (ID > 10 OR ID < 5) OR  ID IN (SELECT ID FROM TABLE2 WHERE ID > 10 OR ID < 5)";
    QueryTreeNode qn = query(sql);
    FilterPreProcessor.optimize(qn, true, null);
    qn.build();

    IFunction func = SubQueryPreProcessor.findNextSubqueryOnFilter(qn);
    Assert.assertTrue(func != null);

    QueryTreeNode qtn = (QueryTreeNode) func.getArgs().get(0);
    Map<Long, Object> subquerySettings = new HashMap<Long, Object>();
    subquerySettings.put(qtn.getSubqueryOnFilterId(), Arrays.asList(1, 2));
    func = SubQueryPreProcessor.assignmentSubqueryOnFilter(qn, subquerySettings);
    FilterPreProcessor.optimize(qn, true, null);
    Assert.assertTrue(func == null);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:SubQueryPreProcessorTest.java

示例8: LENGTH

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Test
public void testQuery_函数别名() throws SqlParserException, QueryException {
    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:beebeandwer,项目名称:TDDL,代码行数:17,代码来源:SqlParserTest.java

示例9: copySelectables

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
public static List<ISelectable> copySelectables(List<ISelectable> selects, String tableName) {
    if (tableName == null) {
        return copySelectables(selects);
    }

    if (selects == null) {
        return null;
    }

    List<ISelectable> news = new ArrayList(selects.size());
    for (ISelectable s : selects) {
        ISelectable a = s.copy();
        if (a instanceof IColumn) {
            setColumn((IColumn) a, tableName);
        } else if (a instanceof IFilter) {
            setFilter((IFilter) a, tableName);
        } else if (a instanceof IFunction) {
            setFunction((IFunction) a, tableName);
        }

        news.add(a);
    }

    return news;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:26,代码来源:OptimizerUtils.java

示例10: getSelectableFromChild

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Override
public ISelectable getSelectableFromChild(ISelectable c) {
    // 如果存在表名,则进行强校验,比如字段为A.ID,否则直接进行ID名字匹配
    if (c.getTableName() != null && !c.getTableName().equals(this.getNode().getTableName())
        && !c.getTableName().equals(this.getNode().getAlias())) {
        return null;
    }

    if (IColumn.STAR.equals(c.getColumnName())) {
        return c;
    }

    if (c instanceof IFunction) {
        c.setTableName(this.getNode().getTableName());
        return c;
    }

    if (SchemaManager.DUAL.equals(getNode().getTableName())) {
        throw new TddlRuntimeException(ErrorCode.ERR_PARSER, "can't not visit column in dual");
    }
    return this.getSelectableFromChild(c.getColumnName());
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:23,代码来源:TableNodeBuilder.java

示例11: putRetColumnInMeta

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
void putRetColumnInMeta(ISelectable column, List<ColumnMeta> metaColumns) {
    String columnName;

    columnName = column.getColumnName();
    DataType type = null;

    // 函数在Map和Reduce过程中的返回类型可以不同
    // 如Avg,map过程返回String
    // reduce过程中返回数字类型
    if (this.isMerge()) {
        type = column.getDataType();
    } else {
        if (column instanceof IFunction) {
            type = ((IFunction) column).getExtraFunction().getMapReturnType();
        } else {
            type = column.getDataType();
        }
    }

    ColumnMeta cm = new ColumnMeta(ExecUtils.getLogicTableName(column.getTableName()),
        columnName,
        type,
        column.getAlias(),
        true);
    metaColumns.add(cm);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:27,代码来源:AggregateCursor.java

示例12: testFunction1

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
@Test
public void testFunction1() throws SqlParserException, QueryException {
    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:beebeandwer,项目名称:TDDL,代码行数:20,代码来源:SqlParserTest.java

示例13: 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

示例14: replaceAliasInFilter

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
private void replaceAliasInFilter(Object filter, String alias) {
    if (filter instanceof IFunction) {
        for (Object sub : ((IFunction) filter).getArgs()) {
            this.replaceAliasInFilter(sub, alias);
        }
    }

    if (filter instanceof ISelectable) {
        if (alias != null) {
            ((ISelectable) filter).setTableName(alias);
        }

        if (((ISelectable) filter).getAlias() != null) {
            ((ISelectable) filter).setColumnName(((ISelectable) filter).getAlias());
            ((ISelectable) filter).setAlias(null);
        }
    }

}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:20,代码来源:MergeNodeBuilder.java

示例15: executeAgg

import com.taobao.tddl.optimizer.core.expression.IFunction; //导入依赖的package包/类
protected ISchematicCursor executeAgg(ISchematicCursor cursor, IDataNodeExecutor executor,
                                      boolean closeResultCursor, IRepository repo, List<IFunction> aggregates,
                                      List<IOrderBy> groupBycols, ExecutionContext executionContext)
                                                                                                    throws TddlException {
    List<ISelectable> _retColumns = null;
    if (executor instanceof IQuery) {
        _retColumns = ((IQuery) executor).getColumns();
    } else if (executor instanceof IJoin) {
        _retColumns = ((IJoin) executor).getColumns();
    } else if (executor instanceof IMerge) {
        _retColumns = ((IMerge) executor).getColumns();
    }

    if (_retColumns != null) {
        if ((aggregates != null && !aggregates.isEmpty()) || (groupBycols != null && !groupBycols.isEmpty())) {
            cursor = repo.getCursorFactory().aggregateCursor(executionContext,
                cursor,
                aggregates,
                groupBycols,
                _retColumns,
                false);
        }
    }
    return cursor;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:26,代码来源:QueryHandlerCommon.java


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