![](/img/trans.png)
[英]How do I create a schema for Hive to parse deeply nested json (Azure Application Insights output) using SerDe?
[英]Create Deeply Nested JSON with Recursion
这个JSON是我期望的输出,
[{
"text": "a",
"nodes": [{
"text": "aa",
"nodes": [{
"text": "aa1"
}, {
"text": "aa2",
"nodes": [{
"text": "aaa1"
},
{
"text": "aaa2",
"nodes": [{
"text": "aaaa21"
}]
},
{
"text": "aaa3"
}
]
}]
}]
},
{
"text": "b",
"nodes": [{
"text": "bb1"
},
{
"text": "bb2"
}
]
},
{
"text": "c",
"nodes": [{
"text": "cc"
}]
},
{
"text": "d",
"nodes": [{
"text": "dd1",
"nodes": [{
"text": "ddd1"
},
{
"text": "ddd2"
},
{
"text": "ddd3",
"nodes": [{
"text": "ddd31",
"nodes": [{
"text": "ddd32"
}]
}]
}
]
}]
}]
因此,简而言之,从下面的表结构中,我想生成一个像上面的JSON树,请为此共享一个Java代码/算法。
一个简单的递归方法会对我有帮助,或者是否有任何标准库可以做到这一点
您的直接问题是,递归函数每次都将执行SQL查询,因此永远不会超出第一个结果行。 因此,堆栈溢出。 重新组织代码,以便查询仅在开始时执行一次。 我没有时间建立表来进行尝试,但是直觉上,您需要将函数移到“ while”循环之前开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.