use of org.h2.result.Row in project ignite by apache.
the class GridSqlInsert method getSQL.
/** {@inheritDoc} */
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
buff.append("INSERT").append("\nINTO ").append(into.getSQL()).append('(');
for (GridSqlColumn col : cols) {
buff.appendExceptFirst(", ");
buff.append('\n').append(col.getSQL());
}
buff.append("\n)\n");
if (direct)
buff.append("DIRECT ");
if (sorted)
buff.append("SORTED ");
if (!rows.isEmpty()) {
buff.append("VALUES\n");
StatementBuilder valuesBuff = new StatementBuilder();
for (GridSqlElement[] row : rows()) {
valuesBuff.appendExceptFirst(",\n");
StatementBuilder rowBuff = new StatementBuilder("(");
for (GridSqlElement e : row) {
rowBuff.appendExceptFirst(", ");
rowBuff.append(e != null ? e.getSQL() : "DEFAULT");
}
rowBuff.append(')');
valuesBuff.append(rowBuff.toString());
}
buff.append(valuesBuff.toString());
} else
buff.append('\n').append(qry.getSQL());
return buff.toString();
}
use of org.h2.result.Row in project ignite by apache.
the class GridSqlMerge method getSQL.
/** {@inheritDoc} */
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
buff.append("MERGE INTO ").append(into.getSQL()).append("(");
for (GridSqlColumn col : cols) {
buff.appendExceptFirst(", ");
buff.append('\n').append(col.getSQL());
}
buff.append("\n)\n");
if (keys != null) {
buff.append("KEY(\n");
buff.resetCount();
for (GridSqlColumn c : keys) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL()).append('\n');
}
buff.append(")\n");
}
if (!rows.isEmpty()) {
buff.append("VALUES\n");
StatementBuilder valuesBuff = new StatementBuilder();
for (GridSqlElement[] row : rows()) {
valuesBuff.appendExceptFirst(",\n");
StatementBuilder rowBuff = new StatementBuilder("(");
for (GridSqlElement e : row) {
rowBuff.appendExceptFirst(", ");
rowBuff.append(e != null ? e.getSQL() : "DEFAULT");
}
rowBuff.append(')');
valuesBuff.append(rowBuff.toString());
}
buff.append(valuesBuff.toString());
} else
buff.append('\n').append(qry.getSQL());
return buff.toString();
}
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();
}
Aggregations