use of org.h2.result.Row in project ignite by apache.
the class DmlStatementsProcessor method streamUpdateQuery.
/**
* Perform given statement against given data streamer. Only rows based INSERT and MERGE are supported
* as well as key bound UPDATE and DELETE (ones with filter {@code WHERE _key = ?}).
*
* @param streamer Streamer to feed data to.
* @param stmt Statement.
* @param args Statement arguments.
* @return Number of rows in given statement for INSERT and MERGE, {@code 1} otherwise.
* @throws IgniteCheckedException if failed.
*/
@SuppressWarnings({ "unchecked", "ConstantConditions" })
long streamUpdateQuery(IgniteDataStreamer streamer, PreparedStatement stmt, Object[] args) throws IgniteCheckedException {
args = U.firstNotNull(args, X.EMPTY_OBJECT_ARRAY);
Prepared p = GridSqlQueryParser.prepared(stmt);
assert p != null;
UpdatePlan plan = UpdatePlanBuilder.planForStatement(p, null);
if (!F.eq(streamer.cacheName(), plan.tbl.rowDescriptor().context().name()))
throw new IgniteSQLException("Cross cache streaming is not supported, please specify cache explicitly" + " in connection options", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
if (plan.mode == UpdateMode.INSERT && plan.rowsNum > 0) {
assert plan.isLocSubqry;
final GridCacheContext cctx = plan.tbl.rowDescriptor().context();
QueryCursorImpl<List<?>> cur;
final ArrayList<List<?>> data = new ArrayList<>(plan.rowsNum);
final GridQueryFieldsResult res = idx.queryLocalSqlFields(idx.schema(cctx.name()), plan.selectQry, F.asList(args), null, false, 0, null);
QueryCursorImpl<List<?>> stepCur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
try {
return new GridQueryCacheObjectsIterator(res.iterator(), idx.objectContext(), cctx.keepBinary());
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
}, null);
data.addAll(stepCur.getAll());
cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
return data.iterator();
}
}, null);
if (plan.rowsNum == 1) {
IgniteBiTuple t = rowToKeyValue(cctx, cur.iterator().next(), plan);
streamer.addData(t.getKey(), t.getValue());
return 1;
}
Map<Object, Object> rows = new LinkedHashMap<>(plan.rowsNum);
for (List<?> row : cur) {
final IgniteBiTuple t = rowToKeyValue(cctx, row, plan);
rows.put(t.getKey(), t.getValue());
}
streamer.addData(rows);
return rows.size();
} else
throw new IgniteSQLException("Only tuple based INSERT statements are supported in streaming mode", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
use of org.h2.result.Row in project ignite by apache.
the class IgniteH2Indexing method rebuildIndexesFromHash.
/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
if (tbl == null)
return;
assert tbl.table() != null;
assert tbl.table().rebuildFromHashInProgress();
H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
Cursor cursor = hashIdx.find((Session) null, null, null);
while (cursor.next()) {
CacheDataRow dataRow = (CacheDataRow) cursor.get();
boolean done = false;
while (!done) {
GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
try {
synchronized (entry) {
// TODO : How to correctly get current value and link here?
GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
row.link(dataRow.link());
List<Index> indexes = tbl.table().getAllIndexes();
for (int i = 2; i < indexes.size(); i++) {
Index idx = indexes.get(i);
if (idx instanceof H2TreeIndex)
((H2TreeIndex) idx).put(row);
}
done = true;
}
} catch (GridCacheEntryRemovedException e) {
// No-op
}
}
}
tbl.table().markRebuildFromHashInProgress(false);
}
use of org.h2.result.Row in project ignite by apache.
the class GridH2AbstractKeyValueRow method toString.
/** {@inheritDoc} */
@Override
public String toString() {
SB sb = new SB("Row@");
sb.a(Integer.toHexString(System.identityHashCode(this)));
addOffheapRowId(sb);
Value v = peekValue(KEY_COL);
sb.a("[ key: ").a(v == null ? "nil" : v.getString());
v = WeakValue.unwrap(peekValue(VAL_COL));
sb.a(", val: ").a(v == null ? "nil" : v.getString());
v = peekValue(VER_COL);
sb.a(", ver: ").a(v == null ? "nil" : v.getString());
sb.a(" ][ ");
if (v != null) {
for (int i = DEFAULT_COLUMNS_COUNT, cnt = getColumnCount(); i < cnt; i++) {
v = getValue(i);
if (i != DEFAULT_COLUMNS_COUNT)
sb.a(", ");
if (!desc.isKeyValueOrVersionColumn(i))
sb.a(v == null ? "nil" : v.getString());
}
}
sb.a(" ]");
return sb.toString();
}
use of org.h2.result.Row in project ignite by apache.
the class H2Tree method compareRows.
/**
* Compare two rows.
*
* @param r1 Row 1.
* @param r2 Row 2.
* @return Compare result.
*/
private int compareRows(GridH2Row r1, SearchRow r2) {
if (r1 == r2)
return 0;
for (int i = 0, len = cols.length; i < len; i++) {
int idx = columnIds[i];
Value v1 = r1.getValue(idx);
Value v2 = r2.getValue(idx);
if (v1 == null || v2 == null) {
// can't compare further
return 0;
}
int c = compareValues(v1, v2);
if (c != 0)
return InlineIndexHelper.fixSort(c, cols[i].sortType);
}
return 0;
}
use of org.h2.result.Row in project ignite by apache.
the class GridH2TableSelfTest method checkIndexesConsistent.
/**
* @param idxs Indexes.
* @param rowSet Rows.
* @return Rows.
*/
private Set<Row> checkIndexesConsistent(ArrayList<Index> idxs, @Nullable Set<Row> rowSet) throws IgniteCheckedException {
for (Index idx : idxs) {
if (!(idx instanceof GridH2TreeIndex))
continue;
Set<Row> set = new HashSet<>();
GridCursor<GridH2Row> cursor = ((GridH2TreeIndex) idx).rows();
while (cursor.next()) assertTrue(set.add(cursor.get()));
if (rowSet == null || rowSet.isEmpty())
rowSet = set;
else
assertEquals(rowSet, set);
}
return rowSet;
}
Aggregations