hi、 我先前也想这样用,但后来发现ddl中的row对应json中的object,基本类型包装一层会导致解析不出来,感觉应该在ddl加一个类型映射一下这种情况
zilong xiao <[email protected]> 于2020年9月1日周二 上午11:47写道: > like this: ARRAY<ROW<a BIGINT, b DOUBLE, c String, d MAP<String, String>>> > > Dream-底限 <[email protected]> 于2020年9月1日周二 上午11:40写道: > > > hi > > > > > 我正在解析json数组,在解析的时候遇到一个问题,当解析的json数组元素为同一类型的时候,我可以使用ddl的array进行存储,但是当json数组元素为不同类型的时候,我没办法做ddl映射,我查看JsonRowSchemaConverter解析json > > array的时候,对于不同类型的数组元素解析后可以用row存储,但请问我在ddl时候要怎么做,因为在DDL用row表示数组会抛出异常 > > > > > > private static TypeInformation<?> convertArray(String location, > > JsonNode node, JsonNode root) { > > // validate items > > if (!node.has(ITEMS)) { > > throw new IllegalArgumentException( > > "Arrays must specify an '" + ITEMS + "' property in node: " + > > location); > > } > > final JsonNode items = node.get(ITEMS); > > > > // list (translated to object array) > > if (items.isObject()) { > > final TypeInformation<?> elementType = convertType( > > location + '/' + ITEMS, > > items, > > root); > > // result type might either be ObjectArrayTypeInfo or > > BasicArrayTypeInfo for Strings > > return Types.OBJECT_ARRAY(elementType); > > } > > // tuple (translated to row) > > else if (items.isArray()) { > > final TypeInformation<?>[] types = convertTypes(location + '/' + > > ITEMS, items, root); > > > > // validate that array does not contain additional items > > if (node.has(ADDITIONAL_ITEMS) && > > node.get(ADDITIONAL_ITEMS).isBoolean() && > > node.get(ADDITIONAL_ITEMS).asBoolean()) { > > throw new IllegalArgumentException( > > "An array tuple must not allow additional items in node: " > > + location); > > } > > > > return Types.ROW(types); > > } > > throw new IllegalArgumentException( > > "Invalid type for '" + ITEMS + "' property in node: " + location); > > } > > >
