use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class HandlerTool method createItem.
/**
* create Item, the Item value referenced by field and changed by field changes
*
* @param sel
* @param fields
* @param type
* @return
*/
public static Item createItem(Item sel, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
Item ret;
if (sel.basicConstItem())
return sel;
if (sel instanceof ItemScalarSubQuery) {
ItemScalarSubQuery scalarSubQuery = (ItemScalarSubQuery) sel;
if (scalarSubQuery.getPlanNode().type() == PlanNode.PlanNodeType.NONAME) {
Item result = scalarSubQuery.getSelect();
result.setItemName(scalarSubQuery.getItemName());
result.setAlias(scalarSubQuery.getItemName());
return result;
} else {
return scalarSubQuery.getValue();
}
}
Item.ItemType i = sel.type();
if (i == Item.ItemType.FUNC_ITEM || i == Item.ItemType.COND_ITEM) {
ItemFunc func = (ItemFunc) sel;
if (func.getPushDownName() == null || func.getPushDownName().length() == 0) {
ret = createFunctionItem(func, fields, startIndex, allPushDown, type);
} else {
ret = createFieldItem(func, fields, startIndex);
}
} else if (i == Item.ItemType.SUM_FUNC_ITEM) {
ItemSum sumFunc = (ItemSum) sel;
if (type != HandlerType.GROUPBY) {
ret = createFieldItem(sumFunc, fields, startIndex);
} else if (sumFunc.getPushDownName() == null || sumFunc.getPushDownName().length() == 0) {
ret = createSumItem(sumFunc, fields, startIndex, allPushDown, type);
} else {
ret = createPushDownGroupBy(sumFunc, fields, startIndex);
}
} else {
ret = createFieldItem(sel, fields, startIndex);
}
ret.fixFields();
return ret;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class HandlerTool method createSumItem.
/**
* @param f
* @param fields
* @param startIndex
* @param allPushDown
* @param type
* @return
*/
private static ItemSum createSumItem(ItemSum f, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
ItemSum 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 = (ItemSum) f.reStruct(args, allPushDown, fields);
ret.setItemName(f.getPushDownName() == null ? f.getItemName() : f.getPushDownName());
return ret;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ViewMeta method setFieldsAlias.
private void setFieldsAlias(PlanNode selNode) throws Exception {
if (viewColumnMeta != null) {
// check if the column number of view is same as the selectList in selectStatement
if (viewColumnMeta.size() != selNode.getColumnsSelected().size()) {
// return error
throw new Exception("The Column_list Size and Select_statement Size Not Match");
}
for (int i = 0; i < viewColumnMeta.size(); i++) {
selNode.getColumnsSelected().get(i).setAlias(viewColumnMeta.get(i).trim());
}
} else {
List<Item> selectList = selNode.getColumnsSelected();
Set<String> tempMap = new HashSet<String>();
for (Item t : selectList) {
if (t.getAlias() != null) {
if (tempMap.contains(t.getAlias())) {
throw new Exception("Duplicate column name '" + t.getItemName() + "'");
}
tempMap.add(t.getAlias());
} else {
if (tempMap.contains(t.getItemName())) {
throw new Exception("Duplicate column name '" + t.getItemName() + "'");
}
tempMap.add(t.getItemName());
}
}
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class MySQLcom method aggResultType.
public static ItemResult aggResultType(List<Item> items, int startIndex, int size) {
ItemResult type = ItemResult.STRING_RESULT;
/* Skip beginning NULL items */
int index = 0, indexEnd;
Item item;
for (index = startIndex, indexEnd = startIndex + size; index < indexEnd; index++) {
item = items.get(index);
if (item.type() != ItemType.NULL_ITEM) {
type = item.resultType();
index++;
break;
}
}
/* Combine result types. Note: NULL items don't affect the result */
for (; index < indexEnd; index++) {
item = items.get(index);
if (item.type() != ItemType.NULL_ITEM)
type = itemStoreType(type, item);
}
return type;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ItemFunc method countRealLength.
/**
* Set max_length/decimals of function if function is floating point and
* result length/precision depends on argument ones.
*/
public void countRealLength() {
int length = 0;
decimals = 0;
maxLength = 0;
for (Item arg : args) {
if (decimals != NOT_FIXED_DEC) {
decimals = Math.max(decimals, arg.getDecimals());
length = Math.max(length, arg.getMaxLength() - arg.getDecimals());
}
maxLength = Math.max(maxLength, arg.getMaxLength());
}
if (decimals != NOT_FIXED_DEC) {
maxLength = length;
length += decimals;
if (// If previous operation gave overflow
length < maxLength)
maxLength = Integer.MAX_VALUE;
else
maxLength = length;
}
}
Aggregations