Search in sources :

Example 11 with Value

use of org.h2.value.Value in project jackrabbit-oak by apache.

the class PersistentCacheCommand method dump.

static void dump(PrintWriter write, String path, String revision, String map, String fileName, boolean values, boolean raw) {
    MVStore s = new MVStore.Builder().readOnly().fileName(fileName).open();
    Map<String, String> meta = s.getMetaMap();
    boolean statsOnly = "".equalsIgnoreCase(map) && "".equals(revision) && "".equals(path);
    if (!statsOnly) {
        if (raw) {
            write.println("map" + "\t" + "key" + "\t" + "length" + "\t" + "value");
        } else if (values) {
            write.println("map,path,revision,p2,length,value");
        } else {
            write.println("map,path,revision,p2,length");
        }
    }
    for (String n : meta.keySet()) {
        if (n.startsWith("name.")) {
            String mapName = n.substring(5, n.length());
            if (map.length() > 0 && !map.equalsIgnoreCase(mapName)) {
                continue;
            }
            MVMap.Builder<String, String> b = new MVMap.Builder<String, String>().keyType(StringDataType.INSTANCE).valueType(StringDataType.INSTANCE);
            MVMap<String, String> m = s.openMap(mapName, b);
            if (statsOnly) {
                statistics(write, m);
            } else if (raw) {
                dumpRaw(write, m);
            } else {
                dump(write, m, path, revision, values);
            }
        }
    }
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) MVMap(org.h2.mvstore.MVMap)

Example 12 with Value

use of org.h2.value.Value in project ignite by apache.

the class MapQueryResult method fetchNextPage.

/**
 * @param rows Collection to fetch into.
 * @param pageSize Page size.
 * @return {@code true} If there are no more rows available.
 */
synchronized boolean fetchNextPage(List<Value[]> rows, int pageSize) {
    assert lazyWorker == null || lazyWorker == MapQueryLazyWorker.currentWorker();
    if (closed)
        return true;
    boolean readEvt = cctx != null && cctx.name() != null && cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
    page++;
    for (int i = 0; i < pageSize; i++) {
        if (!res.next())
            return true;
        Value[] row = 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.currentRow());
    }
    return 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 13 with Value

use of org.h2.value.Value in project ignite by apache.

the class H2Tree method compareRows.

/**
 * Compares two H2 rows.
 *
 * @param r1 Row 1.
 * @param r2 Row 2.
 * @return Compare result: see {@link Comparator#compare(Object, Object)} for values.
 */
public int compareRows(SearchRow 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;
}
Also used : Value(org.h2.value.Value)

Example 14 with Value

use of org.h2.value.Value in project ignite by apache.

the class H2Tree method compare.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
protected int compare(BPlusIO<SearchRow> io, long pageAddr, int idx, SearchRow row) throws IgniteCheckedException {
    if (inlineSize() == 0)
        return compareRows(getRow(io, pageAddr, idx), row);
    else {
        int off = io.offset(idx);
        int fieldOff = 0;
        int lastIdxUsed = 0;
        for (int i = 0; i < inlineIdxs.size(); i++) {
            InlineIndexHelper inlineIdx = inlineIdxs.get(i);
            Value v2 = row.getValue(inlineIdx.columnIndex());
            if (v2 == null)
                return 0;
            int c = inlineIdx.compare(pageAddr, off + fieldOff, inlineSize() - fieldOff, v2, comp);
            if (c == -2)
                break;
            lastIdxUsed++;
            if (c != 0)
                return c;
            fieldOff += inlineIdx.fullSize(pageAddr, off + fieldOff);
            if (fieldOff > inlineSize())
                break;
        }
        if (lastIdxUsed == cols.length)
            return 0;
        SearchRow rowData = getRow(io, pageAddr, idx);
        for (int i = lastIdxUsed, len = cols.length; i < len; i++) {
            IndexColumn col = cols[i];
            int idx0 = col.column.getColumnId();
            Value v2 = row.getValue(idx0);
            if (v2 == null) {
                // Can't compare further.
                return 0;
            }
            Value v1 = rowData.getValue(idx0);
            int c = compareValues(v1, v2);
            if (c != 0)
                return InlineIndexHelper.fixSort(c, col.sortType);
        }
        return 0;
    }
}
Also used : Value(org.h2.value.Value) SearchRow(org.h2.result.SearchRow) IndexColumn(org.h2.table.IndexColumn)

Example 15 with Value

use of org.h2.value.Value in project ignite by apache.

the class InlineIndexHelper method compareAsString.

/**
 * @param pageAddr Page address.
 * @param off Offset.
 * @param v Value to compare.
 * @param ignoreCase {@code True} if a case-insensitive comparison should be used.
 * @return Compare result ({@code -2} means we can't compare).
 */
