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