i have two lists listA and listB of type object
ListA[name=abc, age=34, weight=0, height=0] data collected from excel sheet
ListB[name=null, age=0, weight=70, height=6] data collected from database
Now i want to combine both the lists into a single list
MergedList[name=abc, age=34, weight=70, height=6]
Note: my obj class has more than 15 properties so adding each property one by one using getProperty() will be time-consuming.is there a better way?
Convert them to a Map where the key is the name of the object ( you denoting the elements as name=abc suggests they are name/value pairs ).
Map<String,MyMysteriousObject> converted = list.stream().collect( Collectors.toMap(MyMysteriousObject::getName, Function.identity() ) );
( replace the getName with what ever function you use to get the name of your object )
And then just merge the maps. How to merge maps is described here for example.
While at it, consider replacing the List with Map in your entire code. Will surely save a lot of work elsewhere too.
But if you have to have a list again, just List<MyMysteriousObject> resultList = new ArrayList<>(resultMap);
I would like to create a organogram like:
https://codepen.io/bernardoantunes/pen/inrbh using 2sic Content.
I would like to create a content-type 'organogram' with the following fields:
Title as String
Parent as Entity (of type Organogram)
Description as String
Link as Hyperlink
Using this content-type i would add some elements where child elements could be created.
for example:
- Root
- Child 1 (Root is selected in the Parent field)
- Child 2 (Root is selected in the Parent field)
- Child 3 (Child 2 is selected in the Parent field)
Could this be done using 2sic content App?
I created the content-type and added some elements. Created a razor template and then it gives an error.
operator '==' can not be applied to operands of type System.Collections.Generic.List and ToSic.SexyContent.DynamicEntity
Razor template:
#using Connect.Koi;
#{
var first = AsDynamic(Data["Default"]).First();
var all = AsDynamic(Data["Default"]);
}
<div>#first.Title</div>
var children = all.Where(x => x.parent == first).ToList();
<div>#children.Count</div>
Basically the AsDynamic(...) creates wrapped entity-objects, whereas ...parent gives you a list of related items (because it could have more than 1 parent). If this is the code you want to use, I suggest 1 things.
On the .parent (which should probably be .Parent) use the [0] or .FirstOrDefault() so it's .Parent.FirstOrDefault() == first - remember to enable LINQ by #using System.Linq
Don't compare the AsDynamic objects, because they will be different objects. Better compare the id using .EntityId or something.
So you're resulting compare will probably be .Parent[0].EntityId == first.EntityId.
What I don't like about your solution is the idea, that the first item in the Default-list will somehow be the important one. This doesn't feel right, but I don't know your whole solution...
I have UDF output as :-
Sample records:-
({(Todd,1),(Todd,1),(Todd,1),(Todd,1),(Todd,1),(Todd,5),(Todd,10),(Todd,20),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10)})
({(Jon,1),(Jon,1),(Jon,1),(Jon,1),(Jon,1),(Jon,5),(Jon,10),(Jon,20),(Jon,10),(Jon,10),(Jon,10),(Jon,10),(Jon,5),(Jon,20),(Jon,1)})
Schema for UDF:- name:chararray(1 single column)
Now i want to read this bag of tuples and generate output as :-
Todd,240
Jon,422
The output of the UDF i stored in a temp file and read it back using different schema as:-
D = LOAD '/home/training/pig/pig/UDFdata.txt' AS (B: bag {T: tuple(name:chararray, denom:int)});
After that i am trying to use foreach loop and reference dot notation to find the sum.
X = foreach D generate B.T.name,SUM(B.T.denom);
2017-03-04 13:52:59,507 ERROR org.apache.pig.tools.grunt.Grunt: ERROR
1128: Cannot find field T in name:chararray,denom:int Details at
logfile: /home/training/pig_1488648405070.log
Can you please let me know how to find it? I am new to Apache Pig so not sure how it traverse in Bag of Tuples and find sum.
GROUP the dataset on name before performing SUM.
FLATTEN the bag to perform GROUP.
flattened = FOREACH D GENERATE FLATTEN(B);
dump flattened;
...
(Todd,10)
(Todd,10)
(Jon,1)
(Jon,1)
....
Then, GROUP them on name
grouped = GROUP flattened by name;
dump grouped;
(Jon,{(Jon,1),(Jon,20),(Jon,5),(Jon,10),(Jon,10),(Jon,10),(Jon,10),(Jon,20),(Jon,10),(Jon,5),(Jon,1),(Jon,1),(Jon,1),(Jon,1),(Jon,1)})
(Todd,{(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,20),(Todd,10),(Todd,5),(Todd,1),(Todd,1),(Todd,1),(Todd,1),(Todd,1)})
And apply SUM() over the result
final_sum = FOREACH grouped GENERATE group, SUM(flattened.denom);
dump final_sum;
(Jon,106)
(Todd,100)
I have a string as:
[["structure\/","structure\/home_page\/","structure\/home_page\/headline_list\/","structure\/home_page\/latest\/","topic\/","topic\/location\/","topic\/location\/united_states\/","topic\/location\/united_states\/ohio\/","topic\/location\/united_states\/ohio\/franklin\/","topic\/news\/","topic\/news\/politics\/","topic\/news\/politics\/elections\/,topic\/news\/politics\/elections\/primary\/"]]
I want to regex_extract_all to turn it into elements in a tuple and sepereated by ",". Then I need to filter out the ones don't contain structure and location.
However, I got an error that can't filter regex type. Any idea?
By the way, the ending goal is to parse out the longest hierarchy like (topic|news|politics|elections|primary)
update the script:
data = load load '/web/visit_log/20160303'
USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') as json:map[];
a = foreach data generate json#section as sec_type;
b = foreach act_flt GENERATE ..host, REGEX_EXTRACT_ALL(act_type, 'topic..(?!location)(.*?)"') as extr;
store b into /user/tad/sec_hir
The syntax for filter matches seems incorrect.The data doesn't seem to have () in it.
c = filter b by not extr matches '(structure|location)';
Try changing this to
c = filter b by not (extr matches 'structure|location');
I'm stuck with a very basic problem regarding EMF, here's what i've got.
EClass A:
aID : EInteger (Key: true)
EClass B:
bID : EInteger (Key: true)
EClass C:
Reference refA: to elements of A, containment: true, EKeys: aID, 0 .. n
Reference refB: to elements of B, containment: true, EKeys: bID, 0 .. n
Now here's the problem. In both my a and b list I'd like to have IDs from 0 to n. However, when I do this, I get the message:
The ID '1' of 'A' collides with that of 'B'
I hope my problem is described clearly. Does anyone know what I'm doing wrong? Thanks!
An EAttribute which is set as "ID" should be unique resource-wide. If you want to reference elements using a myReference[name="SomeName"] construction then you should use eKeys, then the eKeyed attribute should have a unique value within a reference.
I am under the impression you defined "aID" and "bID" as "ID's whereas that's not what you really want here.
That could be resolved using OO hierachy. You just need to extend A and B from a common Abstract class that contains the id attribute and it setted as ID in emf properties.
regards