use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class MapQueryResult method fetchNextPage.
/**
* @param rows Collection to fetch into.
* @param pageSize Page size.
* @param dataPageScanEnabled If data page scan is enabled.
* @return {@code true} If there are no more rows available.
*/
boolean fetchNextPage(List<Value[]> rows, int pageSize, Boolean dataPageScanEnabled) {
assert lock.isHeldByCurrentThread();
if (closed)
return true;
assert res != null;
boolean readEvt = cctx != null && cctx.name() != null && cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
QueryContext.threadLocal(H2Utils.context(ses));
page++;
h2.enableDataPageScan(dataPageScanEnabled);
try {
for (int i = 0; i < pageSize; i++) {
if (!res.res.next())
return true;
Value[] row = res.res.currentRow();
if (cpNeeded) {
boolean copied = false;
for (int j = 0; j < row.length; j++) {
Value val = row[j];
if (val instanceof GridH2ValueCacheObject) {
GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject) val;
row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheObject(), h2.objectContext()) {
@Override
public Object getObject() {
return getObject(true);
}
};
copied = true;
}
}
if (i == 0 && !copied)
// No copy on read caches, skip next checks.
cpNeeded = false;
}
assert row != null;
if (readEvt) {
GridKernalContext ctx = h2.kernalContext();
ctx.event().record(new CacheQueryReadEvent<>(ctx.discovery().localNode(), "SQL fields query result set row read.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.SQL.name(), cctx.name(), null, qry.query(), null, null, params, qrySrcNodeId, null, null, null, null, row(row)));
}
rows.add(res.res.currentRow());
res.fetchSizeInterceptor.checkOnFetchNext();
}
return !res.res.hasNext();
} finally {
CacheDataTree.setDataPageScanEnabled(false);
}
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class SqlAbstractLocalSystemView method createRow.
/**
* @param ses Session.
* @param data Data for each column.
*/
protected Row createRow(Session ses, Object... data) {
Value[] values = new Value[data.length];
for (int i = 0; i < data.length; i++) {
Object o = data[i];
Value v = (o == null) ? ValueNull.INSTANCE : (o instanceof Value) ? (Value) o : ValueString.get(o.toString());
values[i] = cols[i].convert(v);
}
return ses.getDatabase().createRow(values, 0);
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class SortedReduceIndexAdapter method compareRows.
/**
* {@inheritDoc}
*/
@Override
public int compareRows(SearchRow rowData, SearchRow compare) {
if (rowData == compare)
return 0;
for (int i = 0, len = indexColumns.length; i < len; i++) {
int index = columnIds[i];
int sortType = indexColumns[i].sortType;
Value v1 = rowData.getValue(index);
Value v2 = compare.getValue(index);
if (v1 == null || v2 == null)
return 0;
else if (v1 == v2)
continue;
else if (v1 == ValueNull.INSTANCE || v2 == ValueNull.INSTANCE) {
if ((sortType & SortOrder.NULLS_FIRST) != 0)
return v1 == ValueNull.INSTANCE ? -1 : 1;
else if ((sortType & SortOrder.NULLS_LAST) != 0)
return v1 == ValueNull.INSTANCE ? 1 : -1;
}
int comp = table.compareTypeSafe(v1, v2);
if ((sortType & SortOrder.DESCENDING) != 0)
comp = -comp;
if (comp != 0)
return comp;
}
return 0;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class H2TreeIndex method toSearchRow.
/**
* @param msg Row message.
* @return Search row.
*/
private SearchRow toSearchRow(GridH2RowMessage msg) {
if (msg == null)
return null;
Value[] vals = new Value[getTable().getColumns().length];
assert vals.length > 0;
List<GridH2ValueMessage> msgVals = msg.values();
for (int i = 0; i < indexColumns.length; i++) {
if (i >= msgVals.size())
continue;
try {
vals[indexColumns[i].column.getColumnId()] = msgVals.get(i).value(ctx);
} catch (IgniteCheckedException e) {
throw new CacheException(e);
}
}
return database.createRow(vals, MEMORY_CALCULATE);
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class DmlAstUtils method elementOrDefault.
/**
* Do what we can to compute default value for this column (mimics H2 behavior).
* @see Table#getDefaultValue
* @see Column#validateConvertUpdateSequence
* @param el SQL element.
* @param col Column.
* @return {@link GridSqlConst#NULL}, if {@code el} is null, or {@code el} if
* it's not {@link GridSqlKeyword#DEFAULT}, or computed default value.
*/
private static GridSqlElement elementOrDefault(GridSqlElement el, GridSqlColumn col) {
if (el == null)
return GridSqlConst.NULL;
if (el != GridSqlKeyword.DEFAULT)
return el;
Column h2Col = col.column();
Expression dfltExpr = h2Col.getDefaultExpression();
Value dfltVal;
try {
dfltVal = dfltExpr != null ? dfltExpr.getValue(null) : null;
} catch (Exception ignored) {
throw new IgniteSQLException("Failed to evaluate default value for a column " + col.columnName());
}
if (dfltVal != null)
return new GridSqlConst(dfltVal);
int type = h2Col.getType();
DataType dt = DataType.getDataType(type);
if (dt.decimal)
dfltVal = ValueInt.get(0).convertTo(type);
else if (dt.type == Value.TIMESTAMP)
dfltVal = ValueTimestamp.fromMillis(U.currentTimeMillis());
else if (dt.type == Value.TIME)
dfltVal = ValueTime.fromNanos(0);
else if (dt.type == Value.DATE)
dfltVal = ValueDate.fromMillis(U.currentTimeMillis());
else
dfltVal = ValueString.get("").convertTo(type);
return new GridSqlConst(dfltVal);
}
Aggregations