Search in sources :

Example 6 with GridH2Row

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Row in project ignite by apache.

the class H2ExtrasLeafIO method storeByOffset.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
public void storeByOffset(long pageAddr, int off, SearchRow row) {
    GridH2Row row0 = (GridH2Row) row;
    assert row0.link() != 0;
    List<InlineIndexHelper> inlineIdxs = InlineIndexHelper.getCurrentInlineIndexes();
    assert inlineIdxs != null : "no inline index helpers";
    int fieldOff = 0;
    for (int i = 0; i < inlineIdxs.size(); i++) {
        InlineIndexHelper idx = inlineIdxs.get(i);
        int size = idx.put(pageAddr, off + fieldOff, row.getValue(idx.columnIndex()), payloadSize - fieldOff);
        if (size == 0)
            break;
        fieldOff += size;
    }
    PageUtils.putLong(pageAddr, off + payloadSize, row0.link());
}
Also used : GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) InlineIndexHelper(org.apache.ignite.internal.processors.query.h2.database.InlineIndexHelper)

Example 7 with GridH2Row

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Row in project ignite by apache.

the class H2InnerIO method storeByOffset.

/**
 * {@inheritDoc}
 */
@Override
public void storeByOffset(long pageAddr, int off, SearchRow row) {
    GridH2Row row0 = (GridH2Row) row;
    assert row0.link() != 0;
    PageUtils.putLong(pageAddr, off, row0.link());
}
Also used : GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)

Example 8 with GridH2Row

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Row in project ignite by apache.

the class H2LeafIO method storeByOffset.

/**
 * {@inheritDoc}
 */
@Override
public void storeByOffset(long pageAddr, int off, SearchRow row) {
    GridH2Row row0 = (GridH2Row) row;
    assert row0.link() != 0;
    PageUtils.putLong(pageAddr, off, row0.link());
}
Also used : GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)

Example 9 with GridH2Row

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Row in project ignite by apache.

the class H2RowDescriptor method createRow.

/** {@inheritDoc} */
@Override
public GridH2Row createRow(KeyCacheObject key, int partId, @Nullable CacheObject val, GridCacheVersion ver, long expirationTime) throws IgniteCheckedException {
    GridH2Row row;
    try {
        if (// Only can happen for remove operation, can create simple search row.
        val == null)
            row = GridH2RowFactory.create(wrap(key, keyType));
        else
            row = schema.offheap() == null ? new GridH2KeyValueRowOnheap(this, key, keyType, val, valType, ver, expirationTime) : new GridH2KeyValueRowOffheap(this, key, keyType, val, valType, ver, expirationTime);
    } catch (ClassCastException e) {
        throw new IgniteCheckedException("Failed to convert key to SQL type. " + "Please make sure that you always store each value type with the same key type " + "or configure key type as common super class for all actual keys for this value type.", e);
    }
    row.ver = ver;
    row.key = key;
    row.val = val;
    row.partId = partId;
    return row;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2KeyValueRowOffheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOffheap) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) GridH2KeyValueRowOnheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)

Example 10 with GridH2Row

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Row in project ignite by apache.

the class GridH2TableSelfTest method testTable.

/**
     * Simple table test.
     *
     * @throws Exception If failed.
     */
