Hi, 如果声明为 ARRAY<VARCHAR> 是否可以满足你的需求呢?如果可以的话,你可以在 1.12之后使用这个feature[1].
[1] https://issues.apache.org/jira/browse/FLINK-18002 zilong xiao <acidzz...@gmail.com> 于2020年9月1日周二 下午5:49写道: > 问题大概懂了,坐等Flink大佬回复 > > Dream-底限 <zhan...@akulaku.com> 于2020年9月1日周二 下午4:43写道: > > > hi > > 就是json数组如果是这种:[1,2,3],我可以直接array<int>解析 > > > > > 如果json数组是这种:[1,"test",true],如果我用array<row<int,string,boolean>>程序是没办法运行的,如果我用array<row<a > > int,b string,c boolean>>,flink做ddl翻译解析json的时候会把row<a int,b string,c > > boolean>这一部分映射为解析jsonobject,但是array元素不是jsonobject会导致取不到数据 > > > > zilong xiao <acidzz...@gmail.com> 于2020年9月1日周二 下午4:04写道: > > > > > 基本类型包装一层会导致解析不出来 这个没太明白,可以举个列子吗? > > > > > > Dream-底限 <zhan...@akulaku.com> 于2020年9月1日周二 下午2:20写道: > > > > > > > hi、 > > > > > > > > > > 我先前也想这样用,但后来发现ddl中的row对应json中的object,基本类型包装一层会导致解析不出来,感觉应该在ddl加一个类型映射一下这种情况 > > > > > > > > zilong xiao <acidzz...@gmail.com> 于2020年9月1日周二 上午11:47写道: > > > > > > > > > like this: ARRAY<ROW<a BIGINT, b DOUBLE, c String, d MAP<String, > > > > String>>> > > > > > > > > > > Dream-底限 <zhan...@akulaku.com> 于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); > > > > > > } > > > > > > > > > > > > > > > > > > > > > -- Best, Benchao Li