本文整理汇总了Java中org.msgpack.value.ValueFactory类的典型用法代码示例。如果您正苦于以下问题:Java ValueFactory类的具体用法?Java ValueFactory怎么用?Java ValueFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueFactory类属于org.msgpack.value包,在下文中一共展示了ValueFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simpleKeyValue
import org.msgpack.value.ValueFactory; //导入依赖的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"));
}
示例2: nullValue
import org.msgpack.value.ValueFactory; //导入依赖的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"));
}
示例3: schemalessKeyValue
import org.msgpack.value.ValueFactory; //导入依赖的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"));
}
示例4: RepeatedPrimitiveConverter
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
public RepeatedPrimitiveConverter(Type parquetType, final ParentContainerUpdater parentUpdater)
{
this.updater = new ParentContainerUpdater.Noop() {
@Override
public void start()
{
RepeatedPrimitiveConverter.this.currentArray = new ArrayList<>();
}
@Override
public void end()
{
parentUpdater.set(ValueFactory.newArray(RepeatedPrimitiveConverter.this.currentArray));
}
@Override
public void set(Value value)
{
RepeatedPrimitiveConverter.this.currentArray.add(value);
}
};
this.elementConverter = newConverter(parquetType, getUpdater()).asPrimitiveConverter();
}
示例5: RepeatedGroupConverter
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
public RepeatedGroupConverter(Type parquetType, final ParentContainerUpdater parentUpdater)
{
this.updater = new ParentContainerUpdater.Noop() {
@Override
public void start()
{
RepeatedGroupConverter.this.currentArray = new ArrayList<>();
}
@Override
public void end()
{
parentUpdater.set(ValueFactory.newArray(RepeatedGroupConverter.this.currentArray));
}
@Override
public void set(Value value)
{
RepeatedGroupConverter.this.currentArray.add(value);
}
};
this.elementConverter = newConverter(parquetType, getUpdater()).asGroupConverter();
}
示例6: fromBoolean
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
public Value fromBoolean(Type outputType, BooleanValue value)
{
if (outputType instanceof BooleanType) {
return value;
}
else if (outputType instanceof LongType) {
return ValueFactory.newInteger(BooleanCast.asLong(value.getBoolean()));
}
else if (outputType instanceof DoubleType) {
return ValueFactory.newFloat(BooleanCast.asDouble(value.getBoolean()));
}
else if (outputType instanceof StringType) {
return ValueFactory.newString(BooleanCast.asString(value.getBoolean()));
}
else if (outputType instanceof JsonType) {
return BooleanCast.asJson(value.getBoolean());
}
else {
assert (false);
return null;
}
}
示例7: fromDouble
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
public Value fromDouble(Type outputType, FloatValue value)
{
if (outputType instanceof BooleanType) {
return ValueFactory.newBoolean(DoubleCast.asBoolean(value.toDouble()));
}
else if (outputType instanceof LongType) {
return ValueFactory.newInteger(DoubleCast.asLong(value.toDouble()));
}
else if (outputType instanceof DoubleType) {
return value;
}
else if (outputType instanceof StringType) {
return ValueFactory.newString(DoubleCast.asString(value.toDouble()));
}
else if (outputType instanceof JsonType) {
return DoubleCast.asJson(value.toDouble());
}
else {
assert (false);
return null;
}
}
示例8: visitMap_DropColumns
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitMap_DropColumns()
{
PluginTask task = taskFromYamlString(
"type: column",
"drop_columns:",
" - {name: $.json1.k1.k1}",
" - {name: $.json1.k2}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":{"k1":"v"},"k2":{"k2":"v"}}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newMap(k1, v),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":{}}", visited.toString());
}
示例9: visitMap_AddColumns
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitMap_AddColumns()
{
PluginTask task = taskFromYamlString(
"type: column",
"add_columns:",
" - {name: $.json1.k3.k3, type: string, default: v}",
" - {name: $.json1.k4, src: $.json1.k2}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":{"k1":"v"},"k2":{"k2":"v"}}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newMap(k1, v),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":{\"k1\":\"v\"},\"k2\":{\"k2\":\"v\"},\"k3\":{\"k3\":\"v\"},\"k4\":{\"k2\":\"v\"}}", visited.toString());
}
示例10: visitMap_dropColumnsUsingBracketNotation
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitMap_dropColumnsUsingBracketNotation()
{
PluginTask task = taskFromYamlString(
"type: column",
"drop_columns:",
" - {name: \"$['json1']['k1']['k1']\"}",
" - {name: \"$['json1']['k2']\"}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":{"k1":"v"},"k2":{"k2":"v"}}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newMap(k1, v),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":{}}", visited.toString());
}
示例11: visitMap_addColumnsUsingBracketNotation
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitMap_addColumnsUsingBracketNotation()
{
PluginTask task = taskFromYamlString(
"type: column",
"add_columns:",
" - {name: \"$['json1']['k3']['k3']\", type: string, default: v}",
" - {name: \"$['json1']['k4']\", src: \"$['json1']['k2']\"}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":{"k1":"v"},"k2":{"k2":"v"}}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newMap(k1, v),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":{\"k1\":\"v\"},\"k2\":{\"k2\":\"v\"},\"k3\":{\"k3\":\"v\"},\"k4\":{\"k2\":\"v\"}}", visited.toString());
}
示例12: visitMap_columnsUsingBracketNotation
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitMap_columnsUsingBracketNotation()
{
PluginTask task = taskFromYamlString(
"type: column",
"columns:",
" - {name: \"$['json1']['k1']\"}",
" - {name: \"$['json1']['k2']['k2']\"}",
" - {name: \"$['json1']['k3']['k3']\", type: string, default: v}",
" - {name: \"$['json1']['k4']\", src: \"$['json1']['k2']\"}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":{"k1":"v"},"k2":{"k1":"v","k2":"v"}}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newMap(k1, v),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":{\"k1\":\"v\"},\"k2\":{\"k2\":\"v\"},\"k3\":{\"k3\":\"v\"},\"k4\":{\"k2\":\"v\"}}", visited.toString());
}
示例13: visitArray_dropColumnsUsingBracketNotation
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitArray_dropColumnsUsingBracketNotation()
{
PluginTask task = taskFromYamlString(
"type: column",
"drop_columns:",
" - {name: \"$['json1']['k1'][0]['k1']\"}",
" - {name: \"$['json1']['k2'][*]\"}"); // ending with [*] is allowed for drop_columns, but not for others
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":[{"k1":"v"}[,"k2":["v","v"]}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newArray(v, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":[{}],\"k2\":[]}", visited.toString());
}
示例14: visitArray_addColumnsUsingBracketNotation
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitArray_addColumnsUsingBracketNotation()
{
PluginTask task = taskFromYamlString(
"type: column",
"add_columns:",
" - {name: \"$['json1']['k1'][1]\", src: \"$['json1']['k1'][0]\"}",
" - {name: \"$['json1']['k3'][0]['k3']\", type: string, default: v}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":[{"k1":"v"}],"k2":["v","v"]}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newArray(v, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":[{\"k1\":\"v\"},{\"k1\":\"v\"}],\"k2\":[\"v\",\"v\"],\"k3\":[{\"k3\":\"v\"}]}", visited.toString());
}
示例15: visitArray_columnsUsingBracketNotation
import org.msgpack.value.ValueFactory; //导入依赖的package包/类
@Test
public void visitArray_columnsUsingBracketNotation()
{
PluginTask task = taskFromYamlString(
"type: column",
"columns:",
" - {name: \"$['json1']['k1'][1]\", src: \"$['json1']['k1'][0]\"}",
" - {name: \"$['json1']['k2'][0]\"}",
" - {name: \"$['json1']['k3'][0]['k3']\", type: string, default: v}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":[{"k1":"v"},"v"],"k2":["v","v"]}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v), v),
k2, ValueFactory.newArray(v, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":[{\"k1\":\"v\"}],\"k2\":[\"v\"],\"k3\":[{\"k3\":\"v\"}]}", visited.toString());
}