use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class SelectExecutor method queryGroupSorted.
private void queryGroupSorted(int columnCount, ResultTarget result) {
int rowNumber = 0;
prepared.setCurrentRowNumber(0);
prepared.setCurrentGroup(null);
Value[] previousKeyValues = null;
while (topTableFilter.next()) {
//for rownum expression
prepared.setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
rowNumber++;
Value[] keyValues = new Value[groupIndex.length];
// update group
for (int i = 0; i < groupIndex.length; i++) {
int idx = groupIndex[i];
Expression expr = expressions.get(idx);
keyValues[i] = expr.getValue(session);
}
if (previousKeyValues == null) {
previousKeyValues = keyValues;
prepared.setCurrentGroup(New.<Expression, Object>hashMap());
} else if (!Arrays.equals(previousKeyValues, keyValues)) {
addGroupSortedRow(previousKeyValues, columnCount, result);
previousKeyValues = keyValues;
prepared.setCurrentGroup(New.<Expression, Object>hashMap());
}
prepared.increaseCurrentGroupRowId();
for (int i = 0; i < columnCount; i++) {
if (groupByExpression == null || !groupByExpression[i]) {
Expression expr = expressions.get(i);
expr.updateAggregate(session);
}
}
}
}
if (previousKeyValues != null) {
addGroupSortedRow(previousKeyValues, columnCount, result);
}
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class SelectExecutor method queryFlat.
private void queryFlat(int columnCount, ResultTarget result, long limitRows) {
// limitRows is never 0 here
if (limitRows > 0 && offsetExpr != null) {
int offset = offsetExpr.getValue(session).getInt();
if (offset > 0) {
limitRows += offset;
}
}
int rowNumber = 0;
prepared.setCurrentRowNumber(0);
int sampleSize = getSampleSizeValue(session);
while (topTableFilter.next()) {
prepared.setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Value[] row = new Value[columnCount];
for (int i = 0; i < columnCount; i++) {
Expression expr = expressions.get(i);
row[i] = expr.getValue(session);
}
result.addRow(row);
rowNumber++;
if ((sort == null) && limitRows > 0 && result.getRowCount() >= limitRows) {
break;
}
if (sampleSize > 0 && rowNumber >= sampleSize) {
break;
}
}
}
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class SelectExecutor method queryGroupAccordant.
private void queryGroupAccordant(int columnCount, ResultTarget result) {
Value[] row = new Value[columnCount];
for (int i = 0; i < columnCount; i++) {
Expression expr = expressions.get(i);
row[i] = expr.getValue(session);
}
result.addRow(row);
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class DefineCommandExecutor method execute.
/**
* execute DDL use default sql translator
*
* @param nodes
*/
public void execute(TableNode[] nodes) {
session.checkCanceled();
List<JdbcWorker<Integer>> workers = New.arrayList(nodes.length);
for (TableNode node : nodes) {
String sql = doTranslate(node);
List<Parameter> items = getPrepared().getParameters();
List<Value> params = New.arrayList(items.size());
for (Parameter parameter : items) {
params.add(parameter.getParamValue());
}
workers.add(createUpdateWorker(node.getShardName(), sql, params));
}
addRuningJdbcWorkers(workers);
try {
// DDL statement returns nothing.
if (workers.size() > 1) {
//MILLISECONDS
int queryTimeout = getQueryTimeout();
if (queryTimeout > 0) {
jdbcExecutor.invokeAll(workers, queryTimeout, TimeUnit.MILLISECONDS);
} else {
jdbcExecutor.invokeAll(workers);
}
} else if (workers.size() == 1) {
workers.get(0).doWork();
}
} catch (InterruptedException e) {
throw DbException.convert(e);
} finally {
removeRuningJdbcWorkers(workers);
for (JdbcWorker<Integer> jdbcWorker : workers) {
jdbcWorker.closeResource();
}
}
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class InsertExecutor method addRow.
@Override
public void addRow(Value[] values) {
TableMate table = castTableMate(prepared.getTable());
Row newRow = table.getTemplateRow();
Column[] columns = prepared.getColumns();
prepared.setCurrentRowNumber(++rowNumber);
for (int j = 0, len = columns.length; j < len; j++) {
Column c = columns[j];
int index = c.getColumnId();
try {
Value v = c.convert(values[j]);
newRow.setValue(index, v);
} catch (DbException ex) {
throw prepared.setRow(ex, rowNumber, Prepared.getSQL(values));
}
}
table.validateConvertUpdateSequence(session, newRow);
addNewRow(newRow);
}
Aggregations