本文整理汇总了Java中org.msgpack.value.MapValue类的典型用法代码示例。如果您正苦于以下问题:Java MapValue类的具体用法?Java MapValue怎么用?Java MapValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MapValue类属于org.msgpack.value包,在下文中一共展示了MapValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: visitMap_DropColumns
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例2: visitMap_AddColumns
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例3: visitMap_dropColumnsUsingBracketNotation
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例4: visitMap_addColumnsUsingBracketNotation
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例5: visitMap_columnsUsingBracketNotation
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:27,代码来源:TestJsonVisitor.java
示例6: visitArray_dropColumnsUsingBracketNotation
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例7: visitArray_addColumnsUsingBracketNotation
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例8: visitArray_columnsUsingBracketNotation
import org.msgpack.value.MapValue; //导入依赖的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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:26,代码来源:TestJsonVisitor.java
示例9: visit_withDotAndBracket
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visit_withDotAndBracket()
{
PluginTask task = taskFromYamlString(
"type: column",
"columns:",
" - {name: \"$.json1['k_1']\"}",
" - {name: \"$.json1['k_1'][0]['k_1']\"}",
" - {name: \"$['json1']['k_2']\"}",
" - {name: \"$['json1']['k_2']['k_2']\"}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k.1":[{"k.1":"v"}], "k.2":{"k.2":"v"}}
Value k1 = ValueFactory.newString("k_1");
Value k2 = ValueFactory.newString("k_2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k_1\":[{\"k_1\":\"v\"}],\"k_2\":{\"k_2\":\"v\"}}", visited.toString());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:27,代码来源:TestJsonVisitor.java
示例10: visit_withSingleQuotesAndDoubleQuotes
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visit_withSingleQuotesAndDoubleQuotes()
{
PluginTask task = taskFromYamlString(
"type: column",
"columns:",
" - {name: \"$['json1']['k_1']\", src: \"$['json1']['k.1']\"}",
" - {name: '$[\"json1\"][\"k_1\"][0][\"k_1\"]', src: '$[\"json1\"][\"k_1\"][0][\"k.1\"]'}",
" - {name: '$[\"json1\"][\"k_2\"]', src: '$[\"json1\"][\"k.2\"]'}",
" - {name: '$[\"json1\"][\"k_2\"][\"k_2\"]', src: '$[\"json1\"][\"k_2\"][\"k.2\"]'}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k.1":[{"k.1":"v"}], "k.2":{"k.2":"v"}}
Value k1 = ValueFactory.newString("k.1");
Value k2 = ValueFactory.newString("k.2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k_1\":[{\"k_1\":\"v\"}],\"k_2\":{\"k_2\":\"v\"}}", visited.toString());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:27,代码来源:TestJsonVisitor.java
示例11: visit_withComplexRename
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visit_withComplexRename()
{
PluginTask task = taskFromYamlString(
"type: column",
"columns:",
" - {name: \"$.json1['k____1']\", src: \"$.json1['k.-=+1']\"}",
" - {name: \"$.json1['k____1'][0]['k____1']\", src: \"$.json1['k____1'][0]['k.-=+1']\"}",
" - {name: \"$['json1']['k_2']\", src: \"$['json1']['k.2']\"}",
" - {name: \"$['json1']['k_2']['k_2']\", src: \"$['json1']['k_2']['k.2']\"}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k.1":[{"k.1":"v"}], "k.2":{"k.2":"v"}}
Value k1 = ValueFactory.newString("k.-=+1");
Value k2 = ValueFactory.newString("k.2");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newMap(k2, v));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k____1\":[{\"k____1\":\"v\"}],\"k_2\":{\"k_2\":\"v\"}}", visited.toString());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:27,代码来源:TestJsonVisitor.java
示例12: visit_withColumnNameIncludingSingleQuotes
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visit_withColumnNameIncludingSingleQuotes()
{
PluginTask task = taskFromYamlString(
"type: column",
"columns:",
" - {name: \"$['\\\\'json1']['k1']\"}");
Schema inputSchema = Schema.builder()
.add("'json1", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":"v"}
Value k1 = ValueFactory.newString("k1");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(k1, v);
MapValue visited = subject.visit("$['\\'json1']", map).asMapValue();
assertEquals("{\"k1\":\"v\"}", visited.toString());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:21,代码来源:TestJsonVisitor.java
示例13: useNoColumnsOption
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void useNoColumnsOption()
throws Exception
{
SchemaConfig schema = schema(
column("id", LONG),
column("code", LONG),
column("name", STRING),
column("description", STRING),
column("flag", BOOLEAN),
column("created_at", STRING),
column("created_at_utc", DOUBLE),
column("price", DOUBLE),
column("spec", JSON),
column("tags", JSON),
column("options", JSON),
column("item_type", STRING),
column("dummy", STRING)
);
ConfigSource config = this.config.deepCopy().set("avsc", this.getClass().getResource("item.avsc").getPath());
transaction(config, fileInput(new File(this.getClass().getResource("items.avro").getPath())));
List<Object[]> records = Pages.toObjects(schema.toSchema(), output.pages);
assertEquals(6, records.size());
Object[] record = records.get(0);
assertEquals(1L, record[0]);
assertEquals(123456789012345678L, record[1]);
assertEquals("Desktop", record[2]);
assertEquals(true, record[4]);
assertEquals("D", record[11]);
assertEquals("[\"tag1\",\"tag2\"]", record[9].toString());
assertEquals("bar", ((MapValue)record[10]).map().get(ValueFactory.newString("foo")).toString());
assertEquals("opt1", ((MapValue)record[8]).map().get(ValueFactory.newString("key")).toString());
assertEquals("2016-05-09T04:35:43+09:00", record[5].toString());
assertNull(record[12]);
}
开发者ID:joker1007,项目名称:embulk-parser-avro,代码行数:40,代码来源:TestAvroParserPlugin.java
示例14: deserializeMap
import org.msgpack.value.MapValue; //导入依赖的package包/类
private Map<Object, Object> deserializeMap( ModuleDescriptor module, MapType mapType, MapValue value )
throws IOException
{
Map<Object, Object> map = new LinkedHashMap<>( value.size() );
for( Map.Entry<Value, Value> entry : value.entrySet() )
{
Object key = doDeserialize( module, mapType.keyType(), entry.getKey() );
Object val = doDeserialize( module, mapType.valueType(), entry.getValue() );
map.put( key, val );
}
return map;
}
开发者ID:apache,项目名称:polygene-java,代码行数:13,代码来源:MessagePackDeserializer.java
示例15: deserializeStatefulAssociationValue
import org.msgpack.value.MapValue; //导入依赖的package包/类
private Object deserializeStatefulAssociationValue( ModuleDescriptor module,
StatefulAssociationValueType<?> valueType,
MapValue value ) throws IOException
{
Map<String, Value> namedValues = value.map().entrySet().stream().map(
entry ->
{
String key = doDeserialize( module, ValueType.STRING, entry.getKey() );
return new AbstractMap.SimpleImmutableEntry<>( key, entry.getValue() );
}
).collect( toMap( HashMap::new ) );
String typeInfo = null;
if( namedValues.containsKey( "_type" ) )
{
typeInfo = doDeserialize( module, ValueType.STRING, namedValues.get( "_type" ) );
}
if( typeInfo != null )
{
// TODO What to do with typeInfo? Value or Entity ?
StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor( module, typeInfo );
if( descriptor == null )
{
throw new SerializationException(
"_type: " + typeInfo + " could not be resolved while deserializing " + value );
}
valueType = descriptor.valueType();
}
ValueBuilder builder = module.instance().newValueBuilderWithState(
valueType.primaryType(),
propertyFunction( valueType.module(), namedValues ),
associationFunction( valueType.module(), namedValues ),
manyAssociationFunction( valueType.module(), namedValues ),
namedAssociationFunction( valueType.module(), namedValues ) );
return builder.newInstance();
}
开发者ID:apache,项目名称:polygene-java,代码行数:38,代码来源:MessagePackDeserializer.java
示例16: doGuessDeserialize
import org.msgpack.value.MapValue; //导入依赖的package包/类
private Object doGuessDeserialize( ModuleDescriptor module, ValueType valueType, Value value )
throws IOException, ClassNotFoundException
{
switch( value.getValueType() )
{
case MAP:
MapValue mapValue = value.asMapValue();
Optional<String> typeInfo = mapValue
.entrySet().stream()
.filter( entry -> entry.getKey().isStringValue() )
.map( entry ->
{
String key = doDeserialize( module, ValueType.STRING, entry.getKey() );
return new AbstractMap.SimpleImmutableEntry<>( key, entry.getValue() );
} )
.filter( entry -> "_type".equals( entry.getKey() ) )
.findFirst()
.map( entry -> doDeserialize( module, ValueType.STRING, entry.getValue() ) );
if( typeInfo.isPresent() )
{
StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor(
module, typeInfo.get() );
if( descriptor != null )
{
return deserializeStatefulAssociationValue( ( (CompositeDescriptor) descriptor ).module(),
descriptor.valueType(),
mapValue );
}
}
default:
throw new SerializationException( "Don't know how to deserialize " + valueType + " from " + value
+ " (" + value.getValueType() + ")" );
}
}
开发者ID:apache,项目名称:polygene-java,代码行数:35,代码来源:MessagePackDeserializer.java
示例17: serializeMap
import org.msgpack.value.MapValue; //导入依赖的package包/类
private MapValue serializeMap( Options options, Map<?, ?> map )
{
ValueFactory.MapBuilder builder = ValueFactory.newMapBuilder();
map.forEach( ( key, value ) -> builder.put( doSerialize( options, key, false ),
doSerialize( options, value, false ) ) );
return builder.build();
}
开发者ID:apache,项目名称:polygene-java,代码行数:8,代码来源:MessagePackSerializer.java
示例18: visitMap_Columns
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visitMap_Columns()
{
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)
.add("json2", 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());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:28,代码来源:TestJsonVisitor.java
示例19: visitArray_DropColumns
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visitArray_DropColumns()
{
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
" - {name: \"$.json1.k3[*].k1\"}");
Schema inputSchema = Schema.builder()
.add("json1", JSON)
.add("json2", JSON)
.build();
JsonVisitor subject = jsonVisitor(task, inputSchema);
// {"k1":[{"k1":"v"}],"k2":["v","v"],"k3":[{"k3":"v"}]}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value k3 = ValueFactory.newString("k3");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newArray(v, v),
k3, ValueFactory.newArray(ValueFactory.newMap(k1, v)));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":[{}],\"k2\":[],\"k3\":[{}]}", visited.toString());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:29,代码来源:TestJsonVisitor.java
示例20: visitArray_AddColumns
import org.msgpack.value.MapValue; //导入依赖的package包/类
@Test
public void visitArray_AddColumns()
{
PluginTask task = taskFromYamlString(
"type: column",
"add_columns:",
" - {name: \"$.json1.k1[1]\", src: \"$.json1.k1[0]\"}",
" - {name: \"$.json1.k3[*].k2\", type: string, default: v}",
" - {name: \"$.json1.k4[*].k1\", type: string, default: v}",
" - {name: \"$.json1.k5[0].k1\", 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"],"k3":[{"k1":"v"}]}
Value k1 = ValueFactory.newString("k1");
Value k2 = ValueFactory.newString("k2");
Value k3 = ValueFactory.newString("k3");
Value v = ValueFactory.newString("v");
Value map = ValueFactory.newMap(
k1, ValueFactory.newArray(ValueFactory.newMap(k1, v)),
k2, ValueFactory.newArray(v, v),
k3, ValueFactory.newArray(ValueFactory.newMap(k1, v)));
MapValue visited = subject.visit("$['json1']", map).asMapValue();
assertEquals("{\"k1\":[{\"k1\":\"v\"},{\"k1\":\"v\"}],\"k2\":[\"v\",\"v\"],\"k3\":[{\"k1\":\"v\",\"k2\":\"v\"}],\"k4\":[],\"k5\":[{\"k1\":\"v\"}]}", visited.toString());
}
开发者ID:sonots,项目名称:embulk-filter-column,代码行数:30,代码来源:TestJsonVisitor.java
注:本文中的org.msgpack.value.MapValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论