Search in sources :

Example 1 with FAILING_TOP_LEVEL_INJECTOR

use of com.hazelcast.jet.sql.impl.inject.UpsertInjector.FAILING_TOP_LEVEL_INJECTOR 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)

Aggregations

DeserializedSchemaBoundGenericRecordBuilder (com.hazelcast.internal.serialization.impl.compact.DeserializedSchemaBoundGenericRecordBuilder)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 FAILING_TOP_LEVEL_INJECTOR (com.hazelcast.jet.sql.impl.inject.UpsertInjector.FAILING_TOP_LEVEL_INJECTOR)1 FieldKind (com.hazelcast.nio.serialization.FieldKind)1 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)1 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)1 QueryException (com.hazelcast.sql.impl.QueryException)1 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)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 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 NotThreadSafe (javax.annotation.concurrent.NotThreadSafe)1