use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class AbstractInlineInnerIO method storeByOffset.
/**
* {@inheritDoc}
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
public final void storeByOffset(long pageAddr, int off, IndexRow row) {
assert row.link() != 0 : row;
assertPageType(pageAddr);
int fieldOff = 0;
InlineIndexRowHandler rowHnd = ThreadLocalRowHandlerHolder.rowHandler();
for (int i = 0; i < rowHnd.inlineIndexKeyTypes().size(); i++) {
try {
InlineIndexKeyType keyType = rowHnd.inlineIndexKeyTypes().get(i);
int size = keyType.put(pageAddr, off + fieldOff, row.key(i), inlineSize - fieldOff);
// Inline size has exceeded.
if (size == 0)
break;
fieldOff += size;
} catch (Exception e) {
throw new IgniteException("Failed to store new index row.", e);
}
}
IORowHandler.store(pageAddr, off + inlineSize, row, storeMvccInfo());
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class H2RowComparator method compareKey.
/**
* {@inheritDoc}
*/
@Override
public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, InlineIndexKeyType type) {
int cmp = super.compareKey(pageAddr, off, maxSize, key, type);
if (cmp != COMPARE_UNSUPPORTED)
return cmp;
int objType = key == NullIndexKey.INSTANCE ? type.type() : key.type();
int highOrder = Value.getHigherOrder(type.type(), objType);
// H2 supports comparison between different types after casting them to single type.
if (highOrder != objType && highOrder == type.type()) {
Value va = DataType.convertToValue(ses, key.key(), highOrder);
va = va.convertTo(highOrder);
IndexKey objHighOrder = IndexKeyFactory.wrap(va.getObject(), highOrder, coctx, keyTypeSettings);
InlineIndexKeyType highType = InlineIndexKeyTypeRegistry.get(objHighOrder, highOrder, keyTypeSettings);
// The only way to invoke inline comparison again.
if (highType != null)
return ((NullableInlineIndexKeyType) highType).compare0(pageAddr, off, objHighOrder);
}
return COMPARE_UNSUPPORTED;
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class InlineIndexColumnTest method testJavaObjectInlineHash.
/**
*/
@Test
public void testJavaObjectInlineHash() throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.JAVA_OBJECT, keyTypeSettings);
Value exp = wrap(new TestPojo(4, 3L), TestPojo.class);
{
int maxSize = 3;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
Assert.assertEquals(0, savedBytesCnt);
}
{
int maxSize = 7;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
Assert.assertEquals(5, savedBytesCnt);
Assert.assertEquals(exp.getObject().hashCode(), keyType.get(pageAddr, off, maxSize).key().hashCode());
Assert.assertEquals(CANT_BE_COMPARE, keyType.compare(pageAddr, off, maxSize, idxKey(exp)));
}
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class InlineIndexColumnTest method testStringTruncate.
/**
*/
@Test
public void testStringTruncate() throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.STRING, keyTypeSettings);
keyType.put(pageAddr, off, idxKey(ValueString.get("aaaaaaa")), 3 + 5);
assertEquals("aaaaa", keyType.get(pageAddr, off, 3 + 5).key());
keyType.put(pageAddr, off, idxKey(ValueString.get("aaa")), 3 + 5);
assertEquals("aaa", keyType.get(pageAddr, off, 3 + 5).key());
keyType.put(pageAddr, off, idxKey(ValueString.get("\u20acaaa")), 3 + 2);
assertNull(keyType.get(pageAddr, off, 3 + 2));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class InlineIndexColumnTest method testJavaObjectInlineBytes.
/**
*/
@Test
public void testJavaObjectInlineBytes() throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
DataRegionMetricsImpl dataRegionMetrics = new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log()));
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, dataRegionMetrics, false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.JAVA_OBJECT, keyTypeSettings);
ValueJavaObject exp = ValueJavaObject.getNoCopy(new TestPojo(4, 3L), null, null);
int maxSize = 3 + 3;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
maxSize = 3 + exp.getBytesNoCopy().length;
assertTrue(Arrays.equals(Arrays.copyOf(exp.getBytesNoCopy(), 3), ((JavaObjectIndexKey) keyType.get(pageAddr, off, maxSize)).bytesNoCopy()));
savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueJavaObject.getNoCopy(null, exp.getBytesNoCopy(), null)), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
assertTrue(Arrays.equals(exp.getBytesNoCopy(), ((JavaObjectIndexKey) keyType.get(pageAddr, off, maxSize)).bytesNoCopy()));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
Aggregations