Hi I have 2 problems related to hibernate criteria
I have the following product which contain many colors.
I wish to find the product which contain at least RED and GREEN.
Product class
String id;
name;
style;
List<Color> colors{};
Color class
id
color
1) Every time I do a retrieval, each product will appear depending on how many colors it has..
for example a product A has red green blue, it will appear 3 times.
I have used FetchMode: Select but it doesn't seems to change.
The only possible solution I can think of is inserting them into a hashset and rewrite the hashcode and equal method for primary key only
2) How do I return queries that is sorted according to the closest match to my search?
For example I search for style and color red,green.
so products that matches style color and red green
1) You use need to distict results.
It is not a matter of changing FetchMode.
Please take a look article this
setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
2) Well... there is no that kind of criteria function to automatically find and order closest match stuff
Anyway, the simplest way to make similar function is to use addOrder with createAlias instead of setFetch
ct.createAlias("colors", "cs")
.add( Restrictions.like("style", value + "%"))
.add( Restrictions.in("color", colorsArray ))
.addOrder( Order.asc("style"))
.addOrder( Order.asc("cs.color"))
I cannot write all kind of match method in here.
Please refer Restrictions's various expression on here
Related
I want to count the occurrences of values in a column. In my case the value I want to count is TRUE().
Lets say my table is called Table and has two columns:
boolean value
TRUE() A
FALSE() B
TRUE() A
TRUE() B
All solutions I found so far are like this:
count_true = COUNTROWS(FILTER(Table, Table[boolean] = TRUE()))
The problem is that I still want the visual (card), that displays the measure, to consider the filters (coming from the slicers) to reduce the table. So if I have a slicer that is set to value = A, the card with the count_true measure should show 2 and not 3.
As far as I understand the FILTER function always overwrites the visuals filter context.
To further explain my intent: At an earlier point the TRUE/FALSE column had the values 1/0 and I could achieve my goal by just using the SUM function that does not specify a filter context and just acts within the visuals filter context.
I think the DAX you gave should work as long as it's a measure, not a calculated column. (Calculated columns cannot read filter context from the report.)
When evaluating the measure,
count_true = COUNTROWS ( FILTER ( Table, Table[boolean] = TRUE() ) )
the first argument inside FILTER is not necessarily the full table but that table already filtered by the local filter context (including report/page/visual filters along with slicer selections and local context from e.g. rows/column a matrix visual).
So if you select Value = "A" via slicer, then the table in FILTER is already filtered to only include "A" values.
I do not know for sure if this will fix your problem but it is more efficient dax in my opinion:
count_true = CALCULATE(COUNTROWS(Table), Table[boolean])
If you still have the issue after changing your measure to use this format, you may have an underlying issue with the model. There is also the function KEEPFILTERS that may apply here but I think using KEEPFILTERS is overcomplicating your case.
I have set of data where I want to apply filters by default to a numberDisplay. The data is something like this.
data = [{category:'A',value:10},
{category:'B',value:10},
{category:'C',value:10},
{category:'S',value:10},
{category:'C',value:10},
{category:'A',value:10}]
I am trying to create a number display which will show sum of values other than category 'S', I tried using fake groups but they are failing. What would be the best method to achieve this ?
You don’t need a fake group for this, since you’re not trying to change the shape/structure of the aggregation. Ordinary crossfilter reductions cover this purpose.
You can simply do
cf.groupAll().reduceSum(d => d.category === ‘S’ ? 0 : d.value);
This will sum the value of every row included in the current filters, but will substitute zero if the row’s category is S.
I have a table with 5 categories and units displayed into 2 types, Actual and budget.
I want to filter this table. Only when 2 or more values are selected in the slicer. Something like this.
I though of adding a measure, but dont know how to work the if statement exactly.
Measure = IF(COUNTROWS(ALLSELECTED(Report[Shipment Group])) = 1, "Something which would not filter the units", SELECTEDVALUE(Report[Units], SUM(Report[Units])))
Not sure if this is correct approach.Would like to know if any other approach is possible. Any help would be helpful. Thank you in advance.
This is a bit of an odd request, but I think I have something that works.
First, you need to create a separate table for your slicer values (or else you can't control filtering how you want). You can hit the new table button and define it as follows:
Groups = VALUES(Report[Shipment Group])
Set your slicer to use Groups[Shipment Group] instead of Report[Shipment Group].
Define your new measure as follows:
Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
SUM(Report[Units]),
SUMX(FILTER(Report,
Report[Shipment Group] IN VALUES(Groups[Shipment Group])),
Report[Units]))
or equivalently
Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
SUM(Report[Units]),
CALCULATE(SUM(Report[Units]),
FILTER(Report,
Report[Shipment Group] IN VALUES(Groups[Shipment Group]))))
Note: Double check that Power BI has not automatically created a relationship between the Groups and Report tables. You don't want that.
I used "Union" to combine two different subject area in an analysis in OBIEE 11 :
"A" is a column in the first subject area with formula that needs
"A_Dim" to be calculated using "A_Dim" and Case-When (So I Should Use "A_Dim" in first subject area then exclude it in result)
"A" equals to zero in second subject area
"B" is a column in the second subject area
"B" equals to zero in first subject area
"C" is a column in Result (Using Add Result Column) that has this formula :
SUM("A" BY sth ) / SUM("B" BY sth)
("A","B",... replaced with saw_i in result column formula as you know)
the problem is, I can not get top 10 rows ordering by "C" ??
(I tried using RANK, TOPN , TOPN(RANK()),... with no luck)
(and one more thing, there are two problem with using "Narrative view" instead of other views , first they want a bar chart, besides in narrative there is no Exclude option and I should use javaScript to get top 10 from thousands of repeated "C" values)
The original question is old, but I figured I would add my solution in case anyone ends up here like I did.
I was able to create a "Result Column" with my TOPN formula. I did not have to create equivalent columns in the two queries that are being unioned (aka there are 4 columns in each union query but 5 columns in the "Result Columns" overall). It seems to work as expected.
I am trying to create a pie chart in Kibana (V2.3.1) which displays values from multiple fields.
Lets say I got documents representing humans with the following fields: (representing if the finger is bent or straight)
Human 1:
human.right_arm.thumb = bent
human.right_arm.pinky = straight
human.left_arm.thumb = straight
human.left_arm.pinky = half-bent
Human 2:
human.right_arm.thumb = straight
human.right_arm.pinky = bent
human.left_arm.thumb = half-bent
human.left_arm.pinky = half-bent
Now I want to create a pie chart on the status of all the fingers. It would create a result like:
bent (= 2) = 25% coverage of the pie
straight (= 3) = 37.5% coverage of the pie
half-bent (= 3) = 37.5% coverage of the pie
In Kibana I can only split one field per chart. So how do I combine the results for all fingers?
And how can I get the same status but then from all the thumbs?
I think scripted fields are the way to go, but I cannot figure out how since as far as I can see the aggregation only combines the results of fields while it should represent a set of fields ("all fingers" or "all thumbs").
I searched the web and found similar issues but never a clear answer.
If necessary I can make changes in Logstash. We use the ruby/code filter to define these fields.
Note: Sadly I am not able to update our ELK stack to a newer version.
Can you make the state of the finger an separate aggregatable field? Then you'll be able to create a pie chart with a count metric and split the slices by terms and then choose the field with the name of the state of the finger.
Eg.
Otherwise, this scripted field might work (not tested since I don't have the necessary setup):
def fingerState = doc['whatever the field is called'].value;
if (fingerState != null)
{
int index = fingerState.lastIndexOf('=');
if (index > 0)
{
return fingerState.substring(index+1);
}
}
return fingerState; //this will return the whole thing if for some reason this format isnt consistent
As for the second question, you can do something like
but for this to work you need to make the state of finger aggregatable.
Hope this works and that it's compatible with your version on ELK (I'm using 5.2)