flatten

Denormalize/flatten list of nested objects into dot separated key value pairs

China☆狼群 提交于 2019-12-06 16:36:11
It would have simpler if my nested objects were dictionaries, but these are list of dictionaries. Example: all_objs1 = [{ 'a': 1, 'b': [{'ba': 2, 'bb': 3}, {'ba': 21, 'bb': 31}], 'c': 4 }, { 'a': 11, 'b': [{'ba': 22, 'bb': 33, 'bc': [{'h': 1, 'e': 2}]}], 'c': 44 }] I expect output in following format: [ {'a': 1, 'b.ba': 2, 'b.bb': 3, 'c': 4}, {'a': 1, 'b.ba': 21, 'b.bb': 31, 'c': 4}, {'a': 11, 'b.ba': 22, 'b.bb': 33, 'bc.h': 1, 'bc.e': 2, 'c': 44}, ] Basically, number of flattened objects generated will be equal to (obj * depth) With my current code: def flatten(obj, flattened_obj, last_key=''

SelectMany to flatten a nested structure

亡梦爱人 提交于 2019-12-06 07:31:46
I am parsing an XML structure and my classes look like the following: class MyXml { //... List<Node> Content { get; set; } //... } class Node { // ... public List<Node> Nodes { get; set; } public string Type { get; set; } //... } MyXml represents the XML file I am parsing, whose elements are all called <node> . Each node has a type attribute, which can have different values. The type of the node is not connected to its depth. I can have any node type at any depth level. I can parse the structure correctly, so I get a MyXml object whose content is a list of Nodes, where ever node in the List

What is destructive?

点点圈 提交于 2019-12-06 02:06:47
I know that Ruby has many methods, especially on array or array like objects, for example sort or flatten . However, these methods also have a twin (the one with an exclamation mark) like sort! and flatten! . Now my questions are: What is the difference between flatten and flatten! (destructive flatten)? A more general question, why is it called destructive? The difference is simply that flatten returns a copy of the array (a new array that is flattened) and flatten! does the modification "in place" or "destructively." The term destructive means that it modifies the original array. This is

Scala nested arrays flattening

不羁的心 提交于 2019-12-05 13:52:05
How to flatten an array of nested arrays of any depth ? For instance val in = Array( 1, Array(2,3), 4, Array(Array(5)) ) would be flattened onto val out = Array(1,2,3,4,5) Thanks in Advance. If you have mixed Int and Array[Int] , which is not a very good idea to begin with, you can do something like in.flatMap{ case i: Int => Array(i); case ai: Array[Int] => ai } (it will throw an exception if you've put something else in your array). You can thus use this as the basis of a recursive function: def flatInt(in: Array[Any]): Array[Int] = in.flatMap{ case i: Int => Array(i) case ai: Array[Int] =>

Flatten nested JSON using jq

南笙酒味 提交于 2019-12-05 09:48:37
I'd like to flatten a nested json object, e.g. {"a":{"b":1}} to {"a.b":1} in order to digest it in solr. I have 11 TB of json files which are both nested and contains dots in field names, meaning not elasticsearch (dots) nor solr (nested without the _childDocument_ notation) can digest it as is. The other solutions would be to replace dots in the field names with underscores and push it to elasticsearch, but I have far better experience with solr therefore I prefer the flatten solution (unless solr can digest those nested jsons as is??). I will prefer elasticsearch only if the digestion

Flatten a DataFrame in Scala with different DataTypes inside

随声附和 提交于 2019-12-05 08:26:19
问题 As you may know, a DataFrame can contain fields which are complex types, like structures (StructType) or arrays (ArrayType). You may need, as in my case, to map all the DataFrame data to a Hive table, with simple type fields (String, Integer...). I've been struggling with this issue for a long time, and I've finally found a solution I want to share. Also, I'm sure it could be improved, so feel free to reply with your own suggestions. It's based on this thread, but also works for ArrayType

Flatten tuple like a bag

百般思念 提交于 2019-12-05 07:53:59
My dataset looks like the following: ( A, (1,2) ) ( B, (2,9) ) I would like to "flatten" the tuples in Pig, basically repeating each record for each value found in the inner-tuple, such that the expected output is: ( A, 1 ) ( A, 2 ) ( B, 2 ) ( B, 9 ) I know this is possible when the tuples (1,2) and (2,9) are bags instead. Your insight is good; it's possible by transforming the tuple in a bag. The schema we want to aim for is: {a: chararray,{(chararray)}} for example: (A,{(1),(2)}) Here is the solution to your problem: A = LOAD 'data.txt' AS (a:chararray,b:(b1:chararray,b2:chararray)); B =

Flattening XSD schema documents (HR-XML 3.0) [closed]

情到浓时终转凉″ 提交于 2019-12-05 06:01:50
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I have several "main" XSD documents, which import "supporting" XSD documents. These schema documents happen to be from the HR-XML 3.0 specification, in particular related to Background Screening. For the purposes of code-generation and convenient single-file schema to reference in my WSDL, I am trying to "flatten" the schema. The imports should be resolved; and there should be no duplication between common

How to flatten a hash, making each key a unique value?

 ̄綄美尐妖づ 提交于 2019-12-05 01:25:56
I want to take a hash with nested hashes and arrays and flatten it out into a single hash with unique values. I keep trying to approach this from different angles, but then I make it way more complex than it needs to be and get myself lost in what's happening. Example Source Hash: { "Name" => "Kim Kones", "License Number" => "54321", "Details" => { "Name" => "Kones, Kim", "Licenses" => [ { "License Type" => "PT", "License Number" => "54321" }, { "License Type" => "Temp", "License Number" => "T123" }, { "License Type" => "AP", "License Number" => "A666", "Expiration Date" => "12/31/2020" } ] }

Convert Nested JSON to Flat JSON

懵懂的女人 提交于 2019-12-04 21:11:59
I am using javascript and I have nested json object getting from mongodb. "abc": [ { "a": "01AABCE2207R1Z5", "b": "Y", "c": [ { "ca": "A", "cb": "AflJufPlFStqKBZ", "cc": "S008400" }, { "cx": "A", "cy": "AflJufPlFStqKBZ", "cz": "S008400" } ] }, { "a": "01AABCE2207R1Z5", "b": "Y", "c": [ { "ca": "A", "cb": "AflJufPlFStqKBZ", "cc": "S008400" }, { "cx": "A", "cy": "AflJufPlFStqKBZ", "cz": "S008400" } ] } ] Above schema have fixed fields there will no changes in schema. Now I want to make it as flat json array object and result should be like that. If c has multiple json object the it should create