Search in sources :

Example 1 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class PortableGetter method getValue.

@Override
Object getValue(Object target, String fieldPath) throws Exception {
    InternalGenericRecord record;
    if (target instanceof PortableGenericRecord) {
        record = (InternalGenericRecord) target;
    } else {
        record = serializationService.readAsInternalGenericRecord((Data) target);
    }
    GenericRecordQueryReader reader = new GenericRecordQueryReader(record);
    return reader.read(fieldPath);
}
Also used : PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord)

Example 2 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class CompactGetter method getValue.

@Override
Object getValue(Object target, String fieldPath) throws Exception {
    InternalGenericRecord record;
    if (target instanceof CompactInternalGenericRecord) {
        record = (InternalGenericRecord) target;
    } else {
        record = serializationService.readAsInternalGenericRecord((Data) target);
    }
    GenericRecordQueryReader reader = new GenericRecordQueryReader(record);
    return reader.read(fieldPath);
}
Also used : CompactInternalGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactInternalGenericRecord) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) CompactInternalGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactInternalGenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord)

Example 3 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class PortableUpsertTargetTest method when_typeIsObject_then_allValuesAreAllowed.

@Test
@Parameters(method = "objectClassDefinitions")
public void when_typeIsObject_then_allValuesAreAllowed(ClassDefinition classDefinition, Object value, Function<InternalGenericRecord, Object> valueExtractor) throws IOException {
    UpsertTarget target = new PortableUpsertTarget(classDefinition);
    UpsertInjector injector = target.createInjector("object", QueryDataType.OBJECT);
    target.init();
    injector.set(value);
    Object portable = target.conclude();
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    InternalGenericRecord record = ss.readAsInternalGenericRecord(ss.toData(portable));
    assertThat(valueExtractor.apply(record)).isEqualTo(value);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 4 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class SqlCompactTest method test_insertNulls.

@Test
public void test_insertNulls() throws IOException {
    String name = randomName();
    sqlService.execute("CREATE MAPPING " + name + " (" + "__key INT " + ", b BOOLEAN " + ", st VARCHAR " + ", bt TINYINT " + ", s SMALLINT " + ", i INTEGER " + ", l BIGINT " + ", bd DECIMAL " + ", f REAL " + ", d DOUBLE " + ", t TIME " + ", dt DATE " + ", tmstmp TIMESTAMP " + ", tmstmpTz TIMESTAMP WITH TIME ZONE " + ") " + "TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='integer'" + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + PERSON_TYPE_NAME + '\'' + ")").updateCount();
    sqlService.execute("SINK INTO " + name + " VALUES (1, null, null, null, " + "null, null, null, null, null, null, null, null, null, null )").updateCount();
    Entry<Data, Data> entry = randomEntryFrom(name);
    InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(entry.getValue());
    assertThat(valueRecord.getNullableBoolean("b")).isNull();
    assertThat(valueRecord.getString("st")).isNull();
    assertThat(valueRecord.getNullableInt8("bt")).isNull();
    assertThat(valueRecord.getNullableInt16("s")).isNull();
    assertThat(valueRecord.getNullableInt32("i")).isNull();
    assertThat(valueRecord.getNullableInt64("l")).isNull();
    assertThat(valueRecord.getDecimal("bd")).isNull();
    assertThat(valueRecord.getNullableFloat32("f")).isNull();
    assertThat(valueRecord.getNullableFloat64("d")).isNull();
    assertThat(valueRecord.getTime("t")).isNull();
    assertThat(valueRecord.getDate("dt")).isNull();
    assertThat(valueRecord.getTimestamp("tmstmp")).isNull();
    assertThat(valueRecord.getTimestampWithTimezone("tmstmpTz")).isNull();
    assertRowsAnyOrder("SELECT * FROM " + name, singletonList(new Row(1, null, null, null, null, null, null, null, null, null, null, null, null, null)));
}
Also used : Data(com.hazelcast.internal.serialization.Data) SqlRow(com.hazelcast.sql.SqlRow) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) Test(org.junit.Test)

Example 5 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class SqlPortableTest method test_fieldsShadowing.

@Test
public void test_fieldsShadowing() throws IOException {
    String name = randomName();
    sqlService.execute("CREATE MAPPING " + name + ' ' + "TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + PORTABLE_FORMAT + '\'' + ", '" + OPTION_KEY_FACTORY_ID + "'='" + PERSON_ID_FACTORY_ID + '\'' + ", '" + OPTION_KEY_CLASS_ID + "'='" + PERSON_ID_CLASS_ID + '\'' + ", '" + OPTION_KEY_CLASS_VERSION + "'='" + PERSON_ID_CLASS_VERSION + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + PORTABLE_FORMAT + '\'' + ", '" + OPTION_VALUE_FACTORY_ID + "'='" + PERSON_FACTORY_ID + '\'' + ", '" + OPTION_VALUE_CLASS_ID + "'='" + PERSON_CLASS_ID + '\'' + ", '" + OPTION_VALUE_CLASS_VERSION + "'='" + PERSON_CLASS_VERSION + '\'' + ")");
    sqlService.execute("SINK INTO " + name + " (id, name) VALUES (1, 'Alice')");
    Entry<Data, Data> entry = randomEntryFrom(name);
    InternalGenericRecord keyRecord = serializationService.readAsInternalGenericRecord(entry.getKey());
    assertThat(keyRecord.getInt32("id")).isEqualTo(1);
    InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(entry.getValue());
    assertThat(valueRecord.getInt32("id")).isEqualTo(0);
    assertThat(valueRecord.getString("name")).isEqualTo("Alice");
    assertRowsAnyOrder("SELECT * FROM " + name, singletonList(new Row(1, "Alice")));
}
Also used : Data(com.hazelcast.internal.serialization.Data) SqlRow(com.hazelcast.sql.SqlRow) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) Test(org.junit.Test)

Aggregations

InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)18 Test (org.junit.Test)15 Data (com.hazelcast.internal.serialization.Data)10 SqlRow (com.hazelcast.sql.SqlRow)8 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)7 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)6 BigDecimal (java.math.BigDecimal)4 GenericRecordQueryReader (com.hazelcast.internal.serialization.impl.GenericRecordQueryReader)3 Parameters (junitparams.Parameters)3 CompactTestUtil.createCompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 CompactInternalGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactInternalGenericRecord)1 CompactTestUtil.createMainDTO (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO)1 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)1