Search in sources :

Example 41 with Column

use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.

the class UpgradingRowAdapter method stringValue.

/**
 * {@inheritDoc}
 */
@Override
public String stringValue(int colIdx) throws InvalidTypeException {
    int mappedId = mapColumn(colIdx);
    Column column = mappedId < 0 ? mapper.mappedColumn(colIdx) : super.schema().column(mappedId);
    if (NativeTypeSpec.STRING != column.type().spec()) {
        throw new SchemaException("Type conversion is not supported yet.");
    }
    return mappedId < 0 ? (String) column.defaultValue() : super.stringValue(mappedId);
}
Also used : SchemaException(org.apache.ignite.internal.schema.SchemaException) Column(org.apache.ignite.internal.schema.Column)

Example 42 with Column

use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.

the class UpgradingRowAdapter method floatValueBoxed.

/**
 * {@inheritDoc}
 */
@Override
public Float floatValueBoxed(int colIdx) throws InvalidTypeException {
    int mappedId = mapColumn(colIdx);
    Column column = mappedId < 0 ? mapper.mappedColumn(colIdx) : super.schema().column(mappedId);
    if (NativeTypeSpec.FLOAT != column.type().spec()) {
        throw new SchemaException("Type conversion is not supported yet.");
    }
    return mappedId < 0 ? (Float) column.defaultValue() : super.floatValueBoxed(mappedId);
}
Also used : SchemaException(org.apache.ignite.internal.schema.SchemaException) Column(org.apache.ignite.internal.schema.Column)

Example 43 with Column

use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.

the class UpgradingRowAdapter method timestampValue.

/**
 * {@inheritDoc}
 */
@Override
public Instant timestampValue(int colIdx) throws InvalidTypeException {
    int mappedId = mapColumn(colIdx);
    Column column = mappedId < 0 ? mapper.mappedColumn(colIdx) : super.schema().column(mappedId);
    if (NativeTypeSpec.TIMESTAMP != column.type().spec()) {
        throw new SchemaException("Type conversion is not supported yet.");
    }
    return mappedId < 0 ? (Instant) column.defaultValue() : super.timestampValue(mappedId);
}
Also used : SchemaException(org.apache.ignite.internal.schema.SchemaException) Column(org.apache.ignite.internal.schema.Column)

Example 44 with Column

use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.

the class SchemaSerializerImpl method writeTo.

/**
 * {@inheritDoc}
 */
@Override
public void writeTo(SchemaDescriptor desc, ByteBuffer byteBuf) {
    byteBuf.putShort(SCHEMA_VER);
    byteBuf.putInt(desc.version());
    appendColumns(desc.keyColumns(), byteBuf);
    appendColumns(desc.valueColumns(), byteBuf);
    Column[] colocationCols = desc.colocationColumns();
    byteBuf.putInt(colocationCols.length);
    for (Column column : colocationCols) {
        appendString(column.name(), byteBuf);
    }
    appendColumnMapping(desc.columnMapping(), desc.length(), byteBuf);
}
Also used : Column(org.apache.ignite.internal.schema.Column)

Example 45 with Column

use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.

the class SchemaSerializerImpl method readColumnMapping.

/**
 * Reads column mapping from byte buffer.
 *
 * @param desc SchemaDescriptor.
 * @param buf  Byte buffer.
 * @return ColumnMapper object.
 */
private ColumnMapper readColumnMapping(SchemaDescriptor desc, ByteBuffer buf) {
    int mappingSize = buf.getInt();
    if (mappingSize == 0) {
        return ColumnMapping.identityMapping();
    }
    ColumnMapper mapper = ColumnMapping.createMapper(desc);
    for (int i = 0; i < mappingSize; i++) {
        int from = buf.getInt();
        int to = buf.getInt();
        if (to == -1) {
            Column col = readColumn(buf);
            mapper.add(col);
        } else {
            mapper.add(from, to);
        }
    }
    return mapper;
}
Also used : Column(org.apache.ignite.internal.schema.Column) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper)

Aggregations

Column (org.apache.ignite.internal.schema.Column)131 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)78 Test (org.junit.jupiter.api.Test)44 Row (org.apache.ignite.internal.schema.row.Row)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 Tuple (org.apache.ignite.table.Tuple)27 MethodSource (org.junit.jupiter.params.provider.MethodSource)27 SchemaException (org.apache.ignite.internal.schema.SchemaException)22 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)20 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)10 Arrays (java.util.Arrays)7 NotNull (org.jetbrains.annotations.NotNull)7 List (java.util.List)6 Random (java.util.Random)6 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)6 BigDecimal (java.math.BigDecimal)5