Search in sources :

Example 21 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getArrayOfNullableBoolean.

@Nullable
@Override
public Boolean[] getArrayOfNullableBoolean(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case ARRAY_OF_BOOLEAN:
            return getVariableSize(fieldName, ARRAY_OF_BOOLEAN, CompactInternalGenericRecord::readBooleanBitsAsNullables);
        case ARRAY_OF_NULLABLE_BOOLEAN:
            return getArrayOfVariableSize(fieldName, ARRAY_OF_NULLABLE_BOOLEAN, Boolean[]::new, ObjectDataInput::readBoolean);
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nullable(javax.annotation.Nullable)

Example 22 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class FieldsUtil method resolveCompact.

/**
 * Resolve the list of fields from a schema {@link com.hazelcast.internal.serialization.impl.compact.Schema},
 * along with their {@link QueryDataType}.
 */
@Nonnull
public static SortedMap<String, QueryDataType> resolveCompact(@Nonnull Schema schema) {
    SortedMap<String, QueryDataType> fields = new TreeMap<>();
    // Add regular fields.
    for (String name : schema.getFieldNames()) {
        FieldKind compactKind = schema.getField(name).getKind();
        QueryDataType type = resolveType(compactKind);
        fields.putIfAbsent(name, type);
    }
    return fields;
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) FieldTypeToFieldKind(com.hazelcast.internal.serialization.impl.portable.FieldTypeToFieldKind) FieldKind(com.hazelcast.nio.serialization.FieldKind) TreeMap(java.util.TreeMap) Nonnull(javax.annotation.Nonnull)

Example 23 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class CompactUpsertTarget method createInjector.

@Override
@SuppressWarnings("checkstyle:ReturnCount")
public UpsertInjector createInjector(@Nullable String path, QueryDataType queryDataType) {
    if (path == null) {
        return FAILING_TOP_LEVEL_INJECTOR;
    }
    boolean hasField = schema.hasField(path);
    if (!hasField) {
        return value -> {
            throw QueryException.error("Unable to inject a non-null value to \"" + path + "\"");
        };
    }
    FieldKind kind = schema.getField(path).getKind();
    switch(kind) {
        case STRING:
            return value -> builder.setString(path, (String) value);
        case NULLABLE_BOOLEAN:
            return value -> builder.setNullableBoolean(path, (Boolean) value);
        case NULLABLE_INT8:
            return value -> builder.setNullableInt8(path, (Byte) value);
        case NULLABLE_INT16:
            return value -> builder.setNullableInt16(path, (Short) value);
        case NULLABLE_INT32:
            return value -> builder.setNullableInt32(path, (Integer) value);
        case NULLABLE_INT64:
            return value -> builder.setNullableInt64(path, (Long) value);
        case DECIMAL:
            return value -> builder.setDecimal(path, (BigDecimal) value);
        case NULLABLE_FLOAT32:
            return value -> builder.setNullableFloat32(path, (Float) value);
        case NULLABLE_FLOAT64:
            return value -> builder.setNullableFloat64(path, (Double) value);
        case TIME:
            return value -> builder.setTime(path, (LocalTime) value);
        case DATE:
            return value -> builder.setDate(path, (LocalDate) value);
        case TIMESTAMP:
            return value -> builder.setTimestamp(path, (LocalDateTime) value);
        case TIMESTAMP_WITH_TIMEZONE:
            return value -> builder.setTimestampWithTimezone(path, (OffsetDateTime) value);
        default:
            throw QueryException.error(kind + " kind is not supported in SQL with Compact format!");
    }
}
Also used : GenericRecord(com.hazelcast.nio.serialization.GenericRecord) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) LocalDateTime(java.time.LocalDateTime) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) BigDecimal(java.math.BigDecimal) FieldKind(com.hazelcast.nio.serialization.FieldKind) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) LocalTime(java.time.LocalTime) GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) DeserializedSchemaBoundGenericRecordBuilder(com.hazelcast.internal.serialization.impl.compact.DeserializedSchemaBoundGenericRecordBuilder) QueryException(com.hazelcast.sql.impl.QueryException) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) FAILING_TOP_LEVEL_INJECTOR(com.hazelcast.jet.sql.impl.inject.UpsertInjector.FAILING_TOP_LEVEL_INJECTOR) FieldKind(com.hazelcast.nio.serialization.FieldKind)

Example 24 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class DeserializedGenericRecord method getArrayOfInt16.

@Override
@Nullable
public short[] getArrayOfInt16(@Nonnull String fieldName) {
    FieldKind fieldKind = check(fieldName, ARRAY_OF_INT16, ARRAY_OF_NULLABLE_INT16);
    if (fieldKind == ARRAY_OF_NULLABLE_INT16) {
        Short[] array = (Short[]) objects.get(fieldName);
        short[] result = new short[array.length];
        for (int i = 0; i < array.length; i++) {
            if (array[i] == null) {
                throw exceptionForUnexpectedNullValueInArray(fieldName, "Int16");
            }
            result[i] = array[i];
        }
        return result;
    }
    return (short[]) objects.get(fieldName);
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) Nullable(javax.annotation.Nullable)

Example 25 with FieldKind

use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.

the class DeserializedGenericRecord method getArrayOfInt64.

@Override
@Nullable
public long[] getArrayOfInt64(@Nonnull String fieldName) {
    FieldKind fieldKind = check(fieldName, ARRAY_OF_INT64, ARRAY_OF_NULLABLE_INT64);
    if (fieldKind == ARRAY_OF_NULLABLE_INT64) {
        Long[] array = (Long[]) objects.get(fieldName);
        long[] result = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            if (array[i] == null) {
                throw exceptionForUnexpectedNullValueInArray(fieldName, "Int64");
            }
            result[i] = array[i];
        }
        return result;
    }
    return (long[]) objects.get(fieldName);
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) Nullable(javax.annotation.Nullable)

Aggregations

FieldKind (com.hazelcast.nio.serialization.FieldKind)40 Nullable (javax.annotation.Nullable)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)16 IOException (java.io.IOException)14 Nonnull (javax.annotation.Nonnull)3 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)2 DeserializedSchemaBoundGenericRecordBuilder (com.hazelcast.internal.serialization.impl.compact.DeserializedSchemaBoundGenericRecordBuilder)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 FieldTypeToFieldKind (com.hazelcast.internal.serialization.impl.portable.FieldTypeToFieldKind)1 FAILING_TOP_LEVEL_INJECTOR (com.hazelcast.jet.sql.impl.inject.UpsertInjector.FAILING_TOP_LEVEL_INJECTOR)1 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)1 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)1 QueryException (com.hazelcast.sql.impl.QueryException)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1