use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class ItTablePersistenceTest method snapshotCheckClosure.
/**
* {@inheritDoc}
*/
@Override
public BooleanSupplier snapshotCheckClosure(JraftServerImpl restarted, boolean interactedAfterSnapshot) {
VersionedRowStore storage = getListener(restarted, raftGroupId()).getStorage();
Row key = interactedAfterSnapshot ? SECOND_KEY : FIRST_KEY;
Row value = interactedAfterSnapshot ? SECOND_VALUE : FIRST_VALUE;
return () -> {
BinaryRow read = storage.get(key, null);
if (read == null) {
return false;
}
return Arrays.equals(value.bytes(), read.bytes());
};
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class ItTablePersistenceTest method createKeyRow.
/**
* Creates a {@link Row} with the supplied key.
*
* @param id Key.
* @return Row.
*/
private static Row createKeyRow(long id) {
RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
rowBuilder.appendLong(id);
return new Row(SCHEMA, new ByteBufferRow(rowBuilder.toBytes()));
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class BinaryRowComparator method columnComparator.
/**
* Creates a comparator for comparing table columns.
*/
private static Comparator<Row> columnComparator(Column column) {
int schemaIndex = column.schemaIndex();
NativeTypeSpec typeSpec = column.type().spec();
switch(typeSpec) {
case INT8:
return (row1, row2) -> {
byte value1 = row1.byteValue(schemaIndex);
byte value2 = row2.byteValue(schemaIndex);
return Byte.compare(value1, value2);
};
case INT16:
return (row1, row2) -> {
short value1 = row1.shortValue(schemaIndex);
short value2 = row2.shortValue(schemaIndex);
return Short.compare(value1, value2);
};
case INT32:
return comparingInt(row -> row.intValue(schemaIndex));
case INT64:
return comparingLong(row -> row.longValue(schemaIndex));
case FLOAT:
return (row1, row2) -> {
float value1 = row1.floatValue(schemaIndex);
float value2 = row2.floatValue(schemaIndex);
return Float.compare(value1, value2);
};
case DOUBLE:
return comparingDouble(row -> row.doubleValue(schemaIndex));
case BYTES:
return comparing(row -> row.bytesValue(schemaIndex), Arrays::compare);
case BITMASK:
return comparing(row -> row.bitmaskValue(schemaIndex).toLongArray(), Arrays::compare);
// all other types implement Comparable
case DECIMAL:
case UUID:
case STRING:
case NUMBER:
case TIMESTAMP:
case DATE:
case TIME:
case DATETIME:
return comparing(row -> (Comparable) typeSpec.objectValue(row, schemaIndex));
default:
throw new IllegalArgumentException(String.format("Unsupported column schema for creating a sorted index. Column name: %s, column type: %s", column.name(), column.type()));
}
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class BinaryRowComparator method rowComparator.
/**
* Creates a comparator that compares two {@link Row}s by comparing individual columns.
*/
private static Comparator<Row> rowComparator(SortedIndexDescriptor descriptor) {
return descriptor.indexRowColumns().stream().map(columnDescriptor -> {
Column column = columnDescriptor.column();
Comparator<Row> columnComparator = columnComparator(column);
if (columnDescriptor.nullable()) {
columnComparator = comparingNull(row -> row.hasNullValue(column.schemaIndex(), column.type().spec()) ? null : row, columnComparator);
}
return columnDescriptor.asc() ? columnComparator : columnComparator.reversed();
}).reduce(Comparator::thenComparing).orElseThrow();
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class PrefixComparator method compare.
/**
* Compares a given row with the configured prefix.
*
* @param binaryRow Row to compare.
* @return the value {@code 0} if the given row starts with the configured prefix;
* a value less than {@code 0} if the row's prefix is smaller than the prefix; and
* a value greater than {@code 0} if the row's prefix is larger than the prefix.
*/
int compare(BinaryRow binaryRow) {
var row = new Row(descriptor.asSchemaDescriptor(), binaryRow);
for (int i = 0; i < prefix.length; ++i) {
ColumnDescriptor columnDescriptor = descriptor.indexRowColumns().get(i);
int compare = compare(columnDescriptor.column(), row, prefix[i]);
if (compare != 0) {
return columnDescriptor.asc() ? compare : -compare;
}
}
return 0;
}
Aggregations