本文整理了Java中org.apache.kafka.connect.data.Struct.getInt32()
方法的一些代码示例,展示了Struct.getInt32()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Struct.getInt32()
方法的具体详情如下:
包路径:org.apache.kafka.connect.data.Struct
类名称:Struct
方法名:getInt32
[英]Equivalent to calling #get(String) and casting the result to a Integer.
[中]相当于调用#get(String)并将结果转换为整数。
代码示例来源:origin: debezium/debezium
/**
* Decodes the encoded value - see {@link #fromLogical(Schema, BigDecimal)} for encoding format
*
* @param value the encoded value
* @return the decoded value
*/
public static SpecialValueDecimal toLogical(final Struct value) {
return new SpecialValueDecimal(new BigDecimal(new BigInteger(value.getBytes(VALUE_FIELD)), value.getInt32(SCALE_FIELD)));
}
}
代码示例来源:origin: debezium/debezium
private void assertMediumUnsigned(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting int-32 since we are dealing with unsignd-mediumint
//So Unsigned MEDIUMINT would be an int32 type
assertThat(after.schema().field("c1").schema()).isEqualTo(Schema.INT32_SCHEMA);
assertThat(after.schema().field("c2").schema()).isEqualTo(Schema.INT32_SCHEMA);
//Validate the schema first, we are expecting int-32 since we are dealing with signed-mediumint.
//So Signed MEDIUMINT would be an INT32 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT32_SCHEMA);
//Validate candidates values
switch (i) {
case 1:
assertThat(after.getInt32("c1")).isEqualTo(16777215);
assertThat(after.getInt32("c2")).isEqualTo(16777215);
assertThat(after.getInt32("c3")).isEqualTo(8388607);
break;
case 2:
assertThat(after.getInt32("c1")).isEqualTo(10777215);
assertThat(after.getInt32("c2")).isEqualTo(10777215);
assertThat(after.getInt32("c3")).isEqualTo(-6388607);
break;
case 3:
assertThat(after.getInt32("c1")).isEqualTo(0);
assertThat(after.getInt32("c2")).isEqualTo(0);
assertThat(after.getInt32("c3")).isEqualTo(-8388608);
}
}
代码示例来源:origin: debezium/debezium
private void assertSmallUnsigned(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting int-32 since we are dealing with unsignd-smallint
//So Unsigned SMALLINT would be an int32 type
assertThat(after.schema().field("c1").schema()).isEqualTo(Schema.INT32_SCHEMA);
assertThat(after.schema().field("c2").schema()).isEqualTo(Schema.INT32_SCHEMA);
//Validate the schema first, we are expecting int-16 since we are dealing with signed-smallint.
//So Signed SMALLINT would be an INT16 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT16_SCHEMA);
//Validate candidates values
switch (i) {
case 1:
assertThat(after.getInt32("c1")).isEqualTo(65535);
assertThat(after.getInt32("c2")).isEqualTo(65535);
assertThat(after.getInt16("c3")).isEqualTo((short)32767);
break;
case 2:
assertThat(after.getInt32("c1")).isEqualTo(45535);
assertThat(after.getInt32("c2")).isEqualTo(45535);
assertThat(after.getInt16("c3")).isEqualTo((short)-12767);
break;
case 3:
assertThat(after.getInt32("c1")).isEqualTo(0);
assertThat(after.getInt32("c2")).isEqualTo(0);
assertThat(after.getInt16("c3")).isEqualTo((short)-32768);
}
}
代码示例来源:origin: debezium/debezium
private void assertGeomRecord(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
Testing.debug(after);
assertThat(i).isNotNull();
if (i == 1) {
// INSERT INTO dbz_507_geometry VALUES (1, ST_GeomFromText('POINT(1 1)', 4326), ST_GeomFromText('LINESTRING(0 0, 1 1)', 3187), ST_GeomFromText('POLYGON((0 0, 1 1, 1 0, 0 0))'), ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 1), LINESTRING(0 0, 1 1))', 4326));
assertThat(after.getStruct("geom").getInt32("srid")).isEqualTo(4326);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("geom").getBytes("wkb"))).isEqualTo("0101000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("linestring").getInt32("srid")).isEqualTo(3187);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("linestring").getBytes("wkb"))).isEqualTo("01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("polygon").getInt32("srid")).isEqualTo(null);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("polygon").getBytes("wkb"))).isEqualTo("0103000000010000000400000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000");
assertThat(after.getStruct("collection").getInt32("srid")).isEqualTo(4326);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("collection").getBytes("wkb"))).isEqualTo("0107000000020000000101000000000000000000F03F000000000000F03F01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
} else if (i == 2) {
// INSERT INTO dbz_507_geometry VALUES (2, ST_GeomFromText('LINESTRING(0 0, 1 1)'), NULL, NULL, NULL);
assertThat(after.getStruct("geom").getInt32("srid")).isEqualTo(null);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("geom").getBytes("wkb"))).isEqualTo("01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("linestring")).isNull();
assertThat(after.getStruct("polygon")).isNull();
assertThat(after.getStruct("collection")).isNull();
}
}
代码示例来源:origin: debezium/debezium
assertThat( ((Struct) records.recordsForTopic(DATABASE.topicForTable("products")).get(0).key()).getInt32("id")).isEqualTo(108);
assertThat( ((Struct) records.recordsForTopic(DATABASE.topicForTable("products")).get(1).key()).getInt32("id")).isEqualTo(109);
assertThat( ((Struct) records.recordsForTopic(DATABASE.topicForTable("products_on_hand")).get(0).key()).getInt32("product_id")).isEqualTo(108);
assertThat( ((Struct) records.recordsForTopic(DATABASE.topicForTable("products_on_hand")).get(1).key()).getInt32("product_id")).isEqualTo(109);
代码示例来源:origin: debezium/debezium
private void assertPoint(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
Testing.debug(after);
assertThat(i).isNotNull();
Double expectedX = after.getFloat64("expected_x");
Double expectedY = after.getFloat64("expected_y");
Integer expectedSrid = after.getInt32("expected_srid");
if (after.getStruct("point") != null) {
Double actualX = after.getStruct("point").getFloat64("x");
Double actualY = after.getStruct("point").getFloat64("y");
Integer actualSrid = after.getStruct("point").getInt32("srid");
//Validate the values
databaseDifferences.geometryAssertPoints(expectedX, expectedY, actualX, actualY);
assertThat(actualSrid).isEqualTo(expectedSrid);
//Test WKB
Point point = (Point) WkbGeometryReader.readGeometry(new ByteReader((byte[]) after.getStruct("point")
.get("wkb")));
databaseDifferences.geometryAssertPoints(expectedX, expectedY, point.getX(), point.getY());
} else if (expectedX != null) {
Assert.fail("Got a null geometry but didn't expect to");
}
}
代码示例来源:origin: debezium/debezium
assertThat( ((Struct) records.recordsForTopic(DATABASE.topicForTable("products")).get(0).key()).getInt32("id")).isEqualTo(108);
assertThat( ((Struct) records.recordsForTopic(DATABASE.topicForTable("products")).get(1).key()).getInt32("id")).isEqualTo(109);
代码示例来源:origin: debezium/debezium
if (record.topic().endsWith("dbz_126_jsontable")) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
String json = after.getString("json");
代码示例来源:origin: debezium/debezium
if (record.topic().endsWith("dbz_126_jsontable")) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
String json = after.getString("json");
代码示例来源:origin: debezium/debezium
@Test
public void shouldReturnRecordedOffsetForUsedReplicaName() {
Document event = new Document().append("ts", new BsonTimestamp(100, 2))
.append("h", Long.valueOf(1987654321))
.append("ns", "dbA.collectA");
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
source.offsetStructForEvent(REPLICA_SET_NAME, event);
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(true);
Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(100);
assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(2);
assertThat(offset.get(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
assertThat(ts.getTime()).isEqualTo(100);
assertThat(ts.getInc()).isEqualTo(2);
Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(100);
assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(2);
assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isNull();
}
代码示例来源:origin: debezium/debezium
@Test
public void shouldReturnRecordedOffsetForUsedReplicaNameDuringInitialSync() {
source.startInitialSync(REPLICA_SET_NAME);
Document event = new Document().append("ts", new BsonTimestamp(100, 2))
.append("h", Long.valueOf(1987654321))
.append("ns", "dbA.collectA");
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
source.offsetStructForEvent(REPLICA_SET_NAME, event);
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(true);
Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(100);
assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(2);
assertThat(offset.get(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
assertThat(ts.getTime()).isEqualTo(100);
assertThat(ts.getInc()).isEqualTo(2);
Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(100);
assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(2);
assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isEqualTo(true);
}
代码示例来源:origin: debezium/debezium
assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(100);
assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(2);
assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
代码示例来源:origin: debezium/debezium
@Test
public void shouldReturnOffsetForUnusedReplicaName() {
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(0);
assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(0);
assertThat(offset.get(SourceInfo.OPERATION_ID)).isNull();
BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
assertThat(ts.getTime()).isEqualTo(0);
assertThat(ts.getInc()).isEqualTo(0);
Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(0);
assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(0);
assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isNull();
assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isNull();
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
}
代码示例来源:origin: debezium/debezium
assertThat(recordSource.getInt32(SourceInfo.BINLOG_ROW_IN_EVENT_OFFSET_KEY)).isEqualTo(row);
assertThat(recordSource.getString(SourceInfo.BINLOG_FILENAME_OFFSET_KEY)).isEqualTo(FILENAME);
if (source.gtidSet() != null) {
代码示例来源:origin: debezium/debezium
@Test
public void shouldReturnOffsetForUnusedReplicaNameDuringInitialSync() {
source.startInitialSync(REPLICA_SET_NAME);
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(0);
assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(0);
assertThat(offset.get(SourceInfo.OPERATION_ID)).isNull();
BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
assertThat(ts.getTime()).isEqualTo(0);
assertThat(ts.getInc()).isEqualTo(0);
Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(0);
assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(0);
assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isNull();
assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isEqualTo(true);
assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
}
代码示例来源:origin: debezium/debezium
Integer c2 = after.getInt32("c2");
long expectedMillis = Duration.ofHours(17).plusMinutes(51).plusSeconds(4).plusMillis(780).toMillis();
assertThat(c2).isEqualTo((int)expectedMillis);
代码示例来源:origin: debezium/debezium
private void assertBigintUnsignedPrecise(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting org.apache.kafka.connect.data.Decimal:Byte since we are dealing with unsignd-bigint
//So Unsigned BIGINY would be an int32 type
assertThat(after.schema().field("c1").schema()).isEqualTo(Decimal.builder(0).schema());
assertThat(after.schema().field("c2").schema()).isEqualTo(Decimal.builder(0).schema());
//Validate the schema first, we are expecting int-64 since we are dealing with signed-bigint.
//So Signed BIGINT would be an INT64 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT64_SCHEMA);
//Validate candidates values
switch (i) {
case 1:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("18446744073709551615"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("18446744073709551615"));
assertThat(after.getInt64("c3")).isEqualTo(9223372036854775807L);
break;
case 2:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("14446744073709551615"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("14446744073709551615"));
assertThat(after.getInt64("c3")).isEqualTo(-1223372036854775807L);
break;
case 3:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("0"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("0"));
assertThat(after.getInt64("c3")).isEqualTo(-9223372036854775808L);
}
}
代码示例来源:origin: debezium/debezium
private void assertIntUnsigned(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
assertThat(after.getInt64("c1")).isEqualTo(4294967295L);
assertThat(after.getInt64("c2")).isEqualTo(4294967295L);
assertThat(after.getInt32("c3")).isEqualTo(2147483647);
assertThat(after.getInt64("c4")).isEqualTo(4294967295L);
assertThat(after.getInt64("c5")).isEqualTo(4294967295L);
assertThat(after.getInt32("c6")).isEqualTo(2147483647);
break;
case 2:
assertThat(after.getInt64("c1")).isEqualTo(3294967295L);
assertThat(after.getInt64("c2")).isEqualTo(3294967295L);
assertThat(after.getInt32("c3")).isEqualTo(-1147483647);
assertThat(after.getInt64("c4")).isEqualTo(3294967295L);
assertThat(after.getInt64("c5")).isEqualTo(3294967295L);
assertThat(after.getInt32("c6")).isEqualTo(-1147483647);
break;
case 3:
assertThat(after.getInt64("c1")).isEqualTo(0L);
assertThat(after.getInt64("c2")).isEqualTo(0L);
assertThat(after.getInt32("c3")).isEqualTo(-2147483648);
assertThat(after.getInt64("c4")).isEqualTo(0L);
assertThat(after.getInt64("c5")).isEqualTo(0L);
assertThat(after.getInt32("c6")).isEqualTo(-2147483648);
代码示例来源:origin: debezium/debezium
private void assertBigintUnsignedLong(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting int-64 since we have forced Long mode for BIGINT UNSIGNED
assertThat(after.schema().field("c1").schema()).isEqualTo(Schema.INT64_SCHEMA);
assertThat(after.schema().field("c2").schema()).isEqualTo(Schema.INT64_SCHEMA);
//Validate the schema first, we are expecting int-64 since we are dealing with signed-bigint.
//So Signed BIGINT would be an INT64 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT64_SCHEMA);
//Validate candidates values, note the loss in precision which is expected since BIGINT UNSIGNED cannot always be represented by
//a long datatype.
switch (i) {
case 1:
assertThat(after.getInt64("c1")).isEqualTo(-1L);
assertThat(after.getInt64("c2")).isEqualTo(-1L);
assertThat(after.getInt64("c3")).isEqualTo(9223372036854775807L);
break;
case 2:
assertThat(after.getInt64("c1")).isEqualTo(-4000000000000000001L);
assertThat(after.getInt64("c2")).isEqualTo(-4000000000000000001L);
assertThat(after.getInt64("c3")).isEqualTo(-1223372036854775807L);
break;
case 3:
assertThat(after.getInt64("c1")).isEqualTo(0L);
assertThat(after.getInt64("c2")).isEqualTo(0L);
assertThat(after.getInt64("c3")).isEqualTo(-9223372036854775808L);
}
}
代码示例来源:origin: debezium/debezium
private void assertTinyintUnsigned(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting int-16 since we are dealing with unsignd-tinyint
//So Unsigned TINYINT would be an INT16 type
assertThat(after.schema().field("c1").schema()).isEqualTo(Schema.INT16_SCHEMA);
assertThat(after.schema().field("c2").schema()).isEqualTo(Schema.INT16_SCHEMA);
//Validate the schema first, we are expecting int-16 since we are dealing with signed-tinyint.
// Note: the recommended mapping of Signed TINYINT is Short which is 16-bit. http://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/mapping.html
//So Signed TINYINT would be an INT16 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT16_SCHEMA);
//Validate candidates values
switch (i) {
case 1:
assertThat(after.getInt16("c1")).isEqualTo((short)255);
assertThat(after.getInt16("c2")).isEqualTo((short)(255));
assertThat(after.getInt16("c3")).isEqualTo((short)127);
break;
case 2:
assertThat(after.getInt16("c1")).isEqualTo((short)155);
assertThat(after.getInt16("c2")).isEqualTo((short)155);
assertThat(after.getInt16("c3")).isEqualTo((short)-100);
break;
case 3:
assertThat(after.getInt16("c1")).isEqualTo((short)0);
assertThat(after.getInt16("c2")).isEqualTo((short)0);
assertThat(after.getInt16("c3")).isEqualTo((short)-128);
}
}
内容来源于网络,如有侵权,请联系作者删除!