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


Java ISelectable.setAlias方法代码示例

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


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

示例1: getColumnsSelectedForParent

import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
 * 列的tablename会设为表别名
 * 
 * @return
 */
public List<ISelectable> getColumnsSelectedForParent() {
    List<ISelectable> res = new ArrayList<ISelectable>(this.getColumnsSelected().size());
    for (ISelectable s : this.getColumnsSelected()) {
        ISelectable a = s.copy();
        if (this.getAlias() != null) {
            a.setTableName(this.getAlias());
        }

        if (s.getAlias() != null) {
            a.setColumnName(s.getAlias()); // 设置为alias name
            a.setAlias(null);
        }
        res.add(a);
    }
    return res;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:22,代码来源:QueryTreeNode.java

示例2: getColumnsReferedForParent

import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
 * 列的tablename会设为表别名
 * 
 * @return
 */
public List<ISelectable> getColumnsReferedForParent() {
    if (this.getAlias() == null) {
        return this.getColumnsRefered();
    } else {
        List<ISelectable> res = new ArrayList<ISelectable>(this.getColumnsRefered().size());
        for (ISelectable s : this.getColumnsRefered()) {
            ISelectable a = s.copy();
            if (this.getAlias() != null) {
                a.setTableName(this.getAlias());
            }

            if (s.getAlias() != null) {
                a.setColumnName(s.getAlias()); // 设置为alias name
                a.setAlias(null);
            }
            res.add(a);
        }
        return res;
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:26,代码来源:QueryTreeNode.java

示例3: createColumnFromString

import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
 * 根据column string构造{@linkplain ISelectable}对象
 * 
 * @param columnStr
 * @return
 */
public static ISelectable createColumnFromString(String columnStr) {
    if (columnStr == null) {
        return null;
    }

    // 别名只能单独处理
    if (TStringUtil.containsIgnoreCase(columnStr, " AS ")) {
        String tmp[] = TStringUtil.splitByWholeSeparator(columnStr, " AS ");
        if (tmp.length != 2) {
            throw new RuntimeException("createColumnFromString:" + columnStr);
        }

        ISelectable c = createColumnFromString(tmp[0].trim());
        c.setAlias(tmp[1].trim());
        return c;
    } else {
        MySqlExprVisitor visitor = MySqlExprVisitor.parser(columnStr);
        Object value = MySqlExprVisitor.parser(columnStr).getColumnOrValue();
        if (value instanceof ISelectable) {
            return (ISelectable) value;
        } else if (value instanceof IFilter) {
            return (IFilter) value;
        } else { // 可能是常量
            return visitor.buildConstanctFilter(value);
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:34,代码来源:OptimizerUtils.java

示例4: buildSelectable

import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
public ISelectable buildSelectable(ISelectable c) {
    if (c == null) {
        return null;
    }

    ISelectable column = null;
    ISelectable columnFromMeta = null;

    if (column == null) {// 查找table meta
        columnFromMeta = this.getSelectableFromChild(c);

        if (columnFromMeta != null) {
            column = columnFromMeta;
            // 直接从子类的table定义中获取表字段,然后根据当前column状态,设置alias和distinct
            column.setAlias(c.getAlias());
            column.setDistinct(c.isDistinct());
        }
    }

    if (column instanceof IFunction) {

        buildFunction((IFunction) column);

    }

    return column;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:28,代码来源:BaseShowNode.java

示例5: createColumnFromString

import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
 * 根据column string构造{@linkplain ISelectable}对象
 * 
 * @param columnStr
 * @return
 */
public static ISelectable createColumnFromString(String columnStr) {
    if (columnStr == null) {
        return null;
    }

    // 别名只能单独处理
    if (TStringUtil.containsIgnoreCase(columnStr, " AS ")) {
        String tmp[] = TStringUtil.splitByWholeSeparator(columnStr, " AS ");
        if (tmp.length != 2) {
            throw new RuntimeException("createColumnFromString:" + columnStr);
        }

        ISelectable c = createColumnFromString(tmp[0].trim());
        c.setAlias(tmp[1].trim());
        return c;
    } else {
        MySqlExprVisitor visitor = MySqlExprVisitor.parser(columnStr);
        Comparable value = MySqlExprVisitor.parser(columnStr).getColumnOrValue();
        if (value instanceof ISelectable) {
            return (ISelectable) value;
        } else if (value instanceof IFilter) {
            return (IFilter) value;
        } else { // 可能是常量
            return visitor.buildConstanctFilter(value);
        }
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:34,代码来源:OptimizerUtils.java

示例6: buildSelectable

import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
 * 用于标记当前节点是否需要根据meta信息填充信息
 * 
 * <pre>
 * SQL. 
 *  a. select id + 2 as id , id from test where id = 2 having id = 4;
 *  b. select id + 2 as id , id from test where id = 2 order by count(id)
 * 
 * 解释:
 * 1.  COLUMN/WHERE/JOIN中列,是取自FROM的表字段
 * 2.  HAVING/ORDER BY/GROUP BY中的列,是取自SELECT中返回的字段,获取对应别名数据
 * </pre>
 * 
 * @param c
 * @param findInSelectList 如果在from的meta中找不到,是否继续在select中寻找
 * @return
 */
public ISelectable buildSelectable(ISelectable c, boolean findInSelectList) {
    if (c == null) {
        return null;
    }

    // 比如SELECT A.ID FROM TABLE1 A,将A.ID改名为TABLE1.ID
    if (c.getTableName() != null) {
        // 对于TableNode如果别名存在别名
        if (node instanceof TableNode && (!(node instanceof KVIndexNode))) {
            boolean isSameName = c.getTableName().equals(node.getAlias())
                                 || c.getTableName().equals(((TableNode) node).getTableName());
            if (node.isSubQuery() && node.getSubAlias() != null) {
                isSameName |= c.getTableName().equals(node.getSubAlias());
            }

            if (!isSameName) {
                throw new IllegalArgumentException("column: " + c.getFullName() + " is not existed in either "
                                                   + this.getNode().getName() + " or select clause");
            }
            c.setTableName(((TableNode) node).getTableName());// 统一改为表名
        }
    }

    ISelectable column = null;
    ISelectable columnFromMeta = null;

    if (findInSelectList) { // 优先查找select
        ISelectable columnFromSelected = getColumnFromSelecteList(c);
        if (columnFromSelected != null) {
            column = columnFromSelected;
            // 在select中找到了一次后,下次不能再从select中,遇到MAX(ID) AS ID会陷入死循环
            findInSelectList = false;
        }
    }

    if (column == null) {// 查找table meta
        columnFromMeta = this.getSelectableFromChild(c);
        if (columnFromMeta != null) {
            column = columnFromMeta;
            // 直接从子类的table定义中获取表字段,然后根据当前column状态,设置alias和distinct
            column.setAlias(c.getAlias());
            column.setDistinct(c.isDistinct());
        }
    }

    if (column == null) {
        throw new IllegalArgumentException("column: " + c.getFullName() + " is not existed in either "
                                           + this.getNode().getName() + " or select clause");
    }

    if ((column instanceof IColumn) && !IColumn.STAR.equals(column.getColumnName())) {
        node.addColumnsRefered(column); // refered不需要重复字段,select添加允许重复
        if (column.isDistinct()) {
            setExistAggregate();
        }
    }

    if (column instanceof IFunction) {
        buildFunction((IFunction) column, findInSelectList);
    }

    return column;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:81,代码来源:QueryTreeNodeBuilder.java


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