use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.
the class SqlCompactTest 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 + " (" + " id INT EXTERNAL NAME \"__key.id\" " + ", \"character\" VARCHAR " + ", 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 + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_KEY_COMPACT_TYPE_NAME + "'='" + PERSON_ID_TYPE_NAME + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + ALL_TYPES_TYPE_NAME + '\'' + ")");
sqlService.execute("SINK INTO " + to + " SELECT 13, 'a', string, \"boolean\", byte, short, \"int\", long, " + "\"float\", \"double\", \"decimal\", \"time\", \"date\", \"timestamp\", timestampTz " + " FROM " + from + " f");
InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(randomEntryFrom(to).getValue());
assertThat(valueRecord.getString("string")).isEqualTo("string");
assertThat(valueRecord.getString("character")).isEqualTo("a");
assertThat(valueRecord.getNullableBoolean("boolean")).isTrue();
assertThat(valueRecord.getNullableInt8("byte")).isEqualTo((byte) 127);
assertThat(valueRecord.getNullableInt16("short")).isEqualTo((short) 32767);
assertThat(valueRecord.getNullableInt32("int")).isEqualTo(2147483647);
assertThat(valueRecord.getNullableInt64("long")).isEqualTo(9223372036854775807L);
assertThat(valueRecord.getNullableFloat32("float")).isEqualTo(1234567890.1F);
assertThat(valueRecord.getNullableFloat64("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, "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))));
}
use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.
the class SqlCompactTest 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 + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_KEY_COMPACT_TYPE_NAME + "'='" + PERSON_ID_TYPE_NAME + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + PERSON_TYPE_NAME + '\'' + ")");
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.getNullableInt32("id")).isEqualTo(1);
InternalGenericRecord valueRecord = serializationService.readAsInternalGenericRecord(entry.getValue());
assertThat(valueRecord.getNullableInt32("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 PortableUpsertTargetTest method test_set.
@Test
public void test_set() throws IOException {
ClassDefinition innerClassDefinition = new ClassDefinitionBuilder(4, 5, 6).build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addPortableField("null", innerClassDefinition).addPortableField("object", innerClassDefinition).addStringField("string").addCharField("character").addBooleanField("boolean").addByteField("byte").addShortField("short").addIntField("int").addLongField("long").addFloatField("float").addDoubleField("double").addDecimalField("decimal").addTimeField("time").addDateField("date").addTimestampField("timestamp").addTimestampWithTimezoneField("timestampTz").build();
UpsertTarget target = new PortableUpsertTarget(classDefinition);
UpsertInjector nullFieldInjector = target.createInjector("null", QueryDataType.OBJECT);
UpsertInjector objectFieldInjector = target.createInjector("object", QueryDataType.OBJECT);
UpsertInjector stringFieldInjector = target.createInjector("string", QueryDataType.VARCHAR);
UpsertInjector characterFieldInjector = target.createInjector("character", QueryDataType.VARCHAR_CHARACTER);
UpsertInjector booleanFieldInjector = target.createInjector("boolean", QueryDataType.BOOLEAN);
UpsertInjector byteFieldInjector = target.createInjector("byte", QueryDataType.TINYINT);
UpsertInjector shortFieldInjector = target.createInjector("short", QueryDataType.SMALLINT);
UpsertInjector intFieldInjector = target.createInjector("int", QueryDataType.INT);
UpsertInjector longFieldInjector = target.createInjector("long", QueryDataType.BIGINT);
UpsertInjector floatFieldInjector = target.createInjector("float", QueryDataType.REAL);
UpsertInjector doubleFieldInjector = target.createInjector("double", QueryDataType.DOUBLE);
UpsertInjector decimalFieldInjector = target.createInjector("decimal", QueryDataType.DECIMAL);
UpsertInjector timeFieldInjector = target.createInjector("time", QueryDataType.TIME);
UpsertInjector dateFieldInjector = target.createInjector("date", QueryDataType.DATE);
UpsertInjector timestampFieldInjector = target.createInjector("timestamp", QueryDataType.TIMESTAMP);
UpsertInjector timestampTzFieldInjector = target.createInjector("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME);
target.init();
nullFieldInjector.set(null);
objectFieldInjector.set(new PortableGenericRecordBuilder(innerClassDefinition).build());
stringFieldInjector.set("1");
characterFieldInjector.set('2');
booleanFieldInjector.set(true);
byteFieldInjector.set((byte) 3);
shortFieldInjector.set((short) 4);
intFieldInjector.set(5);
longFieldInjector.set(6L);
floatFieldInjector.set(7.1F);
doubleFieldInjector.set(7.2D);
decimalFieldInjector.set(new BigDecimal("8.1"));
timeFieldInjector.set(LocalTime.of(12, 23, 34));
dateFieldInjector.set(LocalDate.of(2021, 2, 9));
timestampFieldInjector.set(LocalDateTime.of(2021, 2, 9, 12, 23, 34, 1_000_000));
timestampTzFieldInjector.set(OffsetDateTime.of(2021, 2, 9, 12, 23, 34, 200_000_000, UTC));
Object portable = target.conclude();
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
InternalGenericRecord record = ss.readAsInternalGenericRecord(ss.toData(portable));
assertThat(record.getGenericRecord("null")).isNull();
assertThat(record.getGenericRecord("object")).isEqualTo(new PortableGenericRecordBuilder(innerClassDefinition).build());
assertThat(record.getString("string")).isEqualTo("1");
assertThat(record.getChar("character")).isEqualTo('2');
assertThat(record.getBoolean("boolean")).isEqualTo(true);
assertThat(record.getInt8("byte")).isEqualTo((byte) 3);
assertThat(record.getInt16("short")).isEqualTo((short) 4);
assertThat(record.getInt32("int")).isEqualTo(5);
assertThat(record.getInt64("long")).isEqualTo(6L);
assertThat(record.getFloat32("float")).isEqualTo(7.1F);
assertThat(record.getFloat64("double")).isEqualTo(7.2D);
assertThat(record.getDecimal("decimal")).isEqualTo(new BigDecimal("8.1"));
assertThat(record.getTime("time")).isEqualTo(LocalTime.of(12, 23, 34));
assertThat(record.getDate("date")).isEqualTo(LocalDate.of(2021, 2, 9));
assertThat(record.getTimestamp("timestamp")).isEqualTo(LocalDateTime.of(2021, 2, 9, 12, 23, 34, 1_000_000));
assertThat(record.getTimestampWithTimezone("timestampTz")).isEqualTo(OffsetDateTime.of(2021, 2, 9, 12, 23, 34, 200_000_000, UTC));
}
use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.
the class PortableUpsertTargetTest method when_injectNonExistingPropertyNullValue_then_succeeds.
@Test
public void when_injectNonExistingPropertyNullValue_then_succeeds() throws IOException {
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).build();
UpsertTarget target = new PortableUpsertTarget(classDefinition);
UpsertInjector injector = target.createInjector("field", QueryDataType.INT);
target.init();
injector.set(null);
Object portable = target.conclude();
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
InternalGenericRecord record = ss.readAsInternalGenericRecord(ss.toData(portable));
assertThat(record).isNotNull();
}
use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.
the class PortableUpsertTargetTest method when_doesNotInjectIntoPrimitive_then_insertsDefaultValue.
@Test
@Parameters(method = "primitiveClassDefinitions")
@SuppressWarnings("unused")
public void when_doesNotInjectIntoPrimitive_then_insertsDefaultValue(ClassDefinition classDefinition, QueryDataType type, Object defaultValue, Function<InternalGenericRecord, Object> valueExtractor) throws IOException {
UpsertTarget target = new PortableUpsertTarget(classDefinition);
target.init();
Object portable = target.conclude();
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
InternalGenericRecord record = ss.readAsInternalGenericRecord(ss.toData(portable));
assertThat(valueExtractor.apply(record)).isEqualTo(defaultValue);
}
Aggregations