Search in sources :

Example 6 with InternalGenericRecord

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

the class SqlPortableTest method test_allTypes.

@Test
public void test_allTypes() throws IOException {
    String from = randomName();
    TestAllTypesSqlConnector.create(sqlService, from);
    String to = randomName();
    sqlService.execute("CREATE MAPPING " + to + ' ' + "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 + "'='" + ALL_TYPES_FACTORY_ID + '\'' + ", '" + OPTION_VALUE_CLASS_ID + "'='" + ALL_TYPES_CLASS_ID + '\'' + ", '" + OPTION_VALUE_CLASS_VERSION + "'='" + ALL_TYPES_CLASS_VERSION + '\'' + ")");
    sqlService.execute("SINK INTO " + to + " " + "SELECT 13, 'a', string, \"boolean\", byte, short, \"int\", long, \"float\", \"double\", \"decimal\", " + "\"time\", \"date\", \"timestamp\", timestampTz, \"object\" " + "FROM " + from + " f");
    InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(randomEntryFrom(to).getValue());
    assertThat(valueRecord.getString("string")).isEqualTo("string");
    assertThat(valueRecord.getChar("character")).isEqualTo('a');
    assertThat(valueRecord.getBoolean("boolean")).isTrue();
    assertThat(valueRecord.getInt8("byte")).isEqualTo((byte) 127);
    assertThat(valueRecord.getInt16("short")).isEqualTo((short) 32767);
    assertThat(valueRecord.getInt32("int")).isEqualTo(2147483647);
    assertThat(valueRecord.getInt64("long")).isEqualTo(9223372036854775807L);
    assertThat(valueRecord.getFloat32("float")).isEqualTo(1234567890.1F);
    assertThat(valueRecord.getFloat64("double")).isEqualTo(123451234567890.1D);
    assertThat(valueRecord.getDecimal("decimal")).isEqualTo(new BigDecimal("9223372036854775.123"));
    assertThat(valueRecord.getTime("time")).isEqualTo(LocalTime.of(12, 23, 34));
    assertThat(valueRecord.getDate("date")).isEqualTo(LocalDate.of(2020, 4, 15));
    assertThat(valueRecord.getTimestamp("timestamp")).isEqualTo(LocalDateTime.of(2020, 4, 15, 12, 23, 34, 1_000_000));
    assertThat(valueRecord.getTimestampWithTimezone("timestampTz")).isEqualTo(OffsetDateTime.of(2020, 4, 15, 12, 23, 34, 200_000_000, UTC));
    assertThat(valueRecord.getGenericRecord("object")).isNull();
    assertRowsAnyOrder("SELECT * FROM " + to, singletonList(new Row(13, "a", "string", true, (byte) 127, (short) 32767, 2147483647, 9223372036854775807L, 1234567890.1F, 123451234567890.1D, new BigDecimal("9223372036854775.123"), LocalTime.of(12, 23, 34), LocalDate.of(2020, 4, 15), LocalDateTime.of(2020, 4, 15, 12, 23, 34, 1_000_000), OffsetDateTime.of(2020, 4, 15, 12, 23, 34, 200_000_000, UTC), null)));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with InternalGenericRecord

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

the class SqlPortableTest method test_derivesClassDefinitionFromSchema.

@Test
public void test_derivesClassDefinitionFromSchema() throws IOException {
    String from = randomName();
    TestAllTypesSqlConnector.create(sqlService, from);
    String to = randomName();
    sqlService.execute("CREATE MAPPING " + to + " (" + "id INT EXTERNAL NAME \"__key.id\"" + ", string VARCHAR" + ", \"boolean\" BOOLEAN" + ", byte TINYINT" + ", short SMALLINT" + ", \"int\" INT" + ", long BIGINT" + ", \"float\" REAL" + ", \"double\" DOUBLE" + ", \"decimal\" DECIMAL" + ", \"time\" TIME" + ", \"date\" DATE" + ", \"timestamp\" TIMESTAMP" + ", timestampTz TIMESTAMP WITH TIME ZONE" + ") 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 + "'='" + 997 + '\'' + ", '" + OPTION_VALUE_CLASS_ID + "'='" + 998 + '\'' + ", '" + OPTION_VALUE_CLASS_VERSION + "'='" + 999 + '\'' + ")");
    sqlService.execute("SINK INTO " + to + " SELECT " + "13" + ", string " + ", \"boolean\" " + ", byte " + ", short " + ", \"int\" " + ", long " + ", \"float\" " + ", \"double\" " + ", \"decimal\" " + ", \"time\" " + ", \"date\" " + ", \"timestamp\" " + ", timestampTz " + "FROM " + from);
    InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(randomEntryFrom(to).getValue());
    assertThat(valueRecord.getString("string")).isEqualTo("string");
    assertThat(valueRecord.getBoolean("boolean")).isTrue();
    assertThat(valueRecord.getInt8("byte")).isEqualTo((byte) 127);
    assertThat(valueRecord.getInt16("short")).isEqualTo((short) 32767);
    assertThat(valueRecord.getInt32("int")).isEqualTo(2147483647);
    assertThat(valueRecord.getInt64("long")).isEqualTo(9223372036854775807L);
    assertThat(valueRecord.getFloat32("float")).isEqualTo(1234567890.1F);
    assertThat(valueRecord.getFloat64("double")).isEqualTo(123451234567890.1D);
    assertThat(valueRecord.getDecimal("decimal")).isEqualTo(new BigDecimal("9223372036854775.123"));
    assertThat(valueRecord.getTime("time")).isEqualTo(LocalTime.of(12, 23, 34));
    assertThat(valueRecord.getDate("date")).isEqualTo(LocalDate.of(2020, 4, 15));
    assertThat(valueRecord.getTimestamp("timestamp")).isEqualTo(LocalDateTime.of(2020, 4, 15, 12, 23, 34, 1_000_000));
    assertThat(valueRecord.getTimestampWithTimezone("timestampTz")).isEqualTo(OffsetDateTime.of(2020, 4, 15, 12, 23, 34, 200_000_000, UTC));
    assertRowsAnyOrder("SELECT * FROM " + to, singletonList(new Row(13, "string", true, (byte) 127, (short) 32767, 2147483647, 9223372036854775807L, 1234567890.1f, 123451234567890.1, new BigDecimal("9223372036854775.123"), LocalTime.of(12, 23, 34), LocalDate.of(2020, 4, 15), LocalDateTime.of(2020, 4, 15, 12, 23, 34, 1_000_000), OffsetDateTime.of(2020, 4, 15, 12, 23, 34, 200_000_000, UTC))));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 8 with InternalGenericRecord

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

the class GenericRecordTest method testGetFieldKindThrowsExceptionWhenFieldDoesNotExist.

@Test
public void testGetFieldKindThrowsExceptionWhenFieldDoesNotExist() throws IOException {
    GenericRecord record = compact("test").build();
    assertThrows(IllegalArgumentException.class, () -> {
        record.getFieldKind("doesNotExist");
    });
    InternalSerializationService serializationService = (InternalSerializationService) createSerializationService();
    Data data = serializationService.toData(record);
    InternalGenericRecord internalGenericRecord = serializationService.readAsInternalGenericRecord(data);
    assertThrows(IllegalArgumentException.class, () -> {
        internalGenericRecord.getFieldKind("doesNotExist");
    });
}
Also used : Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with InternalGenericRecord

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

the class SqlPortableTest method test_fieldsMapping.

@Test
public void test_fieldsMapping() throws IOException {
    String name = randomName();
    sqlService.execute("CREATE MAPPING " + name + " (" + "key_id INT EXTERNAL NAME \"__key.id\"" + ", value_id INT EXTERNAL NAME \"this.id\"" + ") 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 + " (value_id, key_id) VALUES (2, 1)");
    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(2);
    assertRowsAnyOrder("SELECT key_id, value_id FROM " + name, singletonList(new Row(1, 2)));
}
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 10 with InternalGenericRecord

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

the class SqlPortableTest method test_nulls.

@Test
public void test_nulls() 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 + " VALUES (1, null)");
    Entry<Data, Data> entry = randomEntryFrom(name);
    InternalGenericRecord keyRecord = serializationService.readAsInternalGenericRecord(entry.getKey());
    assertThat(keyRecord.getInt32("id")).isEqualTo(1);
    InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(entry.getValue());
    // default portable value
    assertThat(valueRecord.getInt32("id")).isEqualTo(0);
    assertThat(valueRecord.getString("name")).isNull();
    assertRowsAnyOrder("SELECT * FROM " + name, singletonList(new Row(1, 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)

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