use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class GetYearValue method get.
@Override
public long get(Item item, Item warnitem, BoolPtr isNull) {
long value = 0;
value = item.valInt().longValue();
isNull.set(item.isNullValue());
if (isNull.get())
return 0;
/*
* Coerce value to the 19XX form in order to correctly compare YEAR(2) &
* YEAR(4) types. Here we are converting all item values but YEAR(4)
* fields since 1) YEAR(4) already has a regular YYYY form and 2) we
* don't want to convert zero/bad YEAR(4) values to the value of 2000.
*/
if (item.type() == Item.ItemType.FIELD_ITEM) {
Field field = ((ItemField) item).getField();
if (field.fieldType() == FieldTypes.MYSQL_TYPE_YEAR && field.getFieldLength() == 4) {
if (value < 70)
value += 100;
if (value <= 1900)
value += 1900;
}
}
/* Convert year to DATETIME packed format */
return MyTime.yearToLonglongDatetimePacked(value);
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class SelectedProcessor method mergePushOrderBy.
private static void mergePushOrderBy(Item orderSel, List<Item> mergeSelects) {
if (orderSel instanceof ItemField) {
if (!mergeSelects.contains(orderSel))
mergeSelects.add(orderSel);
} else if (orderSel instanceof ItemFunc) {
ItemFunc func = (ItemFunc) orderSel;
if (func.isWithSumFunc()) {
for (int index = 0; index < func.getArgCount(); index++) {
Item arg = func.arguments().get(index);
mergePushOrderBy(arg, mergeSelects);
}
} else {
if (!mergeSelects.contains(func)) {
mergeSelects.add(func);
}
// union's order by must be found from selects
func.setPushDownName(func.getItemName());
}
} else if (orderSel instanceof ItemSum) {
ItemSum func = (ItemSum) orderSel;
for (int index = 0; index < func.getArgCount(); index++) {
Item arg = func.arguments().get(index);
mergePushOrderBy(arg, mergeSelects);
}
}
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class SubQueryPreProcessor method transformInSubQuery.
private static SubQueryFilter transformInSubQuery(SubQueryFilter qtn, ItemInSubQuery filter, BoolPtr childTransform) {
Item leftColumn = filter.getLeftOperand();
PlanNode query = filter.getPlanNode();
query = findComparisonsSubQueryToJoinNode(query, childTransform);
QueryNode changeQuery = new QueryNode(query);
String alias = AUTOALIAS + query.getPureName();
changeQuery.setAlias(alias);
if (query.getColumnsSelected().size() != 1)
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "only support subquery of one column");
query.setSubQuery(true).setDistinct(true);
final List<Item> newSelects = qtn.query.getColumnsSelected();
SubQueryFilter result = new SubQueryFilter();
Item rightColumn = query.getColumnsSelected().get(0);
qtn.query.setColumnsSelected(new ArrayList<Item>());
String rightJoinName = rightColumn.getAlias();
if (StringUtils.isEmpty(rightJoinName)) {
if (rightColumn instanceof ItemField) {
rightJoinName = rightColumn.getItemName();
} else {
rightColumn.setAlias(AUTONAME);
rightJoinName = AUTONAME;
}
}
ItemField rightJoinColumn = new ItemField(null, alias, rightJoinName);
// rename the left column's table name
result.query = new JoinNode(qtn.query, changeQuery);
// leave origin sql to new join node
result.query.setSql(qtn.query.getSql());
qtn.query.setSql(null);
result.query.select(newSelects);
qtn.query.setSubQuery(false);
if (!qtn.query.getOrderBys().isEmpty()) {
List<Order> orderBys = new ArrayList<>();
orderBys.addAll(qtn.query.getOrderBys());
result.query.setOrderBys(orderBys);
qtn.query.getOrderBys().clear();
}
if (!qtn.query.getGroupBys().isEmpty()) {
List<Order> groupBys = new ArrayList<>();
groupBys.addAll(qtn.query.getGroupBys());
result.query.setGroupBys(groupBys);
qtn.query.getGroupBys().clear();
result.query.having(qtn.query.getHavingFilter());
qtn.query.having(null);
}
if (qtn.query.getLimitFrom() != -1) {
result.query.setLimitFrom(qtn.query.getLimitFrom());
qtn.query.setLimitFrom(-1);
}
if (qtn.query.getLimitTo() != -1) {
result.query.setLimitTo(qtn.query.getLimitTo());
qtn.query.setLimitTo(-1);
}
if (filter.isNeg()) {
((JoinNode) result.query).setLeftOuterJoin().setNotIn(true);
ItemFuncEqual joinFilter = FilterUtils.equal(leftColumn, rightJoinColumn);
((JoinNode) result.query).addJoinFilter(joinFilter);
result.filter = null;
} else {
Item joinFilter = FilterUtils.equal(leftColumn, rightJoinColumn);
result.query.query(joinFilter);
result.filter = joinFilter;
}
result.query.setUpFields();
return result;
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class PlanNode method dealSingleStarColumn.
protected void dealSingleStarColumn(List<Item> newSels) {
for (NamedField field : innerFields.keySet()) {
ItemField col = new ItemField(null, field.getTable(), field.getName());
newSels.add(col);
}
}
use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.
the class PlanNode method setUpSelects.
protected void setUpSelects() {
if (columnsSelected.isEmpty()) {
columnsSelected.add(new ItemField(null, null, "*"));
}
boolean withWild = false;
for (Item sel : columnsSelected) {
if (sel.isWild())
withWild = true;
}
if (withWild)
dealStarColumn();
outerFields.clear();
nameContext.setFindInSelect(false);
nameContext.setSelectFirst(false);
for (Item sel : columnsSelected) {
setUpItem(sel);
NamedField field = makeOutNamedField(sel);
if (outerFields.containsKey(field) && getParent() != null)
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "duplicate field");
outerFields.put(field, sel);
}
}
Aggregations