use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class TupleMarshallerImpl method marshalKey.
/**
* {@inheritDoc}
*/
@Override
public Row marshalKey(@NotNull Tuple keyTuple) throws TupleMarshallerException {
try {
final SchemaDescriptor schema = schemaReg.schema();
InternalTuple keyTuple0 = toInternalTuple(schema, keyTuple, true);
if (keyTuple0.knownColumns() < keyTuple.columnCount()) {
throw new SchemaMismatchException("Key tuple contains extra columns: " + extraColumnNames(keyTuple, true, schema));
}
final RowAssembler rowBuilder = createAssembler(schema, keyTuple0, InternalTuple.NO_VALUE);
Columns cols = schema.keyColumns();
for (int i = 0, len = cols.length(); i < len; i++) {
final Column col = cols.column(i);
writeColumn(rowBuilder, col, keyTuple0);
}
return new Row(schema, rowBuilder.build());
} catch (Exception ex) {
throw new TupleMarshallerException("Failed to marshal tuple.", ex);
}
}
use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method getBuilder.
/**
* Get TableSchemaBuilder with default table.
*
* @param nullable If all columns should be nullable.
* @param withPk If builder should contains primary key index.
* @return TableSchemaBuilder.
*/
private TableDefinitionBuilder getBuilder(boolean nullable, boolean withPk) {
Function<ColumnDefinitionBuilder, ColumnDefinition> postProcess = builder -> builder.asNullable(nullable).build();
TableDefinitionBuilder res = SchemaBuilders.tableBuilder("SCHEMA", "TABLE").columns(SchemaBuilders.column("ID", ColumnType.UUID).build(), postProcess.apply(SchemaBuilders.column("INT8", ColumnType.INT8)), postProcess.apply(SchemaBuilders.column("INT16", ColumnType.INT16)), postProcess.apply(SchemaBuilders.column("INT32", ColumnType.INT32)), postProcess.apply(SchemaBuilders.column("INT64", ColumnType.INT64)), postProcess.apply(SchemaBuilders.column("FLOAT", ColumnType.FLOAT)), postProcess.apply(SchemaBuilders.column("DOUBLE", ColumnType.DOUBLE)), postProcess.apply(SchemaBuilders.column("UUID", ColumnType.UUID)), postProcess.apply(SchemaBuilders.column("STRING", ColumnType.string())), postProcess.apply(SchemaBuilders.column("STRING_FS10", ColumnType.stringOf(10))), postProcess.apply(SchemaBuilders.column("BLOB", ColumnType.blobOf())), postProcess.apply(SchemaBuilders.column("BLOB_FS10", ColumnType.blobOf(10))), postProcess.apply(SchemaBuilders.column("DECIMAL", ColumnType.decimalOf(1, 1))), postProcess.apply(SchemaBuilders.column("NUMBER", ColumnType.numberOf(12))), postProcess.apply(SchemaBuilders.column("BITMASK_FS10", ColumnType.bitmaskOf(10))));
if (withPk) {
res.withPrimaryKey("ID");
}
return res;
}
use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class Row method findColumn.
/**
* Gets the column offset and length encoded into a single 8-byte value (4 least significant bytes encoding the offset from the
* beginning of the row and 4 most significant bytes encoding the field length for varlength columns). The offset and length should be
* extracted using {@link #offset(long)} and {@link #length(long)} methods. Will also validate that the actual column type matches the
* requested column type, throwing {@link InvalidTypeException} if the types do not match.
*
* @param colIdx Column index.
* @param type Expected column type.
* @return {@code -1} if value is {@code null} for a column, otherwise encoded offset + length of the column.
* @see #offset(long)
* @see #length(long)
* @see InvalidTypeException If actual column type does not match the requested column type.
*/
protected long findColumn(int colIdx, NativeTypeSpec type) throws InvalidTypeException {
// Get base offset (key start or value start) for the given column.
boolean isKeyCol = schema.isKeyColumn(colIdx);
Columns cols;
int chunkBaseOff;
int flags;
if (isKeyCol) {
cols = schema.keyColumns();
chunkBaseOff = KEY_CHUNK_OFFSET;
flags = keyFlags();
} else {
// Adjust the column index according to the number of key columns.
if (!hasValue()) {
throw new IllegalStateException("Row has no value.");
}
colIdx -= schema.keyColumns().length();
cols = schema.valueColumns();
chunkBaseOff = KEY_CHUNK_OFFSET + readInteger(KEY_CHUNK_OFFSET);
flags = valueFlags();
}
if (cols.column(colIdx).type().spec() != type) {
throw new InvalidTypeException("Invalid column type requested [requested=" + type + ", column=" + cols.column(colIdx) + ']');
}
int nullMapLen = cols.nullMapSize();
VarTableFormat format = VarTableFormat.fromFlags(flags);
if (nullMapLen > 0 && isNull(chunkBaseOff, colIdx)) {
return -1;
}
int dataOffset = varTableOffset(chunkBaseOff, nullMapLen);
dataOffset += format.vartableLength(format.readVartableSize(row, dataOffset));
return type.fixedLength() ? fixedSizeColumnOffset(chunkBaseOff, dataOffset, cols, colIdx, nullMapLen > 0) : varlenColumnOffsetAndLength(chunkBaseOff, dataOffset, cols, colIdx, nullMapLen, format);
}
Aggregations