private int compareAsString(long pageAddr, int off, Value v, boolean ignoreCase) {
    String s = v.getString();
    int len1 = PageUtils.getShort(pageAddr, off + 1) & 0x7FFF;
    int len2 = s.length();
    int c, c2, c3, c4, cntr1 = 0, cntr2 = 0;
    char v1, v2;
    // Skip length and type byte.
    long addr = pageAddr + off + 3;
    // Try reading ASCII.
    while (cntr1 < len1 && cntr2 < len2) {
        c = (int) GridUnsafe.getByte(addr) & 0xFF;
        if (c > 127)
            break;
        cntr1++;
        addr++;
        v1 = (char) c;
        v2 = s.charAt(cntr2++);
        if (ignoreCase) {
            v1 = Character.toUpperCase(v1);
            v2 = Character.toUpperCase(v2);
        }
        if (v1 != v2)
            return fixSort(Integer.signum(v1 - v2), sortType());
    }
    // read other
    while (cntr1 < len1 && cntr2 < len2) {
        c = (int) GridUnsafe.getByte(addr++) & 0xFF;
        switch(c >> 4) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                /* 0xxxxxxx*/
                cntr1++;
                v1 = (char) c;
                break;
            case 12:
            case 13:
                /* 110x xxxx   10xx xxxx*/
                cntr1 += 2;
                if (cntr1 > len1)
                    throw new IllegalStateException("Malformed input (partial character at the end).");
                c2 = (int) GridUnsafe.getByte(addr++) & 0xFF;
                if ((c2 & 0xC0) != 0x80)
                    throw new IllegalStateException("Malformed input around byte: " + (cntr1 - 2));
                c = c & 0x1F;
                c = (c << 6) | (c2 & 0x3F);
                v1 = (char) c;
                break;
            case 14:
                /* 1110 xxxx  10xx xxxx  10xx xxxx */
                cntr1 += 3;
                if (cntr1 > len1)
                    throw new IllegalStateException("Malformed input (partial character at the end).");
                c2 = (int) GridUnsafe.getByte(addr++) & 0xFF;
                c3 = (int) GridUnsafe.getByte(addr++) & 0xFF;
                if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80))
                    throw new IllegalStateException("Malformed input around byte: " + (cntr1 - 3));
                c = c & 0x0F;
                c = (c << 6) | (c2 & 0x3F);
                c = (c << 6) | (c3 & 0x3F);
                v1 = (char) c;
                break;
            case 15:
                /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
                cntr1 += 4;
                if (cntr1 > len1)
                    throw new IllegalStateException("Malformed input (partial character at the end).");
                c2 = (int) GridUnsafe.getByte(addr++) & 0xFF;
                c3 = (int) GridUnsafe.getByte(addr++) & 0xFF;
                c4 = (int) GridUnsafe.getByte(addr++) & 0xFF;
                if (((c & 0xF8) != 0xf0) || ((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80) || ((c4 & 0xC0) != 0x80))
                    throw new IllegalStateException("Malformed input around byte: " + (cntr1 - 4));
                c = c & 0x07;
                c = (c << 6) | (c2 & 0x3F);
                c = (c << 6) | (c3 & 0x3F);
                c = (c << 6) | (c4 & 0x3F);
                // Subtract 0x010000, c is now 0..fffff (20 bits)
                c = c - 0x010000;
                // height surrogate
                v1 = (char) (0xD800 + ((c >> 10) & 0x7FF));
                v2 = s.charAt(cntr2++);
                if (v1 != v2)
                    return fixSort(Integer.signum(v1 - v2), sortType());
                if (cntr2 == len2)
                    // Finish comparison here.
                    return fixSort(1, sortType());
                // Low surrogate.
                v1 = (char) (0xDC00 + (c & 0x3FF));
                v2 = s.charAt(cntr2++);
                if (v1 != v2)
                    return fixSort(Integer.signum(v1 - v2), sortType());
                continue;
            default:
                /* 10xx xxxx */
                throw new IllegalStateException("Malformed input around byte: " + cntr1);
        }
        v2 = s.charAt(cntr2++);
        if (ignoreCase) {
            v1 = Character.toUpperCase(v1);
            v2 = Character.toUpperCase(v2);
        }
        if (v1 != v2)
            return fixSort(Integer.signum(v1 - v2), sortType());
    }
    int res = cntr1 == len1 && cntr2 == len2 ? 0 : cntr1 == len1 ? -1 : 1;
    if (isValueFull(pageAddr, off))
        return fixSort(res, sortType());
    if (res >= 0)
        // b) Even truncated current value is longer, so that it's bigger.
        return fixSort(1, sortType());
    return -2;
}
Also used : ValueString(org.h2.value.ValueString)

Aggregations

Value (org.h2.value.Value)291 SQLException (java.sql.SQLException)94 DbException (org.h2.message.DbException)91 ResultSet (java.sql.ResultSet)69 PreparedStatement (java.sql.PreparedStatement)61 Statement (java.sql.Statement)53 Column (org.h2.table.Column)44 ValueString (org.h2.value.ValueString)44 JdbcStatement (org.h2.jdbc.JdbcStatement)42 JdbcPreparedStatement (org.h2.jdbc.JdbcPreparedStatement)36 SimpleResultSet (org.h2.tools.SimpleResultSet)31 StatementBuilder (org.h2.util.StatementBuilder)28 IndexColumn (org.h2.table.IndexColumn)23 Expression (org.h2.expression.Expression)22 IOException (java.io.IOException)21 Row (org.h2.result.Row)19 SearchRow (org.h2.result.SearchRow)18 Connection (java.sql.Connection)17 ValueArray (org.h2.value.ValueArray)17 ValueTimestamp (org.h2.value.ValueTimestamp)17