Search in sources :

Example 26 with Value

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);
    }
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) Value(org.h2.value.Value) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Example 27 with Value

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);
}
Also used : Value(org.h2.value.Value)

Example 28 with Value

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;
}
Also used : Value(org.h2.value.Value)

Example 29 with Value

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);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) Value(org.h2.value.Value) GridH2ValueMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage)

Example 30 with Value

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);
}
Also used : GridSqlConst(org.apache.ignite.internal.processors.query.h2.sql.GridSqlConst) GridSqlColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn) Column(org.h2.table.Column) Expression(org.h2.expression.Expression) Value(org.h2.value.Value) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) DataType(org.h2.value.DataType) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Aggregations

Value (org.h2.value.Value)751 Value (org.gridgain.internal.h2.value.Value)326 SQLException (java.sql.SQLException)186 DbException (org.h2.message.DbException)126 ValueBigint (org.h2.value.ValueBigint)100 DbException (org.gridgain.internal.h2.message.DbException)98 PreparedStatement (java.sql.PreparedStatement)78 ResultSet (java.sql.ResultSet)78 Column (org.h2.table.Column)65 Statement (java.sql.Statement)56 Expression (org.h2.expression.Expression)52 ValueSmallint (org.h2.value.ValueSmallint)52 Column (org.gridgain.internal.h2.table.Column)50 ValueString (org.gridgain.internal.h2.value.ValueString)49 Row (org.h2.result.Row)49 SearchRow (org.h2.result.SearchRow)49 ArrayList (java.util.ArrayList)44 JdbcStatement (org.gridgain.internal.h2.jdbc.JdbcStatement)42 Database (org.h2.engine.Database)42 BigDecimal (java.math.BigDecimal)41