use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class TestMySQLItemVisitor method testOrderby.
@Test
public void testOrderby() {
MySqlSelectQueryBlock query = getQuery("select col1,col2 from table1 order by col1 asc, col2 desc ");
SQLOrderBy orderBy = query.getOrderBy();
int i = 0;
for (SQLSelectOrderByItem p : orderBy.getItems()) {
i++;
String orderCol = "col" + i;
SQLExpr expr = p.getExpr();
MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
expr.accept(v);
Item item = v.getItem();
Assert.assertEquals(true, orderCol.equals(item.getItemName()));
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ItemFuncCase method findItem.
/**
* Find and return matching items for CASE or ELSE item if all compares are
* failed or NULL if ELSE item isn't defined.
* <p>
* IMPLEMENTATION In order to do correct comparisons of the CASE expression
* (the expression between CASE and the first WHEN) with each WHEN
* expression several comparators are used. One for each result type. CASE
* expression can be evaluated up to # of different result types are used.
* To check whether the CASE expression already was evaluated for a
* particular result type a bit mapped variable value_added_map is used.
* Result types are mapped to it according to their int values i.e.
* STRING_RESULT is mapped to bit 0, REAL_RESULT to bit 1, so on.
*
* @retval NULL Nothing found and there is no ELSE expression defined
* @retval item Found item or ELSE item if defined and all comparisons are
* failed
*/
private Item findItem() {
if (firstExprNum == -1) {
for (int i = 0; i < ncases; i += 2) {
// No expression between CASE and the first WHEN
if (args.get(i).valBool())
return args.get(i + 1);
continue;
}
} else {
/* Compare every WHEN argument with it and return the first match */
Item leftCmpItem = args.get(firstExprNum);
if (leftCmpItem.isNull() || leftCmpItem.type() == ItemType.NULL_ITEM) {
return elseExprNum != -1 ? args.get(elseExprNum) : null;
}
for (int i = 0; i < ncases; i += 2) {
if (args.get(i).type() == ItemType.NULL_ITEM)
continue;
Item rightCmpItem = args.get(i);
ArgComparator comparator = new ArgComparator(leftCmpItem, rightCmpItem);
comparator.setCmpFunc(null, leftCmpItem, rightCmpItem, false);
if (comparator.compare() == 0 && !rightCmpItem.isNullValue())
return args.get(i + 1);
}
}
// No, WHEN clauses all missed, return ELSE expression
return elseExprNum != -1 ? args.get(elseExprNum) : null;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ItemFuncCase method valDecimal.
@Override
public BigDecimal valDecimal() {
Item item = findItem();
if (item == null) {
nullValue = true;
return null;
}
BigDecimal res = item.valDecimal();
nullValue = item.isNullValue();
return res;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ItemFuncCase method toExpression.
// @Override
// protected Item cloneStruct() {
// List<Item> newArgList = cloneStructList(args);
// return new Item_func_case(newArgList, ncases, first_expr_num,
// else_expr_num);
// }
@Override
public SQLExpr toExpression() {
SQLCaseExpr caseExpr = new SQLCaseExpr();
List<SQLExpr> exprList = toExpressionList(args);
for (int index = 0; index < ncases; ) {
SQLExpr exprCond = exprList.get(index++);
SQLExpr exprValue = exprList.get(index++);
SQLCaseExpr.Item item = new SQLCaseExpr.Item(exprCond, exprValue);
caseExpr.addItem(item);
}
if (firstExprNum > 0) {
caseExpr.setValueExpr(exprList.get(firstExprNum));
}
if (elseExprNum > 0) {
caseExpr.setElseExpr(exprList.get(elseExprNum));
}
return caseExpr;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ItemFuncIf method valReal.
@Override
public BigDecimal valReal() {
Item arg = args.get(0).valBool() ? args.get(1) : args.get(2);
BigDecimal value = arg.valReal();
nullValue = arg.isNullValue();
return value;
}
Aggregations