How do I use custom-operators in Doctrine DQL? - doctrine-orm

I am trying to use PostGIS functions in my queries. I am using jsor/doctrine-postgis package to add relevant functionality to Doctrine. I am not exactly sure if I have configured it incorrectly or if I am doing something wrong.
For example:
->where('ST_Intersects(st.coords,ST_MakeEnvelope(-1,-1,1,1,4326))')
However this does not work because syntax checker wants a comparison operator. I get the following error:
Error: Expected =, <, <=, <>, >, >=, !=, got end of string
I managed to avoid this error by checking true/false. While this is undesirable, it works.
->where('ST_Intersects(st.coords,ST_MakeEnvelope(-1,-1,1,1,4326))=true')
But I want to use the && operator. I am not sure exactly how can I manage that? What I mean is something like this:
->where('st.coords && ST_MakeEnvelope(-1,-1,1,1,4326))')
But this returns an error:
Error: Expected =, <, <=, <>, >, >=, !=, got '&'
Am I doing something wrong? This feels over-complicated for some reason?

It's a known bug. There is nothing you can do. From jsor, the author
AFAICT, implementing custom operators isn't possible with Doctrine :( I don't think i can do much here. The only solution i'm aware of is using Doctrine's Native SQL feature. Closing for now. Feel free to reopen if you have further questions/ideas.
So your only option is ->createNativeQuery if you want to make use of a GIST index, or geometry_overlaps if you don't care.

You should add " = true" at end of where:
/**
* #param string $bbox
* #param int|null $limit
* #return MyEntity[]
*/
public function findByCoordinatesBoundingBox(string $bbox, int $limit = null): array
{
return $this->createQueryBuilder('n')
->where("ST_Intersects(n.coordinates, ST_MakeEnvelope({$bbox})) = true")
->orderBy('n.id', 'ASC')
->setMaxResults($limit)
->getQuery()
->getResult()
;
}

Related

Multiple conditions with contains in power automate desktop

I want to evaluate multiple conditions in one If statement in Power Automate Desktop. I have been able to do it with the basic operators (=, >, <, <>, etc.) and using IsEmpty. But I have not found any documentation about how to use it with these:
Contains
Does not contain
Starts with
Doesn't start with
Ends with
Doesn't end with
I would like to evaluate something like this:
%strFileContents Contains 'word' and strFilePath Does not contain '.txt'%
I know that I can achieve this with multiple ifs but I would like to know if it can be done in a single one.
Thanks.
%Contains(strFileContents, 'Word', True) AND NOT(Contains(strFilePath,'.txt.))%
You can add as many AND or OR as you like to evaluate the condition.

monetdb regexp select

I'm doing some testing with MonetDB.
The gist of the query I'm trying perform (using borrowed syntax) goes like this:
SELECT mystring FROM mytable WHERE mystring REGEXP 'myxpression';
MonetDB does not support this syntax, but the docs claim that it supports PCRE, so this may be possible, still the syntax eludes me.
Check the Does MonetDB support regular expression predicates?
The implementation is there in the MonetDB backend, the module that
implements it is pcre (to be found in MonetDB5 source tree).
I'm not sure whether it is available by default from MonetDB/SQL.
If not, with these two function definition, you link SQL functions to the
respective implementations in MonetDB5:
-- case sensitive
create function pcre_match(s string, pattern string)
returns BOOLEAN
external name pcre.match;
-- case insensitive
create function pcre_imatch(s string, pattern string)
returns BOOLEAN
external name pcre.imatch;
If you need more, I'd suggest to have a look at MonetDB5/src/modules/mal/
pcre.mx in the source code.
Use select name from sys.functions; to check if the function exists, otherwise you will need to create it.
As an example, you may use pcre_imatch() like this:
SELECT mystring FROM mytable WHERE pcre_imatch(mystring, 'myexpression');

Enabling Elasticsearch index names with illegal characters

I am trying to create elasticsearch indexes with strings like xxx/yyy and xxx yyy but these are not permitted because they contain illegal characters (/ and ). These names are largely user created and out of my control so changing the names for the sake of fitting into the requirements of elasticsearch is not really an option.
This is the exact error message:
[Error: InvalidIndexNameException[[XXX\%FFZZZ] Invalid index name [XXX\%FFZZZ], must not contain the following characters [\, /, *, ?, ", <, >, |, , ,]]]
Anyways, I've tried URL encoding the strings, but that doesn't work because those include capital letters which are not permitted and backslash escaping is out of the question because it is in the list of illegal characters.
Is there a conventional solution to this problem, or do I have to come up with some sketchy serialization and/or hashing scheme to solve this?
Hmm, letting users have the control on such things like index name is asking for troubles :)
But if you're willing to pursue that route, what I suggest is simply to remove any character that is not alphanumeric and lowercase the result in the process.
In PHP that would be:
$index = preg_replace("/[^a-z0-9]+/i", "", $index);
In Java:
index = index.replace("/[^a-z0-9]+/i", "");
In Javascript:
index = index.replace(/[^a-z0-9]+/i, "");
Please do not allow users to define the index name. You can try to filter out illegal characters, but your regexp might have an issue, and you might run into trouble later.
Also users might not understand why they create problems if one usere uses My_Index and writes stuff in and the next user trying to access yndex accesses the same index.
BTW: The regexp given above is more strict than the list of legal characters asks for. For example _ is legal (but not at the beginning of the name), if you wanted to create a regexp that allows everything that is legal by ES standards, your regexp becomes more complicated and more error prone.

Nested 'or' restriction in 'and' one leading in unexpected result

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).

"AND"ing multiple assertion parameters in JMeter

I want to assert multiple variables in one single Response Assertion pattern. A method exists to verify an OR of multiple values, but i haven't found one for AND.
For example, to assert values v1, v2, or v3 - you could add in the
Response Assertion > Patterns to Test >Add : v1|v2|v31. The test will pass if any one of them is found in the response. This also works with the || operator.
I need something that gives me the same flexibility with an AND condition. I'm currently having to add one pattern for each value I want to assert, and this is extremely painful to do, especially with a long assertion list.
Does anyone know of a way to combine assertion patterns using some kind of an AND operator? I have tried obvious ones, &, &&, ., +,etc. but no luck thus far.
When you add multiple lines to the Response Assertion the default operation is to AND the lines.
A separate line for each V1, V2, V3 equals V1&V2&V3.
This means you can also mix. A line for V1 and a line for V2|V3 equals V1&(V2|V3).
I thinks that Beanshell Assertion is that what you're looking for, it gives as much flexibility as you can think of.
Example AND-based assertion code will look like:
String response = new String(ResponseData);
if (response.contains(vars.get("v1")) && response.contains(vars.get("v2"))) {
Failure = false;
} else {
Failure = true;
FailureMessage = "Specified conditions were not met";
}
You can refer to How to use BeanShell: JMeter's favorite built-in component guide for more detailed explanation and kind of cookbook.