use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class ERJoinChooser method getERKey.
private ERTable getERKey(PlanNode tn, Item c) {
if (!(c instanceof ItemField))
return null;
if (tn.type() != PlanNode.PlanNodeType.TABLE && !PlanUtil.isERNode(tn)) {
return null;
}
Pair<TableNode, ItemField> pair = PlanUtil.findColumnInTableLeaf((ItemField) c, tn);
if (pair == null)
return null;
TableNode tableNode = pair.getKey();
ItemField col = pair.getValue();
ERTable cm = new ERTable(tableNode.getSchema(), tableNode.getPureName(), col.getItemName());
if (tn.type() == PlanNode.PlanNodeType.TABLE) {
return cm;
} else {
List<ERTable> erList = ((JoinNode) tn).getERkeys();
for (ERTable cerKey : erList) {
if (isErRelation(cm, cerKey))
return cm;
}
return null;
}
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class HandlerTool method createPushDownGroupBy.
// ------------------------------- helper methods ------------------------
/**
* 1.count(id) : count(id) = sum[count(id) 0...n];
* 2.sum(id): sum(id) = sum[sum(id) 0...n];
* 3.avg(id) avg(id) = sum[sum(id) 0...n]/sum[count(id) 0...n];
*
* @param sumFunction aggregate function name
* @param fields
* @return
*/
protected static Item createPushDownGroupBy(ItemSum sumFunction, List<Field> fields, int startIndex) {
String funName = sumFunction.funcName().toUpperCase();
String colName = sumFunction.getItemName();
String pdName = sumFunction.getPushDownName();
Item ret = null;
List<Item> args = new ArrayList<>();
if (funName.equalsIgnoreCase("AVG")) {
String colNameSum = colName.replace(funName + "(", "SUM(");
String colNameCount = colName.replace(funName + "(", "COUNT(");
Item sumFuncSum = new ItemField(null, null, colNameSum);
sumFuncSum.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("SUM")));
Item sumFuncCount = new ItemField(null, null, colNameCount);
sumFuncCount.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("COUNT")));
Item itemSum = createFieldItem(sumFuncSum, fields, startIndex);
Item itemCount = createFieldItem(sumFuncCount, fields, startIndex);
args.add(itemSum);
args.add(itemCount);
} else if (funName.equalsIgnoreCase("STD") || funName.equalsIgnoreCase("STDDEV_POP") || funName.equalsIgnoreCase("STDDEV_SAMP") || funName.equalsIgnoreCase("STDDEV") || funName.equalsIgnoreCase("VAR_POP") || funName.equalsIgnoreCase("VAR_SAMP") || funName.equalsIgnoreCase("VARIANCE")) {
// variance: v[0]:count,v[1]:sum,v[2]:variance(locally)
String colNameCount = colName.replace(funName + "(", "COUNT(");
String colNameSum = colName.replace(funName + "(", "SUM(");
String colNameVar = colName.replace(funName + "(", "VARIANCE(");
Item sumFuncCount = new ItemField(null, null, colNameCount);
sumFuncCount.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("COUNT")));
Item sumFuncSum = new ItemField(null, null, colNameSum);
sumFuncSum.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("SUM")));
Item sumFuncVar = new ItemField(null, null, colNameVar);
sumFuncVar.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("VARIANCE")));
Item itemCount = createFieldItem(sumFuncCount, fields, startIndex);
Item itemSum = createFieldItem(sumFuncSum, fields, startIndex);
Item itemVar = createFieldItem(sumFuncVar, fields, startIndex);
args.add(itemCount);
args.add(itemSum);
args.add(itemVar);
} else {
Item subItem = createFieldItem(sumFunction, fields, startIndex);
args.add(subItem);
}
ret = sumFunction.reStruct(args, true, fields);
ret.setItemName(sumFunction.getPushDownName() == null ? sumFunction.getItemName() : sumFunction.getPushDownName());
return ret;
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class HandlerTool method createFieldItem.
protected static ItemField createFieldItem(Item col, List<Field> fields, int startIndex) {
int index = findField(col, fields, startIndex);
if (index < 0)
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "field not found:" + col);
ItemField ret = new ItemField(fields.get(index));
ret.setItemName(col.getPushDownName() == null ? col.getItemName() : col.getPushDownName());
return ret;
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class HandlerTool method findField.
/**
* findField in sel from start
*
* @param sel
* @param fields
* @param startIndex
* @return
*/
public static int findField(Item sel, List<Field> fields, int startIndex) {
String selName = (sel.getPushDownName() == null ? sel.getItemName() : sel.getPushDownName());
selName = selName.trim();
String tableName = sel.getTableName();
for (int index = startIndex; index < fields.size(); index++) {
Field field = fields.get(index);
// field.name==null if '' push down
String colName2 = field.getName() == null ? null : field.getName().trim();
String tableName2 = field.getTable();
if (sel instanceof ItemField && !StringUtil.equalsWithEmpty(tableName, tableName2)) {
continue;
}
if (selName.equalsIgnoreCase(colName2)) {
return index;
}
}
return -1;
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class MultiNodeSelectHandler method mergeFieldEof.
private void mergeFieldEof(List<byte[]> fields, BackendConnection conn) throws IOException {
fieldCount = fields.size();
List<FieldPacket> fieldPackets = new ArrayList<>();
for (byte[] field : fields) {
this.netOutBytes += field.length;
FieldPacket fieldPacket = new FieldPacket();
fieldPacket.read(field);
if (rrs.getSchema() != null) {
fieldPacket.setDb(rrs.getSchema().getBytes());
}
if (rrs.getTableAlias() != null) {
fieldPacket.setTable(rrs.getTableAlias().getBytes());
}
if (rrs.getTable() != null) {
fieldPacket.setOrgTable(rrs.getTable().getBytes());
}
fieldPackets.add(fieldPacket);
}
List<Order> orderBys = new ArrayList<>();
for (String groupBy : rrs.getGroupByCols()) {
ItemField itemField = new ItemField(rrs.getSchema(), rrs.getTableAlias(), groupBy);
orderBys.add(new Order(itemField));
}
rowComparator = new RowDataComparator(fieldPackets, orderBys);
outputHandler.fieldEofResponse(null, null, fieldPackets, null, false, conn);
}
Aggregations