Nested 'or' restriction in 'and' one leading in unexpected result - hibernate-criteria

i am quite confused about how the Criteria API does build the final query.
Here's some code :
someCriteria.add(
Restrictions.and(
Restrictions.or(Restrictions.gt(a,b),Restrictions.isNull(a)),
Restrictions.ge(d,e)
)
I was expecting something like
SELECT.. FROM...
WHERE (A > B or A IS NULL) AND (D > E)
But when I inspect my criteria entries, I see instead something like :
SELECT.. FROM...
WHERE A > B or A IS NULL AND D > E
thus leading in unexpected result.
I am quite sure I could rewrite the query so that it is no more a problem, but since the application I am about to develop for is based on such queries, I need to understand the problem.
So, anyone could explain why I dot not get expected parentheses around the part of the query generated by the "Restrictions.or(...)"?
Thanks in advance.
PS : Hibernate core 4.3.4.Final

So the problem was not with "Criteria", but with my excessive trust in the debugging tools : the Criteria does actually match the first solution, ie adds parentheses around each generated restriction.
But when I tried to log or watch the criterion entries inside the Criteria object, some parentheses were just not displayed, leading me into misinterpreting my problem.
So the solution to understand the problem was to log the actual request (eg using property "show_sql" in the sessionFactoryBean and setting log4j.logger.org.hibernate.sql to TRACE level).

Related

OpenModelica SimulationOptions 'variableFilter' not working with '^' exceptions

To reduce size of my simulation output files, I want to give variable name exceptions instead of a list of many certain variables to the simulationsOptions/outputFilter (cf. OpenModelica Users Guide / Output) of my model. I found the regexp operator "^" to fullfill my needs, but that didn't work as expected. So I think that something is wrong with the interpretation of connected character strings when negated.
Example:
When I have any derivatives der(...) in my model and use variableFilter=der.* the output file will contain all the filtered derivatives. Since there are no other varibles beginning with character d the same happens with variableFilter=d.*. For testing I also tried variableFilter=rde.* to confirm that every variable is filtered.
When I now try to except by variableFilter=^der.*, =^rde.* or =^d.*, I get exactly the same result as without using ^. So the operator seems to be ignored in this notation.
When I otherwise use variableFilter=[^der].*, =[^rde].* or even =[^d].*, all wanted derivation variables are filtered from the ouput, but there is no difference between those three expressions above. For me it seems that every character is interpretated standalone and not as as a connected string.
Did I understand and use the regexp usage right or could this be a code bug?
Side/follow-up question: Where can I officially report this for software revision?
_
OpenModelica v.1.19.2 (64-bit)

Google data studio : Error in formula for custom fields with REGEXP_MATCH

I'm currently playing with Google Data Studio and I'm having an error that I can't get rid of.
I'm trying to create a custom field that will store some values depending on the result of my regex, see below the code :
GDS is not accepting this formula as I'm getting the error : Invalid Formula.
The documentation about REGEXP_MATCH is also saying that it returns true or false but when I just get the return of the regex '.' (looking for any character), I do not get any of these values. Instead it shows me {$theCharacterFound} ex : {A}.
Hope someone will be able to tell me what I am doing wrong !
EDIT : I found out in this topic that it is apparently a problem with the postgreSQL connector (that I'm using) so we can only hope that Google will fix it...
I think you are missing an r before the regex literal:
CASE
WHEN REGEXP_MATCH(my_field_text, r'\bWord1\b') THEN 'True'
WHEN REGEXP_MATCH(my_field_text, r'\bWord2\b') THEN 'False'
ELSE NULL
END
Note also that I placed word boundaries around your search term words. This will prevent Word1 from matching a substring in a large string, e.g. AWord1s, which you might not want to count as a match.

How to I make gerrit query that spans across few specific projects?

I tried for few hours to find the right syntax for making a regex query that returns reviews from 2-3 different projects but I failed and decided to crowdsource the task ;)
The search is documented at https://review.openstack.org/Documentation/user-search.html and mentions possible use of REGEX,... but it just didn't work.
Task: return all CRs from openstack-infra/gerritlib and openstack-infra/git-review projects from https://review.openstack.org
Doing it for one project works well project:openstack-infra/gerritlib
Ideally I would like to look for somethign like ^openstack-infra\/(gerritlib|git-review), or at least this is the standard regex syntax.
Still, I found impossible to use parentheses so far, every time I used them it stopped it from returning any results.
1) You don't need to escape the "/" character.
2) You need to use double quotes to make the parentheses work.
So the following search should work for you:
project:"^openstack-infra/(gerritlib|git-review)"

