Drupal 7 EntityFieldQuery OR Condition - drupal-7

I've got a query going using EntityFieldQuery. I have two fields called field_tags and field_categories the column name I'm looking at in each is tid. I want to check each field for a matching tid. Each one is checking a separate array of tids.
Normally I would use something like:
$query->fieldCondition('field_tags', 'tid', $my_tags, 'IN');
But now, since I'm checking if there are any matches in the tags array for field_tags OR the categories array for field_categories, I don't know how to do it. The idea is that each row returned must match at least one tag or one category.
I know there has to be an OR condition in there somewhere...
Thanks,
Howie

Found this: http://treehouseagency.com/blog/fredric-mitchell/2012/02/21/or-queries-entityfieldquery which explains how to use a tag to later the query and incorporate an OR clause.

Related

Countifs formula doesn't work when using array exclusion but works with inclusion

I have a Countifs formula that filters multiple headings, and sometimes multiple criteria in a specific heading.
It doesn't work when filtering a specific heading to exclude 2 options. It works when I include.
It's easier to exclude 2 options than to include 10, it's a template so the data in the column always changes, so better to exclude just 2.
This formula includes "MA05" and "MA07", which gives the correct answer
=SUM(COUNTIFS(Table15[Vendor],{"MA05","MA07"},Table15[MS],4,Table15[[ SOH DC]],">0",Table15[[ SOH]],0,Table15[RP Type],"Roster",Table15[Listing Status],"Listed",Table15[Ownership 2],"Hyper"))
but this one should exclude them, gives the wrong answer
=SUM(COUNTIFS(Table15[Vendor],{"<>MA05","<>MA07"},Table15[MS],4,Table15[[ SOH]],0,Table15[RP Type],"Roster",Table15[Listing Status],"Listed",Table15[Ownership 2],"Hyper"))
I think the problem comes in with the double exclusion {"<>MA05","<>MA07"}.
I just don't know how to fix it.
When you use an array you are essentially creating an OR filter, but you need an AND if you're going to exclude, which is actually simpler - you just repeat the column and additional criterion:
=COUNTIFS(Table15[Vendor],"<>MA05",Table15[Vendor],"<>MA07",Table15[MS],4,Table15[[ SOH]],0,Table15[RP Type],"Roster",Table15[Listing Status],"Listed",Table15[Ownership 2],"Hyper")

