You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by hagersaleh <lo...@yahoo.com> on 2015/07/04 16:01:31 UTC

How can handles Exist ,not Exist query on flink

How can handles Exist ,not Exist , all and any in query
Example
SELECT P.PRODUCT_ID,
 P.PRODUCT_NAME
FROM PRODUCTS P
WHERE NOT EXISTS
 (
 SELECT  1
 FROM SALES S
 WHERE S.PRODUCT_ID = P.PRODUCT_ID);





--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Re: How can handles Exist ,not Exist query on flink

Posted by hagersaleh <lo...@yahoo.com>.
when write this code display error
 no interface expected here public static class MyCoGrouper extends
CoGroupFunction<Customer,Orders,Result> {

ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        DataSet<Customer> customers = getCustomerDataSet(env,mask,l,map);

        DataSet<Orders> orders= getOrdersDataSet(env,maskorder,l1,maporder);

        DataSet<Result> result =
customers.coGroup(orders).where(0).equalTo(1).with
            (new CoGroupFunction<Customer,Orders,Result>() {

        @Override
        public void coGroup(Iterator<Customer> leftElements,
                            Iterator<Orders> rightElements,
                           Collector<Result> out) throws Exception {

                 if(rightElements.hasNext()) {
           while(leftElements.hasNext()) {

        out.collect(new
Result(leftElements.next().f0,leftElements.next().f1,rightElements.next().f0
               ,rightElements.next().f1,rightElements.next().f2));

        }
        }

        }
        });



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p2196.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Re: How can handles Exist ,not Exist query on flink

Posted by Michele Bertoni <mi...@mail.polimi.it>.
ds1.filter(//here selection of query 1)
ds2.filter(//here selection of query 2)

exist
ds1.join(ds2.distinct(id)).where(id).equal(id){ // join by your join key(s) - note the distinct operator, otherwise you will get many line for each input line
(left, right) => left //collect left
}

or

ds1.cogroup(ds2).where(id).equal(id){ //cogroup by your join key(s)
(left : Iterator, right: Iterator, out: Collector) => 
if(right.hasNext) //exist something in right dataset
	while(left.hasNext) //collect all the left
		out.collect(left.next)
}



not exist

ds1.cogroup(ds2).where(id).equal(id){ //cogroup by your join key(s)
(left : Iterator, right: Iterator, out: Collector) => 
if( ! right.hasNext) //nothing exists in right dataset - note the not (exclamation mark) in front
	while(left.hasNext) //collect all the left
		out.collect(left.next)
}




in short you are doing a full-outer-join and keeping only elements with at [ least one(exist) | no(not exist) ] matching element


this is just a sketch written on my smartphone you should re-adapt it to your query
cheers



> Il giorno 16/lug/2015, alle ore 00:44, hagersaleh <lo...@yahoo.com> ha scritto:
> 
> please help 
> I want example 
> 
> 
> 
> --
> View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p2068.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.


Re: How can handles Exist ,not Exist query on flink

Posted by hagersaleh <lo...@yahoo.com>.
please help 
I want example 



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p2068.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Re: How can handles Exist ,not Exist query on flink

Posted by hagersaleh <lo...@yahoo.com>.
I want example on use join or co group for handles Exists or not Exists



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p2006.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Re: How can handles Exist ,not Exist query on flink

Posted by hagersaleh <lo...@yahoo.com>.
Meaning it can not be implemented Exist and not Exist on Filnk but look for
alternative query
example
where 0 < (select count(selitem) from fromritem)



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p1976.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Re: How can handles Exist ,not Exist query on flink

Posted by hagersaleh <lo...@yahoo.com>.
thanks



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p1975.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Re: How can handles Exist ,not Exist query on flink

Posted by Fabian Hueske <fh...@gmail.com>.
Hi,

if you decorrelate the subquery, you can execute EXIST or NOT EXIST with a
join or co group.

If you search for "subquery decorrelation" you will find a good amount of
information.
Note that subquery decorrelation is not possble in general. Queries with
subqueries that cannot be decorrelated cannot be executed efficiently by
Flink (and other parallel system struggle with that as well).

cheers, Fabian

2015-07-07 16:26 GMT+02:00 hagersaleh <lo...@yahoo.com>:

> please help
>
>
>
> --
> View this message in context:
> http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p1973.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive
> at Nabble.com.
>

Re: How can handles Exist ,not Exist query on flink

Posted by hagersaleh <lo...@yahoo.com>.
please help



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-can-handles-Exist-not-Exist-query-on-flink-tp1939p1973.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.