use of org.apache.ignite.internal.schema.NativeTypeSpec in project ignite-3 by apache.
the class KeyValueViewOperationsTest method kvView.
/**
* Creates key-value view.
*/
private KeyValueViewImpl<TestKeyObject, TestObjectWithAllTypes> kvView() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
Mapper<TestKeyObject> keyMapper = Mapper.of(TestKeyObject.class);
Mapper<TestObjectWithAllTypes> valMapper = Mapper.of(TestObjectWithAllTypes.class);
Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, valCols);
// Validate all types are tested.
Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
assertEquals(Collections.emptySet(), missedTypes);
return new KeyValueViewImpl<>(table, new DummySchemaManagerImpl(schema), keyMapper, valMapper);
}
use of org.apache.ignite.internal.schema.NativeTypeSpec in project ignite-3 by apache.
the class UpgradingRowAdapterTest method serializeValuesToRow.
/**
* Validates row values after serialization-then-deserialization.
*
* @param schema Row schema.
* @param vals Row values.
* @return Row bytes.
*/
private byte[] serializeValuesToRow(SchemaDescriptor schema, List<Object> vals) {
assertEquals(schema.keyColumns().length() + schema.valueColumns().length(), vals.size());
int nonNullVarLenKeyCols = 0;
int nonNullVarLenValCols = 0;
int nonNullVarLenKeySize = 0;
int nonNullVarLenValSize = 0;
for (int i = 0; i < vals.size(); i++) {
NativeTypeSpec type = schema.column(i).type().spec();
if (vals.get(i) != null && !type.fixedLength()) {
if (type == NativeTypeSpec.BYTES) {
byte[] val = (byte[]) vals.get(i);
if (schema.isKeyColumn(i)) {
nonNullVarLenKeyCols++;
nonNullVarLenKeySize += val.length;
} else {
nonNullVarLenValCols++;
nonNullVarLenValSize += val.length;
}
} else if (type == NativeTypeSpec.STRING) {
if (schema.isKeyColumn(i)) {
nonNullVarLenKeyCols++;
nonNullVarLenKeySize += RowAssembler.utf8EncodedLength((CharSequence) vals.get(i));
} else {
nonNullVarLenValCols++;
nonNullVarLenValSize += RowAssembler.utf8EncodedLength((CharSequence) vals.get(i));
}
} else if (type == NativeTypeSpec.NUMBER) {
if (schema.isKeyColumn(i)) {
nonNullVarLenKeyCols++;
nonNullVarLenKeySize += RowAssembler.sizeInBytes((BigInteger) vals.get(i));
} else {
nonNullVarLenValCols++;
nonNullVarLenValSize += RowAssembler.sizeInBytes((BigInteger) vals.get(i));
}
} else if (type == NativeTypeSpec.DECIMAL) {
if (schema.isKeyColumn(i)) {
nonNullVarLenKeyCols++;
nonNullVarLenKeySize += RowAssembler.sizeInBytes((BigDecimal) vals.get(i));
} else {
nonNullVarLenValCols++;
nonNullVarLenValSize += RowAssembler.sizeInBytes((BigDecimal) vals.get(i));
}
} else {
throw new IllegalStateException("Unsupported variable-length type: " + type);
}
}
}
RowAssembler asm = new RowAssembler(schema, nonNullVarLenKeySize, nonNullVarLenKeyCols, nonNullVarLenValSize, nonNullVarLenValCols);
for (int i = 0; i < vals.size(); i++) {
if (vals.get(i) == null) {
asm.appendNull();
} else {
NativeType type = schema.column(i).type();
switch(type.spec()) {
case INT8:
asm.appendByte((Byte) vals.get(i));
break;
case INT16:
asm.appendShort((Short) vals.get(i));
break;
case INT32:
asm.appendInt((Integer) vals.get(i));
break;
case INT64:
asm.appendLong((Long) vals.get(i));
break;
case FLOAT:
asm.appendFloat((Float) vals.get(i));
break;
case DOUBLE:
asm.appendDouble((Double) vals.get(i));
break;
case UUID:
asm.appendUuid((java.util.UUID) vals.get(i));
break;
case STRING:
asm.appendString((String) vals.get(i));
break;
case NUMBER:
asm.appendNumber((BigInteger) vals.get(i));
break;
case DECIMAL:
asm.appendDecimal((BigDecimal) vals.get(i));
break;
case BYTES:
asm.appendBytes((byte[]) vals.get(i));
break;
case BITMASK:
asm.appendBitmask((BitSet) vals.get(i));
break;
case DATE:
asm.appendDate((LocalDate) vals.get(i));
break;
case TIME:
asm.appendTime((LocalTime) vals.get(i));
break;
case DATETIME:
asm.appendDateTime((LocalDateTime) vals.get(i));
break;
case TIMESTAMP:
asm.appendTimestamp((Instant) vals.get(i));
break;
default:
throw new IllegalStateException("Unsupported test type: " + type);
}
}
}
return asm.toBytes();
}
Aggregations