当前位置: 首页>>代码示例>>Java>>正文


Java SourceRecord.value方法代码示例

本文整理汇总了Java中org.apache.kafka.connect.source.SourceRecord.value方法的典型用法代码示例。如果您正苦于以下问题:Java SourceRecord.value方法的具体用法?Java SourceRecord.value怎么用?Java SourceRecord.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.kafka.connect.source.SourceRecord的用法示例。


在下文中一共展示了SourceRecord.value方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testOptionalFieldMap

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void testOptionalFieldMap() {
    final Flatten<SourceRecord> xform = new Flatten.Value<>();
    xform.configure(Collections.<String, String>emptyMap());

    Map<String, Object> supportedTypes = new HashMap<>();
    supportedTypes.put("opt_int32", null);

    Map<String, Object> oneLevelNestedMap = Collections.singletonMap("B", (Object) supportedTypes);

    SourceRecord transformed = xform.apply(new SourceRecord(null, null,
            "topic", 0,
            null, oneLevelNestedMap));

    assertNull(transformed.valueSchema());
    assertTrue(transformed.value() instanceof Map);
    Map<String, Object> transformedMap = (Map<String, Object>) transformed.value();

    assertNull(transformedMap.get("B.opt_int32"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:FlattenTest.java

示例2: nestedRecord

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void nestedRecord() throws IOException, InterruptedException {
    Map<String, String> config = new HashMap<>();
    config.put(FluentdSourceConnectorConfig.FLUENTD_SCHEMAS_ENABLE, "false");
    task.start(config);
    Map<String, Double> version = new HashMap<>();
    version.put("stable", 0.12);
    version.put("unstable", 0.14);
    List<String> versions = new ArrayList<>();
    versions.add("v0.12");
    versions.add("v0.14");
    Map<String, Object> record = new HashMap<>();
    record.put("versions", versions);
    record.put("version", version);
    // {"versions": ["v0.12", "v0.14"], version: {"stable": 0.12, "unstable": 0.14}}
    fluency.emit("test", record);
    Thread.sleep(1000);
    List<SourceRecord> sourceRecords = task.poll();
    assertEquals(1, sourceRecords.size());
    SourceRecord sourceRecord = sourceRecords.get(0);
    assertNull(sourceRecord.key());
    Map<String, Object> value = (Map<String, Object>) sourceRecord.value();
    assertThat((List<String>) value.get("versions"), hasItems("v0.12", "v0.14"));
    assertEquals(value.get("version"), version);
}
 
开发者ID:fluent,项目名称:kafka-connect-fluentd,代码行数:26,代码来源:FluentdSourceTaskTest.java

示例3: simpleKeyValue

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void simpleKeyValue() {
    Map<String, String> map = new HashMap<>();
    map.put(FluentdSourceConnectorConfig.FLUENTD_SCHEMAS_ENABLE, "true");
    FluentdSourceConnectorConfig config = new FluentdSourceConnectorConfig(map);
    EventEntry eventEntry = EventEntry.of(
            Instant.now(),
            ValueFactory.newMap(
                    ValueFactory.newString("message"),
                    ValueFactory.newString("This is a message."),
                    ValueFactory.newString("flag"),
                    ValueFactory.newBoolean(true)));

    MessagePackConverver converter = new MessagePackConverver(config);
    SourceRecord sourceRecord = converter.convert("topic", "tag", 0L, eventEntry);

    assertEquals(Schema.STRING_SCHEMA, sourceRecord.keySchema());
    assertEquals("tag", sourceRecord.key());
    assertEquals("topic", sourceRecord.valueSchema().name());
    Struct struct = (Struct) sourceRecord.value();
    assertEquals("This is a message.", struct.get("message"));
    assertTrue(struct.getBoolean("flag"));
}
 
开发者ID:fluent,项目名称:kafka-connect-fluentd,代码行数:24,代码来源:MessagePackConverterTest.java

示例4: nullValue

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void nullValue() {
    Map<String, String> map = new HashMap<>();
    map.put(FluentdSourceConnectorConfig.FLUENTD_SCHEMAS_ENABLE, "true");
    FluentdSourceConnectorConfig config = new FluentdSourceConnectorConfig(map);
    EventEntry eventEntry = EventEntry.of(
            Instant.now(),
            ValueFactory.newMap(
                    ValueFactory.newString("message"),
                    ValueFactory.newNil()));

    MessagePackConverver converter = new MessagePackConverver(config);
    SourceRecord sourceRecord = converter.convert("topic", "tag", 0L, eventEntry);

    assertEquals(Schema.STRING_SCHEMA, sourceRecord.keySchema());
    assertEquals("tag", sourceRecord.key());
    assertEquals("topic", sourceRecord.valueSchema().name());
    Struct struct = (Struct) sourceRecord.value();
    assertNull(struct.get("message"));
}
 
开发者ID:fluent,项目名称:kafka-connect-fluentd,代码行数:21,代码来源:MessagePackConverterTest.java

示例5: schemalessKeyValue

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void schemalessKeyValue() {
    Map<String, String> map = new HashMap<>();
    map.put(FluentdSourceConnectorConfig.FLUENTD_SCHEMAS_ENABLE, "false");
    FluentdSourceConnectorConfig config = new FluentdSourceConnectorConfig(map);
    EventEntry eventEntry = EventEntry.of(
            Instant.now(),
            ValueFactory.newMap(
                    ValueFactory.newString("message"),
                    ValueFactory.newString("This is a message.")));

    MessagePackConverver converter = new MessagePackConverver(config);
    SourceRecord sourceRecord = converter.convert("topic", "tag", 0L, eventEntry);

    Assert.assertNull(sourceRecord.keySchema());
    Assert.assertNull(sourceRecord.key());
    Assert.assertNull(sourceRecord.valueSchema());
    Map<String, Object> value = (Map<String, Object>) sourceRecord.value();
    Assert.assertEquals("This is a message.", value.get("message"));
}
 
开发者ID:fluent,项目名称:kafka-connect-fluentd,代码行数:21,代码来源:MessagePackConverterTest.java

示例6: testNestedMapWithDelimiter

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void testNestedMapWithDelimiter() {
    final Flatten<SourceRecord> xform = new Flatten.Value<>();
    xform.configure(Collections.singletonMap("delimiter", "#"));

    Map<String, Object> supportedTypes = new HashMap<>();
    supportedTypes.put("int8", (byte) 8);
    supportedTypes.put("int16", (short) 16);
    supportedTypes.put("int32", 32);
    supportedTypes.put("int64", (long) 64);
    supportedTypes.put("float32", 32.f);
    supportedTypes.put("float64", 64.);
    supportedTypes.put("boolean", true);
    supportedTypes.put("string", "stringy");
    supportedTypes.put("bytes", "bytes".getBytes());

    Map<String, Object> oneLevelNestedMap = Collections.singletonMap("B", (Object) supportedTypes);
    Map<String, Object> twoLevelNestedMap = Collections.singletonMap("A", (Object) oneLevelNestedMap);

    SourceRecord transformed = xform.apply(new SourceRecord(null, null,
            "topic", 0,
            null, twoLevelNestedMap));

    assertNull(transformed.valueSchema());
    assertTrue(transformed.value() instanceof Map);
    Map<String, Object> transformedMap = (Map<String, Object>) transformed.value();
    assertEquals(9, transformedMap.size());
    assertEquals((byte) 8, transformedMap.get("A#B#int8"));
    assertEquals((short) 16, transformedMap.get("A#B#int16"));
    assertEquals(32, transformedMap.get("A#B#int32"));
    assertEquals((long) 64, transformedMap.get("A#B#int64"));
    assertEquals(32.f, (float) transformedMap.get("A#B#float32"), 0.f);
    assertEquals(64., (double) transformedMap.get("A#B#float64"), 0.);
    assertEquals(true, transformedMap.get("A#B#boolean"));
    assertEquals("stringy", transformedMap.get("A#B#string"));
    assertArrayEquals("bytes".getBytes(), (byte[]) transformedMap.get("A#B#bytes"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:38,代码来源:FlattenTest.java

示例7: testOptionalFieldStruct

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void testOptionalFieldStruct() {
    final Flatten<SourceRecord> xform = new Flatten.Value<>();
    xform.configure(Collections.<String, String>emptyMap());

    SchemaBuilder builder = SchemaBuilder.struct();
    builder.field("opt_int32", Schema.OPTIONAL_INT32_SCHEMA);
    Schema supportedTypesSchema = builder.build();

    builder = SchemaBuilder.struct();
    builder.field("B", supportedTypesSchema);
    Schema oneLevelNestedSchema = builder.build();

    Struct supportedTypes = new Struct(supportedTypesSchema);
    supportedTypes.put("opt_int32", null);

    Struct oneLevelNestedStruct = new Struct(oneLevelNestedSchema);
    oneLevelNestedStruct.put("B", supportedTypes);

    SourceRecord transformed = xform.apply(new SourceRecord(null, null,
            "topic", 0,
            oneLevelNestedSchema, oneLevelNestedStruct));

    assertEquals(Schema.Type.STRUCT, transformed.valueSchema().type());
    Struct transformedStruct = (Struct) transformed.value();
    assertNull(transformedStruct.get("B.opt_int32"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:28,代码来源:FlattenTest.java

示例8: nestedMap

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void nestedMap() {
    Map<String, String> map = new HashMap<>();
    map.put(FluentdSourceConnectorConfig.FLUENTD_SCHEMAS_ENABLE, "true");
    FluentdSourceConnectorConfig config = new FluentdSourceConnectorConfig(map);
    EventEntry eventEntry = EventEntry.of(
            Instant.now(),
            ValueFactory.newMap(
                    ValueFactory.newString("message"),
                    ValueFactory.newString("This is a message."),
                    ValueFactory.newString("nested"),
                    ValueFactory.newMap(
                            ValueFactory.newString("key"),
                            ValueFactory.newInteger(42)
                    )));

    MessagePackConverver converter = new MessagePackConverver(config);
    SourceRecord sourceRecord = converter.convert("topic", "tag", 0L, eventEntry);

    assertEquals(Schema.STRING_SCHEMA, sourceRecord.keySchema());
    assertEquals("tag", sourceRecord.key());
    assertEquals("topic", sourceRecord.valueSchema().name());
    Struct struct = (Struct) sourceRecord.value();
    assertEquals("This is a message.", struct.get("message"));
    Struct nested = struct.getStruct("nested");
    Long expected = 42L;
    assertEquals(expected, nested.getInt64("key"));
}
 
开发者ID:fluent,项目名称:kafka-connect-fluentd,代码行数:29,代码来源:MessagePackConverterTest.java

示例9: nestedArray

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void nestedArray() {
    Map<String, String> map = new HashMap<>();
    map.put(FluentdSourceConnectorConfig.FLUENTD_SCHEMAS_ENABLE, "true");
    FluentdSourceConnectorConfig config = new FluentdSourceConnectorConfig(map);
    EventEntry eventEntry = EventEntry.of(
            Instant.now(),
            ValueFactory.newMap(
                    ValueFactory.newString("message"),
                    ValueFactory.newString("This is a message."),
                    ValueFactory.newString("nested"),
                    ValueFactory.newArray(
                            ValueFactory.newFloat(3.14f),
                            ValueFactory.newFloat(42.195f)
                    )));

    MessagePackConverver converter = new MessagePackConverver(config);
    SourceRecord sourceRecord = converter.convert("topic", "tag", 0L, eventEntry);

    assertEquals(Schema.STRING_SCHEMA, sourceRecord.keySchema());
    assertEquals("tag", sourceRecord.key());
    assertEquals("topic", sourceRecord.valueSchema().name());
    Struct struct = (Struct) sourceRecord.value();
    assertEquals("This is a message.", struct.get("message"));
    List<Double> list = struct.getArray("nested");
    assertEquals(list.get(0), 3.14, 0.01);
    assertEquals(list.get(1), 42.195, 0.01);
}
 
开发者ID:fluent,项目名称:kafka-connect-fluentd,代码行数:29,代码来源:MessagePackConverterTest.java

示例10: testNestedStruct

import org.apache.kafka.connect.source.SourceRecord; //导入方法依赖的package包/类
@Test
public void testNestedStruct() {
    final Flatten<SourceRecord> xform = new Flatten.Value<>();
    xform.configure(Collections.<String, String>emptyMap());

    SchemaBuilder builder = SchemaBuilder.struct();
    builder.field("int8", Schema.INT8_SCHEMA);
    builder.field("int16", Schema.INT16_SCHEMA);
    builder.field("int32", Schema.INT32_SCHEMA);
    builder.field("int64", Schema.INT64_SCHEMA);
    builder.field("float32", Schema.FLOAT32_SCHEMA);
    builder.field("float64", Schema.FLOAT64_SCHEMA);
    builder.field("boolean", Schema.BOOLEAN_SCHEMA);
    builder.field("string", Schema.STRING_SCHEMA);
    builder.field("bytes", Schema.BYTES_SCHEMA);
    Schema supportedTypesSchema = builder.build();

    builder = SchemaBuilder.struct();
    builder.field("B", supportedTypesSchema);
    Schema oneLevelNestedSchema = builder.build();

    builder = SchemaBuilder.struct();
    builder.field("A", oneLevelNestedSchema);
    Schema twoLevelNestedSchema = builder.build();

    Struct supportedTypes = new Struct(supportedTypesSchema);
    supportedTypes.put("int8", (byte) 8);
    supportedTypes.put("int16", (short) 16);
    supportedTypes.put("int32", 32);
    supportedTypes.put("int64", (long) 64);
    supportedTypes.put("float32", 32.f);
    supportedTypes.put("float64", 64.);
    supportedTypes.put("boolean", true);
    supportedTypes.put("string", "stringy");
    supportedTypes.put("bytes", "bytes".getBytes());

    Struct oneLevelNestedStruct = new Struct(oneLevelNestedSchema);
    oneLevelNestedStruct.put("B", supportedTypes);

    Struct twoLevelNestedStruct = new Struct(twoLevelNestedSchema);
    twoLevelNestedStruct.put("A", oneLevelNestedStruct);

    SourceRecord transformed = xform.apply(new SourceRecord(null, null,
            "topic", 0,
            twoLevelNestedSchema, twoLevelNestedStruct));

    assertEquals(Schema.Type.STRUCT, transformed.valueSchema().type());
    Struct transformedStruct = (Struct) transformed.value();
    assertEquals(9, transformedStruct.schema().fields().size());
    assertEquals(8, (byte) transformedStruct.getInt8("A.B.int8"));
    assertEquals(16, (short) transformedStruct.getInt16("A.B.int16"));
    assertEquals(32, (int) transformedStruct.getInt32("A.B.int32"));
    assertEquals(64L, (long) transformedStruct.getInt64("A.B.int64"));
    assertEquals(32.f, transformedStruct.getFloat32("A.B.float32"), 0.f);
    assertEquals(64., transformedStruct.getFloat64("A.B.float64"), 0.);
    assertEquals(true, transformedStruct.getBoolean("A.B.boolean"));
    assertEquals("stringy", transformedStruct.getString("A.B.string"));
    assertArrayEquals("bytes".getBytes(), transformedStruct.getBytes("A.B.bytes"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:60,代码来源:FlattenTest.java


注:本文中的org.apache.kafka.connect.source.SourceRecord.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。