use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class PushDownVisitor method getJoinOn.
private StringBuilder getJoinOn(JoinNode join, MysqlVisitor leftVisitor, MysqlVisitor rightVisitor) {
StringBuilder joinOnFilterStr = new StringBuilder();
boolean first = true;
for (int i = 0; i < join.getJoinFilter().size(); i++) {
Item filter = join.getJoinFilter().get(i);
if (first) {
sqlBuilder.append(" on ");
first = false;
} else
joinOnFilterStr.append(" and ");
joinOnFilterStr.append(filter);
}
if (join.getOtherJoinOnFilter() != null) {
if (!first) {
joinOnFilterStr.append(" and ");
}
joinOnFilterStr.append(join.getOtherJoinOnFilter());
}
// is not left join
if (leftVisitor.getWhereFilter() != null && !join.getLeftOuter()) {
if (!first) {
joinOnFilterStr.append(" and ");
}
joinOnFilterStr.append("(");
joinOnFilterStr.append(leftVisitor.getWhereFilter());
joinOnFilterStr.append(")");
}
// is not right join
if (rightVisitor.getWhereFilter() != null && !join.getRightOuter()) {
if (!first) {
joinOnFilterStr.append(" and ");
}
joinOnFilterStr.append("(");
joinOnFilterStr.append(rightVisitor.getWhereFilter());
joinOnFilterStr.append(")");
}
return joinOnFilterStr;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class PushDownVisitor method visitPushDownNameSel.
@Override
protected String visitPushDownNameSel(Item item) {
String orgPushDownName = null;
if (item.isWithSubQuery()) {
Item tmpItem = PlanUtil.rebuildSubQueryItem(item);
orgPushDownName = tmpItem.getItemName();
} else {
orgPushDownName = item.getItemName();
}
if (item.type().equals(Item.ItemType.FIELD_ITEM)) {
orgPushDownName = "`" + item.getTableName() + "`.`" + orgPushDownName + "`";
}
String pushAlias = null;
if (pushNameMap.containsKey(orgPushDownName)) {
// duplicate column
item.setPushDownName(pushNameMap.get(orgPushDownName));
return null;
}
if (item.type().equals(Item.ItemType.SUM_FUNC_ITEM)) {
// generate alias for aggregate function,it must contain the real name
String aggName = ((ItemSum) item).funcName().toUpperCase();
pushAlias = getMadeAggAlias(aggName) + getRandomAliasName();
} else if (item.getAlias() != null) {
pushAlias = item.getAlias();
if (pushAlias.startsWith(Item.FNAF))
pushAlias = getRandomAliasName();
} else if (orgPushDownName.length() > MAX_COL_LENGTH) {
pushAlias = getRandomAliasName();
} else if (isTopQuery && !item.type().equals(Item.ItemType.FIELD_ITEM)) {
pushAlias = getRandomAliasName();
}
if (pushAlias == null) {
if (item.type().equals(Item.ItemType.FIELD_ITEM)) {
pushNameMap.put(orgPushDownName, null);
} else {
item.setPushDownName(orgPushDownName);
pushNameMap.put(orgPushDownName, orgPushDownName);
}
} else {
item.setPushDownName(pushAlias);
pushNameMap.put(orgPushDownName, pushAlias);
}
if (pushAlias == null)
return orgPushDownName;
else
return orgPushDownName + " as `" + pushAlias + "`";
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class DistinctHandler method fieldEofResponse.
/**
* treat all the data from parent as Field Type
*/
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, final List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
if (terminate.get())
return;
if (this.pool == null)
this.pool = DbleServer.getInstance().getBufferPool();
this.fieldPackets = fieldPackets;
List<Field> sourceFields = HandlerTool.createFields(this.fieldPackets);
if (this.distinctCols == null) {
// eg:show tables
this.distinctCols = new ArrayList<>();
for (FieldPacket fp : this.fieldPackets) {
Item sel = HandlerTool.createItemField(fp);
this.distinctCols.add(sel);
}
}
List<Order> orders = this.fixedOrders;
if (orders == null)
orders = HandlerTool.makeOrder(this.distinctCols);
RowDataComparator comparator = new RowDataComparator(this.fieldPackets, orders, this.isAllPushDown(), type());
localResult = new DistinctLocalResult(pool, sourceFields.size(), comparator, CharsetUtil.getJavaCharset(conn.getCharset().getResults())).setMemSizeController(session.getOtherBufferMC());
nextHandler.fieldEofResponse(null, null, this.fieldPackets, null, this.isLeft, conn);
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class HandlerTool method makeOrder.
/**
* make order by from distinct
*
* @param selects
* @return
*/
public static List<Order> makeOrder(List<Item> selects) {
List<Order> orders = new ArrayList<>();
for (Item sel : selects) {
Order order = new Order(sel, SQLOrderingSpecification.ASC);
orders.add(order);
}
return orders;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class HandlerTool method createFunctionItem.
protected static ItemFunc createFunctionItem(ItemFunc f, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
ItemFunc ret = null;
List<Item> args = new ArrayList<>();
for (int index = 0; index < f.getArgCount(); index++) {
Item arg = f.arguments().get(index);
Item newArg = null;
if (arg.isWild())
newArg = new ItemInt(0);
else
newArg = createItem(arg, fields, startIndex, allPushDown, type);
if (newArg == null)
throw new RuntimeException("Function argument not found:" + arg);
args.add(newArg);
}
ret = (ItemFunc) f.reStruct(args, allPushDown, fields);
ret.setItemName(f.getPushDownName() == null ? f.getItemName() : f.getPushDownName());
return ret;
}
Aggregations