Search in sources :

Example 1 with MarshallerException

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

the class KeyValueViewImpl method marshal.

/**
 * Marshal keys to a row.
 *
 * @param keys Key objects.
 * @return Binary rows.
 */
@NotNull
public Collection<BinaryRow> marshal(@NotNull Collection<K> keys) {
    final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> keyRows = new ArrayList<>(keys.size());
    try {
        for (K key : keys) {
            final BinaryRow keyRow = marsh.marshal(Objects.requireNonNull(key));
            keyRows.add(keyRow);
        }
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
    return keyRows;
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MarshallerException

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

the class KeyValueViewImpl method unmarshalPairs.

/**
 * Marshal key-value pairs.
 *
 * @param rows Binary rows.
 * @return Key-value pairs.
 */
@NotNull
public Map<K, V> unmarshalPairs(Collection<BinaryRow> rows) {
    if (rows.isEmpty()) {
        return Collections.emptyMap();
    }
    final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
    Map<K, V> pairs = new HashMap<>(rows.size());
    try {
        for (Row row : schemaReg.resolve(rows)) {
            if (row != null) {
                pairs.put(marsh.unmarshalKey(row), marsh.unmarshalValue(row));
            }
        }
        return pairs;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MarshallerException

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

the class RecordViewImpl method unmarshal.

/**
 * Unmarshal records.
 *
 * @param rows Row collection.
 * @return Records collection.
 */
@NotNull
public Collection<R> unmarshal(Collection<BinaryRow> rows) {
    if (rows.isEmpty()) {
        return Collections.emptyList();
    }
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<R> recs = new ArrayList<>(rows.size());
    try {
        for (Row row : schemaReg.resolve(rows)) {
            if (row != null) {
                recs.add(marsh.unmarshal(row));
            }
        }
        return recs;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with MarshallerException

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

the class RecordViewImpl method marshalKeys.

/**
 * Marshal key-records.
 *
 * @param recs Records collection.
 * @return Binary rows collection.
 */
private Collection<BinaryRow> marshalKeys(@NotNull Collection<R> recs) {
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(recs.size());
    try {
        for (R rec : recs) {
            final BinaryRow row = marsh.marshalKey(Objects.requireNonNull(rec));
            rows.add(row);
        }
        return rows;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Example 5 with MarshallerException

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

the class RecordViewImpl method marshal.

/**
 * Marshal records.
 *
 * @param recs Records collection.
 * @return Binary rows collection.
 */
private Collection<BinaryRow> marshal(@NotNull Collection<R> recs) {
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(recs.size());
    try {
        for (R rec : recs) {
            final BinaryRow row = marsh.marshal(Objects.requireNonNull(rec));
            rows.add(row);
        }
        return rows;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Aggregations

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)9 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 IgniteException (org.apache.ignite.lang.IgniteException)9 ArrayList (java.util.ArrayList)6 Row (org.apache.ignite.internal.schema.row.Row)5 NotNull (org.jetbrains.annotations.NotNull)5 HashMap (java.util.HashMap)2 Map (java.util.Map)1