Search in sources :

Example 31 with Column

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

the class RecordMarshallerImpl method collectObjectStats.

/**
 * Reads mapped object fields and gather statistic.
 *
 * @throws MarshallerException If failed to read object content.
 */
private ObjectStatistic collectObjectStats(Columns cols, Marshaller marsh, Object obj) throws MarshallerException {
    if (obj == null || !cols.hasVarlengthColumns()) {
        return ObjectStatistic.ZERO_VARLEN_STATISTICS;
    }
    int cnt = 0;
    int size = 0;
    for (int i = cols.firstVarlengthColumn(); i < cols.length(); i++) {
        final Column column = cols.column(i);
        final Object val = marsh.value(obj, column.schemaIndex());
        if (val == null || column.type().spec().fixedLength()) {
            continue;
        }
        size += getValueSize(val, column.type());
        cnt++;
    }
    return new ObjectStatistic(cnt, size);
}
Also used : Column(org.apache.ignite.internal.schema.Column)

Example 32 with Column

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

the class SchemaDescriptorConverter method convert.

/**
 * Build schema descriptor by table schema.
 *
 * @param schemaVer Schema version.
 * @param tblCfg    Table schema.
 * @return SchemaDescriptor.
 */
public static SchemaDescriptor convert(int schemaVer, TableDefinition tblCfg) {
    Set<String> keyColumnsNames = tblCfg.keyColumns();
    List<Column> keyCols = new ArrayList<>(keyColumnsNames.size());
    List<Column> valCols = new ArrayList<>(tblCfg.columns().size() - keyColumnsNames.size());
    int idx = 0;
    for (ColumnDefinition col : tblCfg.columns()) {
        if (keyColumnsNames.contains(col.name())) {
            keyCols.add(convert(idx, col));
        } else {
            valCols.add(convert(idx, col));
        }
        idx++;
    }
    return new SchemaDescriptor(schemaVer, keyCols.toArray(Column[]::new), tblCfg.colocationColumns().toArray(String[]::new), valCols.toArray(Column[]::new));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ArrayList(java.util.ArrayList) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition)

Example 33 with Column

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

the class UpgradingRowAdapter method doubleValueBoxed.

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

Example 34 with Column

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

the class UpgradingRowAdapter method longValueBoxed.

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

Example 35 with Column

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

the class UpgradingRowAdapter method doubleValue.

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

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