use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class InSubQueryHandler method fieldEofResponse.
@Override
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
if (terminate.get()) {
return;
}
lock.lock();
try {
// create field for first time
if (this.fieldPackets.isEmpty()) {
this.fieldPackets = fieldPackets;
sourceField = HandlerTool.createField(this.fieldPackets.get(0));
Item select = itemSubQuery.getSelect();
select.setPushDownName(select.getAlias());
Item tmpItem = HandlerTool.createItem(select, Collections.singletonList(this.sourceField), 0, isAllPushDown(), type());
itemSubQuery.setFiled(tmpItem);
}
} finally {
lock.unlock();
}
}
use of com.actiontech.dble.plan.common.item.Item 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.Item in project dble by actiontech.
the class HandlerTool method getItemListBytes.
public static List<byte[]> getItemListBytes(List<Item> items) {
List<byte[]> ret = new ArrayList<>(items.size());
for (Item item : items) {
byte[] b = item.getRowPacketByte();
ret.add(b);
}
return ret;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class TestMySQLItemVisitor method testJoinCondition.
@Test
public void testJoinCondition() {
MySqlSelectQueryBlock query = getQuery("select a.col1,b.col2 from table1 a inner join table2 b on a.id =b.id");
SQLJoinTableSource from = (SQLJoinTableSource) query.getFrom();
MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
from.getCondition().accept(v);
Item item = v.getItem();
Assert.assertEquals(true, "a.id = b.id".equals(item.getItemName()));
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class TestMySQLItemVisitor method testGroupbyHaving.
@Test
public void testGroupbyHaving() {
MySqlSelectQueryBlock query = getQuery("select col1 from table1 group by col1 having count(*)>1 ");
SQLSelectGroupByClause groupBy = query.getGroupBy();
SQLExpr q = groupBy.getHaving();
MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
q.accept(v);
Item item = v.getItem();
Assert.assertEquals(true, "COUNT(*) > 1".equals(item.getItemName()));
}
Aggregations