本文整理汇总了Java中com.taobao.tddl.optimizer.core.expression.ISelectable.setTableName方法的典型用法代码示例。如果您正苦于以下问题:Java ISelectable.setTableName方法的具体用法?Java ISelectable.setTableName怎么用?Java ISelectable.setTableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.core.expression.ISelectable
的用法示例。
在下文中一共展示了ISelectable.setTableName方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
}
示例3: getSelectableFromParent
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
* 解决correlated subquery问题, 当前对象找不到,尝试找一下parent节点
*
* <pre>
* <a href="http://dev.mysql.com/doc/refman/5.6/en/correlated-subqueries.html">correlated subquery</a>
* </pre>
*/
protected ISelectable getSelectableFromParent(ISelectable c) {
if (this.getNode().getParent() != null) {
ISelectable column = this.getNode().getParent().getBuilder().getSelectableFromChild(c);
if (column != null) {
String alias = this.getNode().getParent().getAlias();
if (alias != null) {
column.setTableName(alias);
}
}
return column;
} else {
return null;
}
}
示例4: getColumnFromOtherNode
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
* 从select列表中查找字段,并根据查找的字段信息进行更新,比如更新tableName
*/
protected ISelectable getColumnFromOtherNode(ISelectable c, QueryTreeNode other) {
ISelectable res = findColumnFromOtherNode(c, other);
if (res == null) {
return null;
}
if (c instanceof IColumn) {
c.setDataType(res.getDataType());
c.setAutoIncrement(res.isAutoIncrement());
// 如果是子表的结构,比如Join/Merge的子节点,字段的名字直接使用别名
if (other.getAlias() != null) {
c.setTableName(other.getAlias());
} else {
c.setTableName(res.getTableName());
}
}
return c;
}
示例5: getSelectableFromChild
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
public ISelectable getSelectableFromChild(ISelectable c) {
if (c.getTableName() != null) {
if ((!c.getTableName().equals(this.getNode().getIndexName()))
&& (!c.getTableName().equals(this.getNode().getAlias()))) {
return null;
}
}
if (IColumn.STAR.equals(c.getColumnName())) {
return c;
}
if (c instanceof IFunction) {
c.setTableName(this.getNode().getIndexName());
return c;
}
return this.getSelectableFromChild(c.getColumnName());
}
示例6: buildOrderBy
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
@Override
public void buildOrderBy() {
// 如果merge本身没指定order by,则继承子节点的order by
if (this.getNode().getOrderBys() == null || this.getNode().getOrderBys().isEmpty()) {
QueryTreeNode child = (QueryTreeNode) this.getNode().getChild();
if (child.getOrderBys() != null) {
for (IOrderBy o : child.getOrderBys()) {
ISelectable sc = o.getColumn().copy();
if (o.getColumn().getAlias() != null) {
sc.setColumnName(o.getColumn().getAlias());
}
if (child.getAlias() != null) {
sc.setTableName(child.getAlias());
}
this.getNode().orderBy(sc, o.getDirection());
}
}
}
super.buildOrderBy();
// 检查group列是否在select列中
for (IOrderBy order : node.getOrderBys()) {
checkOrderColumnExist(order, (QueryTreeNode) node.getChild());
}
}
示例7: getSelectableFromChild
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的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());
}
示例8: getColumnFromOtherNode
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
/**
* 从select列表中查找字段,并根据查找的字段信息进行更新,比如更新tableName
*/
public ISelectable getColumnFromOtherNode(ISelectable c, QueryTreeNode other) {
ISelectable res = findColumnFromOtherNode(c, other);
if (res == null) {
return null;
}
if (c instanceof IColumn) {
c.setDataType(res.getDataType());
// 如果是子表的结构,比如Join/Merge的子节点,字段的名字直接使用别名
if (other.getAlias() != null) {
c.setTableName(other.getAlias());
} else {
c.setTableName(res.getTableName());
}
}
return c;
}
示例9: buildOrderBy
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
@Override
public void buildOrderBy() {
// 如果merge本身没指定order by,则继承子节点的order by
if (this.getNode().getOrderBys() == null || this.getNode().getOrderBys().isEmpty()) {
QueryTreeNode child = (QueryTreeNode) this.getNode().getChild();
if (child.getOrderBys() != null) {
for (IOrderBy o : child.getOrderBys()) {
ISelectable sc = o.getColumn().copy();
if (o.getColumn().getAlias() != null) {
sc.setColumnName(o.getColumn().getAlias());
}
if (child.getAlias() != null) {
sc.setTableName(child.getAlias());
}
this.getNode().orderBy(sc, o.getDirection());
}
}
}
super.buildOrderBy();
}
示例10: getSelectableFromChild
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
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;
}
return this.getSelectableFromChild(c.getColumnName());
}
示例11: build
import com.taobao.tddl.optimizer.core.expression.ISelectable; //导入方法依赖的package包/类
@Override
public void build() {
super.build();
if (this.getDuplicateUpdateColumns() != null) {
for (ISelectable s : this.getDuplicateUpdateColumns()) {
ISelectable res = null;
for (Object obj : table.getColumnsReferedForParent()) {
ISelectable querySelected = (ISelectable) obj;
if (s.isSameName(querySelected)) { // 尝试查找对应的字段信息
res = querySelected;
break;
}
}
if (res == null) {
throw new IllegalArgumentException("column: " + s.getColumnName() + " is not existed in "
+ table.getName());
}
s.setTableName(res.getTableName());
s.setDataType(res.getDataType());
s.setAutoIncrement(res.isAutoIncrement());
}
convertTypeToSatifyColumnMeta(this.getDuplicateUpdateColumns(), this.getDuplicateUpdateValues());
}
}
示例12: 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;
}