use of org.apache.ignite.internal.schema.NativeType 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();
}
use of org.apache.ignite.internal.schema.NativeType in project ignite-3 by apache.
the class UpgradingRowAdapterTest method generateRowValues.
/**
* Generate row values for given row schema.
*
* @param schema Row schema.
* @return Row values.
*/
private List<Object> generateRowValues(SchemaDescriptor schema) {
ArrayList<Object> res = new ArrayList<>(schema.length());
for (int i = 0; i < schema.length(); i++) {
NativeType type = schema.column(i).type();
res.add(SchemaTestUtils.generateRandomValue(rnd, type));
}
return res;
}
Aggregations