public void testTable() throws Exception {
    // Test insert.
    long x = MAX_X;
    Random rnd = new Random();
    while (x-- > 0) {
        UUID id = UUID.randomUUID();
        GridH2Row row = row(id, System.currentTimeMillis(), rnd.nextBoolean() ? id.toString() : UUID.randomUUID().toString(), rnd.nextInt(100));
        tbl.doUpdate(row, false);
    }
    assertEquals(MAX_X, tbl.getRowCountApproximation());
    assertEquals(MAX_X, tbl.getRowCount(null));
    for (GridH2IndexBase idx : tbl.indexes()) {
        assertEquals(MAX_X, idx.getRowCountApproximation());
        assertEquals(MAX_X, idx.getRowCount(null));
    }
    // Check correct rows order.
    checkOrdered((GridH2TreeIndex) tbl.indexes().get(0), new Comparator<SearchRow>() {

        @Override
        public int compare(SearchRow o1, SearchRow o2) {
            UUID id1 = (UUID) o1.getValue(0).getObject();
            UUID id2 = (UUID) o2.getValue(0).getObject();
            return id1.compareTo(id2);
        }
    });
    checkOrdered((GridH2TreeIndex) tbl.indexes().get(1), new Comparator<SearchRow>() {

        @Override
        public int compare(SearchRow o1, SearchRow o2) {
            Long x1 = (Long) o1.getValue(3).getObject();
            Long x2 = (Long) o2.getValue(3).getObject();
            int c = x2.compareTo(x1);
            if (c != 0)
                return c;
            Timestamp t1 = (Timestamp) o1.getValue(1).getObject();
            Timestamp t2 = (Timestamp) o2.getValue(1).getObject();
            return t1.compareTo(t2);
        }
    });
    checkOrdered((GridH2TreeIndex) tbl.indexes().get(2), new Comparator<SearchRow>() {

        @Override
        public int compare(SearchRow o1, SearchRow o2) {
            String s1 = (String) o1.getValue(2).getObject();
            String s2 = (String) o2.getValue(2).getObject();
            return s2.compareTo(s1);
        }
    });
    // Indexes data consistency.
    ArrayList<? extends Index> idxs = tbl.indexes();
    checkIndexesConsistent((ArrayList<Index>) idxs, null);
    // Check unique index.
    UUID id = UUID.randomUUID();
    UUID id2 = UUID.randomUUID();
    assertTrue(tbl.doUpdate(row(id, System.currentTimeMillis(), id.toString(), rnd.nextInt(100)), false));
    assertTrue(tbl.doUpdate(row(id2, System.currentTimeMillis(), id2.toString(), rnd.nextInt(100)), false));
    // Check index selection.
    checkQueryPlan(conn, "SELECT * FROM T", SCAN_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE ID IS NULL", PK_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE ID = RANDOM_UUID()", PK_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE ID > RANDOM_UUID()", PK_NAME);
    checkQueryPlan(conn, "SELECT * FROM T ORDER BY ID", PK_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE STR IS NULL", STR_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE STR = 'aaaa'", STR_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE STR > 'aaaa'", STR_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T ORDER BY STR DESC", STR_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE X IS NULL", NON_UNIQUE_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE X = 10000", NON_UNIQUE_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T WHERE X > 10000", NON_UNIQUE_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T ORDER BY X DESC", NON_UNIQUE_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T ORDER BY X DESC, T", NON_UNIQUE_IDX_NAME);
    checkQueryPlan(conn, "SELECT * FROM T ORDER BY T, X DESC", SCAN_IDX_NAME);
    // Simple queries.
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select id from t where x between 0 and 100");
    int i = 0;
    while (rs.next()) i++;
    assertEquals(MAX_X + 2, i);
    // -----
    rs = s.executeQuery("select id from t where t is not null");
    i = 0;
    while (rs.next()) i++;
    assertEquals(MAX_X + 2, i);
    // ----
    int cnt = 10 + rnd.nextInt(25);
    long t = System.currentTimeMillis();
    for (i = 0; i < cnt; i++) {
        id = UUID.randomUUID();
        assertTrue(tbl.doUpdate(row(id, t, id.toString(), 51), false));
    }
    rs = s.executeQuery("select x, id from t where x = 51 limit " + cnt);
    i = 0;
    while (rs.next()) {
        assertEquals(51, rs.getInt(1));
        i++;
    }
    assertEquals(cnt, i);
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Index(org.h2.index.Index) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) ValueString(org.h2.value.ValueString) Timestamp(java.sql.Timestamp) ValueTimestamp(org.h2.value.ValueTimestamp) Random(java.util.Random) ValueLong(org.h2.value.ValueLong) ResultSet(java.sql.ResultSet) UUID(java.util.UUID) SearchRow(org.h2.result.SearchRow)

Aggregations

GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Index (org.h2.index.Index)5 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)4 IndexingQueryCacheFilter (org.apache.ignite.spi.indexing.IndexingQueryCacheFilter)3 Random (java.util.Random)2 UUID (java.util.UUID)2 IgniteException (org.apache.ignite.IgniteException)2 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)2 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)2 InlineIndexHelper (org.apache.ignite.internal.processors.query.h2.database.InlineIndexHelper)2 Cursor (org.h2.index.Cursor)2 SingleRowCursor (org.h2.index.SingleRowCursor)2 SearchRow (org.h2.result.SearchRow)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Timestamp (java.sql.Timestamp)1 HashSet (java.util.HashSet)1