jpa 2.0: how to do a sql minus of a collection with a table - jpa-2.0

I am looking for a JPQL or Criteria expression to find a subset of integers(codes) in my collection which are not in the table.
Native Query for Oracle DB would be:
SELECT column_value
FROM Table(:listOfCodes)
MINUS
SELECT code
FROM table1;
This is similar to the post here but not exactly what i want jpa 2.0 criteria api expression for sql minus
Any pointers/help would be much appreciated.

You could just query for the values that are in the table and in your set, and then take the complement of what the query returns:
List<Integer> valuesInTheTable =
(List<Integer>) em.createQuery("select a.column from Entity a where a in (:values)")
.setParameter("values", values)
.getResultList();
Set<Integer> valuesNotInTheTable = new HashSet<Integer>(values);
valuesNotInTheTable.removeAll(valuesInTheTable);

Related

Parsing DAX Query with Regular expression to get measures and dimensions

I want to create an application that uses Extended Events to analyze the usage of Azure Analysis Services models.
Specifically, I want to know what measures and dimensions the end users are using.
I look at the QueryEnd event and try to parse the TextData field. Depending on the tool used for querying the model I get either MDX or DAX in the TextData.
I think I have managed to parse the MDX with this RegEx: ([[\w ]+].[[\w ]+](?:.(?:Members|[Q\d]))?)
(from this post: Regular expression for extracting element from MDX Query)
Now parsing the DAX is the problem. If I query the model from fx PowerBI I get a DAX like this:
EVALUATE
TOPN(
502,
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL('Product'[Color], \"IsGrandTotalRowTotal\"),
\"Order_Count\", 'SalesOrderDetail'[Order Count]
),
[IsGrandTotalRowTotal],
0,
[Order_Count],
0,
'Product'[Color],
1
)
ORDER BY
[IsGrandTotalRowTotal] DESC, [Order_Count] DESC, 'Product'[Color]
What I would like to match with the RegEx is:
'Product'[Color] and 'SalesOrderDetail'[Order Count]
And.... how would i know that Order Count is used as a measyre while Color is an attribute of the Product dimension?..... guess I won't?
Thanx a lot
Nicolaj
think I just found a possible solution for parsing both DAX and MDX queries:
([\[\'][\w ]+[\]\']\.?[\[\'][\w ]+[\]\'])(?!.*\1)
This will give me what I need.... without duplicates. Improvements are welcomed :-)
For disambiguating columns from measures, I would query the DMVs for the deployed model to get a list of columns and a list of measures. Then you can just look up your parsed tokens in the two lists:
DMV docs
Column DMV
Measure DMV.
Note that measure names are globally unique among the population of column and measure names, so that is an easy lookup (just throw away the table reference). Column names are only unique within the table they belong to.
It looks like you've already got a regex that's working for you, so run with that.
I'll also note that almost all PBI visuals which are returning anything other than a simple list (e.g. slicers or one column tables will return just a list) will follow the pattern of the query you shared.
Measures should all be in later args to SUMMARIZECOLUMNS. The pattern is:
SUMMARIZECOLUMNS (
<grouping columns, optionally in a ROLLUPADDISSUBTOTAL>,
<filters, defined above in VARs>,
<measures as ("Alias", [Measure]) pairs>
)

How to filter selective data from a postgres using PDI components?

For example : I have a column named description, in this column there are millions of records. I just want to filter records only with "a=x" (where x can be any value) using pentaho?.This pattern can be at any position in the column
Assuming that in your description column you always have a value after the pattern 'a=' you could just do the filtering in PostgreSQL using LIKE
SELECT
description
FROM
your_table
WHERE
description LIKE '%a=%'
Then you just put this query inside a Table Input step in your transformation.

Need to apply filter on using OR condition

I have Dataset in PowerBI as below.
In PowerBI Desktop I want to filter records of below table based on condition described below.
ProjectName ReleaseDate UserReleaseDate
PROJ-1 12/09/2019 null
PROJ-2 null 02/02/2019
PROJ-3 07/07/2018 null
Date are in DD/MM/YYYY format.
I want to filter those records where
(ReleaseDate OR UserReleaseDate is IsInNextNYears(1))
You pretty much just do exactly what you described.
Table.SelectRows(YourTable, each (Date.IsInNextNYears([ReleaseDate], 1) or Date.IsInNextNYears([UserReleaseDate], 1)))
If you use any filter operation on a column in Power Query it will automatically create a Table.SelectRows step that you can edit to do what you want instead.

RegEx in the select for DB2

I have a table with one column having a large json object in the format below. The column datatype is VARCHAR
column1
--------
{"key":"value",....}
I'm interested in the first value of the column data
in regex I can do it by .*?:(.*),.* with group(1) giving me the value
How can i use it in the select query
Don't do that, it's bad database design. Shred the keys and values to their own table as columns, or use the XML data type. XML would work fine because you can index the structure well, and you can use XPATH queries on the data. XPATH supports regexp natively.
You can use regular expression with xQuery, you just need to call the function matches from a SQL query or a FLORW query.
This is an example of how to use regular expressions from SQL:
db2 "with val as (
select t.text
from texts t
where xmlcast(xmlquery('fn:matches(\$TEXT,''^[A-Za-z 0-9]*$'')') as integer) = 0
)
select * from val"
For more information:
http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.xml.doc/doc/xqrfnmat.html
http://angocadb2.blogspot.fr/2014/04/regular-expressions-in-db2.html
DB2 doesn't have any built in regex functionality, unfortunately. I did find an article about how to add this with libraries:
http://www.ibm.com/developerworks/data/library/techarticle/0301stolze/0301stolze.html
Without regexes, this operation would be a mess. You could make a function that goes through the string character by character to find the first value. Or, if you will need to do more than this one operation, you could make a procedure that parses the json and throws it into a table of keys/values. Neither one sounds fun, though.
In DB2 for z/OS you will have to pass the variable to XMLQUERY with the PASSING option
db2 "with val as (
select t.text
from texts t
where xmlcast(xmlquery('fn:matches($TEXT,''^[A-Za-z 0-9]*$'')'
PASSING t.text as "TEXT") as integer) = 0
)
select * from val"

Wildcard search on Date fields

I use HSQLDB2.0 and JPA2.0 for my current project and have few date columns in DB.
I would like to run wildcard queries on the date columns. How could I do that?
Ex : If my DB contains two rows with date values as : 10-01-2011 and 15-02-2011
and my search criteria will be "%10-01%", then result should be 10-01-2011.
Else if search criteria is "%2011%" then both rows need to be fetched with the select query.
Thanks in advance,
Satya
You can define an autogenerated column of type VARCHAR containing a copy of the date. You can then perform queries with both LIKE predicates and REGEXP_MATCHES() function. An example of the column definition is below:
DATEGEN VARCHAR(10) GENERATED ALWAYS AS (CAST(DATECOL AS VARCHAR(10))
Note the string representation of DATE is in the form '2011-02-26' and your query strings should follow this pattern.
This can be achieved in this format :
select date_birth from member where to_char(date_birth,'MM-yyyy') like '%02-2011%'
select date_birth from member where to_char(date_birth,'MM-dd') like '%02-15%'
select date_birth from member where to_char(date_birth,'dd-yyyy') like '%30-2011%'
Regards,
Satya