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);
}
}
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;
}
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!");
}
}
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);
}
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);
}
Aggregations