RGoogleAnalytics replacing unexpectedly escaped characters with gsub

I'm using RGoogleAnalytics, I'm just at the learning stage at the moment.
I'm following the code in the tutorial here https://code.google.com/p/r-google-analytics/
But when I try to run
ga.goals <- conf$GetGoals()
ga.goals
I get an error message telling me there is an unexpected escaped character '\.' at pos 7
I get a similar message for the next two lines of code (GetSegments)
This question deals with a similar problems in the Facebook Graphs API
How to replace "unexpected escaped character" in R
I've tried using a similar bit of code
confGoalsSub <- gsub('\\.', ' ', conf$GetGoals())
to remove the escaped characters, but I get another error :
cannot coerce type 'closure' to vector of type 'character'
Out of desperation I have tried confGoalsSub <- gsub('\\.', ' ', conf) which returns a character vector that is just garbage (it's just the code for conf with the decimal points stripped out).
Can anyone suggest a better expression than gsub that will return a useful object?
EDIT: As per the suggestion below I've now added the brackets at the end of the function call but I still get the same error message about unexpected escape characters. I get the same error when I try to call other, similar function such as $GetSegments().
I saw on one video at the weekend that this package was broken for a long time, although the speaker did not provide details as to why. Perhaps I should give up and try one of the other Google Analytics packages in R.
Seems odd, given that this one is supposed to be Google supported.
I think this error arises when the RJSON library isn't able to parse the Google Analytics Data Feed properly and convert it into a nested list. The updated version of [RGoogleAnalytics] (http://cran.r-project.org/web/packages/RGoogleAnalytics/index.html) fixes this problem. Currently, you won't be able to retrieve Goals and Segments from your Google Analytics account using the library but beyond that it supports the full range of dimensions and metrics.

Django Haystack refuses to show no results, even for absurd queries

My question may be a bit strange, but it's been bothering me since the behavior is not what I expected. Here is my query:
query = request.GET.get('q','')
#in search_indexes:
#start_datetime = indexes.DateTimeField(model_attr='start_datetime',null=True)
#end_datetime = indexes.DateTimeField(model_attr='end_datetime')
search_events = SearchQuerySet().models(Event).filter(content=query).
filter(end_datetime__gte=datetime.now()).
order_by("start_datetime")
Now I type in a query like "asdfasdfjasldf lolol hwtf asdlfka" and I still get 3 results. (Note, I only have 5 events to start with. Not sure if that could affect anything.) I print out the scores, and they are [42,42,42]. Doesn't filter() match on exact phrases? Especially if I use quotes?
//edit
I also tried using auto_query, and the results are the same.
I'm really confused about what's happening, so hopefully somebody can help clear this up. Thanks in advance!
Turns out that someone else on my team had set HAYSTACK_DEFAULT_OPERATOR to 'OR' instead of 'AND'. Explains everything - the additional filter tag was actually expanding the number of results!
You might like to perform search using auto_query():
search_events = SearchQuerySet().models(Event)
.auto_query(query)
.filter(end_datetime__gte=datetime.now())
.order_by("start_datetime")
It has some extra features, like for example exact query searching when phrase is enclosed in quotes.