Grouping tablix by Paramater is SSRS (#Error) and automatically adding (0) when selected in expression

I hope this is not a stupid question, but I have searched everywhere and have tried everything.
I have a dashboard and would like to group the tablix (The dashboard is inside the tablix) by one of the Parameters (Consultant). There are a few Data sets(queries) in the report and all of the Parameters are filtered with IN in the where clause.
The problem I have is that when I go to the row group properties and select the Parameter in the expression, then it automatically adds a (0) at the end. If I take the (0) away then I get the error message:
the group expression used in grouping 'Group1' returned a data type
that is not valid
I know the (0) is for getting the first value, but I am using Multi-valued Parameters.
I have tried one thing I found, but unfortunately it didn't work for me (SSRS Group By Parameter).
Edited:
This is to show you that there are multiple Data Sets(Queries) in this report
I have the dashboard in a tablix so that I can group for each Consultant, so when I choose 3 Consultant, I get 3 dashboards.
Expression used:
Then I get this error:
I have also tried using the CStr, but also no luck.
When I add the Parameter in any expression box it automatically put the (0) as below:
But then it doesn't use the parameter as I get an #Error where is should be the Consultant name.
I also used this option for page break but end up with graphs below each other:
This is what happens to the Charts(Sub Reports)
To give you an idea how the dashboard should look for each Consultant.
Regarding the other question I saw. I just tried exactly as they said but also no luck
I hope this isn't too much information. Just trying to help you help me.
Thank you!
UPDATE:
Parameter Properties:
Have you tried using the list tool to separate the sub reports by Consultant? A list acts like a container and will create whatever is inside for your grouping. You should also be able to apply a parameter to the list for filtering.

scala readCsvFile behaviour

I´m using flink to load a csv file to a dataset of pojos, defined through a scala case class, using readCsvFile method, and I have a problem that i cannot solve.
When in the csv there is a record with some format error in any of its fields it is discarded, and I assume that the only way to keep those records is to type them all as String and do the validations myself.
The problem is that if the last field after the delimiter is empty, the record is discarded by default, I think because it is considered as not having the expected number of fields it should, and it is not possible to handle this record error, while if the empty value if in any of the previous fields there is no problem.
Example
field1|field2|field3
a||c
a|b|
In this example, first record is returned by readCsvFile method but not the second.
Is this behaviour right? and there is any walk around to get the record?
Thanks
Case classes and tuples in Flink do not support null values. Therefore, a||c is invalid if the empty field is not a String. I recommend to use the RowCsvInputFormat in this case. It supports nulls and generic rows can be converted to any other class in a following map operator.
The problem is that, as you say, if the field is a String, the record should be valid even if it is null, and this doesn't happen when the null value is in the last field. The behaviour is different depending on the position.
I will try also with RowCsvInputFormat as you recommend.
Thanks

How to update keys in a JSON array Postgresql

I am using PostgreSQL 9.4.1 and have run into an issue with a column that I need to update. The column is of type JSON with elements in the following format:
["a","b","c",...]
["a","c","d",...]
["c","d","e",...]
etc.
so that each element is a string. It is my understanding that each of these elements are considered keys to the JSON array (please correct me if I am a bit confused here, I haven't ever worked with JSON datatype columns before, so I'm still trying to get a grip on them anyways). There is not an actual pattern to these arrays, and their contents are dependent on user input from somewhere else. My goal is to update any of the arrays that contain a particular element (say "b" for the purpose of explaining my question more thoroughly) and replace the content "b" with say "b1". Meaning that:
["a","b","c",...]
would be updated to
["a","b1","c",...]
I have found a few ways listed on this site (I don't currently have the links, but I can find them again if necessary) to update VALUES for a particular KEY, but I haven't found a way mentioned to change the KEY itself. I have already found a way to target the specific rows of interest by doing something similar to:
SELECT *
FROM TableA
WHERE column::json ?| ["b", other string elements of interest]
Any suggestions would be greatly appreciated. Thanks for your help!
So I went ahead and gave that a check (because it looks like it should work, and it's more or less what I ended up doing), but I figured out what I was trying to do! What I got was this:
UPDATE TableA
SET column = REPLACE(column::TEXT,'b','b1')::JSON
WHERE column::JSON ?| ['b']
And now that I think about it, I probably don't even need the last where condition because the replace won't affect anything that doesn't have 'b' in it. But that worked for me, and it looks like yours probably should too! Thanks for the help!
I wanted to rename a specific key for json array column.
I tried and it worked on PostgreSQL 9.4:
UPDATE Your_Table_Name
SET Your_Column_Name = replace(Your_Column_Name::TEXT,'Key_Old_Name','Key_New_Name')::json
WHERE attributes::jsonb ? 'Key_Old_Name'
Basically, solution is to go over the list of json_array_elements, and based on json value using CASE condition replace certain value with other one. After all, need to re-build new json array using array_agg() and to_json() description of aggregate functions in psql is here.
Possible query can be the following:
-- Sample DDL and JSON data
CREATE TABLE jsontest (data JSON);
INSERT INTO jsontest VALUES ('["a","b","c"]'::JSON);
-- QUERY
WITH result AS (
SELECT to_json( -- creating updated json structure
array_agg( -- create array with new element "b1"
CASE WHEN element::TEXT = '"b"' -- here we process array elements to find "b"
THEN to_json('b1'::TEXT)
ELSE element
END)) as new_json
FROM jsontest,json_array_elements(jsontest.data) as element
)
UPDATE jsontest SET data = result.new_json FROM result;

Use array formula with index match

Is it possible to do an array formula with index match:
e.g:
=arrayformula(if(len(A3:A),INDEX('SheetB'!E:E,MATCH(A3:A,'SheetB'!H:H,0))))
If not, is there a solution that doesn't involve google scripts?
It seems INDEX can not return multiple values. It can not be used inside ARRAYFORMULA.
The only solution I know of is to use VLOOKUP.
See this thread :
https://productforums.google.com/forum/#!topic/docs/jVvjbz8u7A8
Example from there :
=ArrayFormula(VLOOKUP( B12:B15; H2:R32; 1; TRUE))
Cheers!
Use XLOOKUP
=ARRAYFORMULA(XLOOKUP(K2:K,R2:R,S2:S))
With XLOOKUP you can look in one column for a search term, and return a result from the same row in another column, regardless of which side the return column is on
In the OP's specific case, one can actually use VLOOKUP for its intended purpose, as a replacement for MATCH:
=arrayformula(if(len(A3:A),VLOOKUP(A3:A,{SheetB!E:E,SheetB!H:H},2,false)))
In the general case of trying to use INDEX to retrieve multiple values, it can be replaced with a kludge of VLOOKUP and SEQUENCE:
=arrayformula(VLOOKUP(A:A,{SEQUENCE(rows(B:B)),B:B},2,true))
does what would have been accomplished by
=arrayformula(INDEX(B:B,A:A))
if the latter worked as OP expected.
I know this is old now, but it turns out that INDEX() acts as a defacto ARRAYFORMULA() now. You can see a fabulous example of this on this google sheet, which shows how to use a and index(split()) to extract a particular set of text from a cell. The MK.demo tab provides a visual on how the array formula is implied with the INDEX() function.
Nowadays, using a FILTER() or QUERY() function can give the kinds of multiple vlookup the OP was looking for.
im not sure if its gonna work but i did an "IF(ISBLANK() before the INDEX(...) in the ARRAYFORMULA and it went down all the way

Resources