use of com.actiontech.dble.plan.common.field.Field in project dble by actiontech.
the class RowDataComparator method cmp.
private int cmp(RowDataPacket o1, RowDataPacket o2, int index) {
List<byte[]> bo1 = getCmpBytes(o1);
List<byte[]> bo2 = getCmpBytes(o2);
boolean isAsc = ascList.get(index);
Field field = cmpFields.get(index);
byte[] b1 = bo1.get(index);
byte[] b2 = bo2.get(index);
int rs;
if (isAsc) {
rs = field.compare(b1, b2);
} else {
rs = field.compare(b2, b1);
}
if (rs != 0 || cmpFields.size() == (index + 1)) {
return rs;
} else {
return cmp(o1, o2, index + 1);
}
}
use of com.actiontech.dble.plan.common.field.Field 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.field.Field in project dble by actiontech.
the class ShowTables method responseDirect.
private static void responseDirect(ServerConnection c, String cSchema, ShowCreateStmtInfo info) {
ByteBuffer buffer = c.allocate();
Map<String, String> tableMap = getTableSet(cSchema, info);
PackageBufINf bufInf;
if (info.isFull()) {
List<FieldPacket> fieldPackets = new ArrayList<>(2);
bufInf = writeFullTablesHeader(buffer, c, cSchema, fieldPackets);
if (info.getWhere() != null) {
MySQLItemVisitor mev = new MySQLItemVisitor(c.getSchema(), c.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager());
info.getWhereExpr().accept(mev);
List<Field> sourceFields = HandlerTool.createFields(fieldPackets);
Item whereItem = HandlerTool.createItem(mev.getItem(), sourceFields, 0, false, DMLResponseHandler.HandlerType.WHERE);
bufInf = writeFullTablesRow(bufInf.getBuffer(), c, tableMap, bufInf.getPacketId(), whereItem, sourceFields);
} else {
bufInf = writeFullTablesRow(bufInf.getBuffer(), c, tableMap, bufInf.getPacketId(), null, null);
}
} else {
bufInf = writeTablesHeaderAndRows(buffer, c, tableMap, cSchema);
}
writeRowEof(bufInf.getBuffer(), c, bufInf.getPacketId());
}
use of com.actiontech.dble.plan.common.field.Field 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.field.Field in project dble by actiontech.
the class DirectGroupByHandler method fieldEofResponse.
@Override
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, final List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
if (terminate.get())
return;
if (this.pool == null)
this.pool = DbleServer.getInstance().getBufferPool();
this.fieldPackets = fieldPackets;
List<Field> sourceFields = HandlerTool.createFields(this.fieldPackets);
for (ItemSum sumFunc : referredSumFunctions) {
ItemSum sum = (ItemSum) (HandlerTool.createItem(sumFunc, sourceFields, 0, this.isAllPushDown(), this.type()));
sums.add(sum);
}
prepareSumAggregators(sums, true);
setupSumFunctions(sums);
/* group fieldpackets are front of the origin */
sendGroupFieldPackets((MySQLConnection) conn);
// row in localresult is DGRowPacket which is added aggregate functions result from origin rowdatapacket
localResultFps = this.fieldPackets;
List<ItemSum> localResultReferredSums = referredSumFunctions;
RowDataComparator comparator = new RowDataComparator(this.localResultFps, this.groupBys, this.isAllPushDown(), this.type());
groupLocalResult = new GroupByLocalResult(pool, localResultFps.size(), comparator, localResultFps, localResultReferredSums, this.isAllPushDown(), CharsetUtil.getJavaCharset(conn.getCharset().getResults())).setMemSizeController(session.getOtherBufferMC());
for (int i = 0; i < bucketSize; i++) {
RowDataComparator tmpComparator = new RowDataComparator(this.localResultFps, this.groupBys, this.isAllPushDown(), this.type());
GroupByBucket bucket = new GroupByBucket(queue, outQueue, pool, localResultFps.size(), tmpComparator, localResultFps, localResultReferredSums, this.isAllPushDown(), CharsetUtil.getJavaCharset(conn.getCharset().getResults()));
bucket.setMemSizeController(session.getOtherBufferMC());
buckets.add(bucket);
bucket.start();
}
if (this.groupStart.compareAndSet(false, true)) {
startOwnThread(conn);
}
}
Aggregations