-
Notifications
You must be signed in to change notification settings - Fork 227
Support derived tables #5
Comments
Hi James, As and when usage of Phoenix increase, the demand for Nested queries will shoot up. Can you please consider this in your subsequent releases? Regards, |
Thanks for the feedback, @jhanit. Would you be able to provide some sample queries for your nested query use cases, as this would ensure it'll meet your needs? Often times, with the lack of derived tables, a "poor man's" workaround is to perform the inner query using UPSERT SELECT into a temp table, and then referencing the temp table in the outer query. Would this work for you in the interim? |
Hi James, Please find the sample nested queries use case along with SQL queries which i have tested with sql. col1,col2,col3,col4 are dynamic(for SQl i just added while creating table). Requirement:- My SQL querry:- 1st Approachselect Ent.entity,Ent.Facility, Att.Col1,Att.Col2,Att.Col3,Att.Col4 from (select distinct entity,facility from event_mgmt where entity is not null and facility is not null) Ent join (select * from (select entity, col1, col2 from ( select entity, col1, col2, ROW_NUMBER() OVER ( partition by entity order by eventTime desc) rn from event_mgmt where entity is not null) A where rn = 1) A, (select facility, col3, col4 from ( select facility, col3, col4, ROW_NUMBER() OVER ( partition by facility order by eventTime desc) rn from event_mgmt where facility is not null) A where rn = 1) B) Att on Ent.Entity = Att.Entity and Ent.Facility = Att.Facility 2nd ApproachTrying to use temp table by converting the above query into more update(which will translate into upsert select). But i was unable to get rid off join some how. --get prelim data in temp table select distinct entity,facility, cast (null as int) as col1, cast (null as varchar) as col2, cast (null as int) as col3, cast (null as varchar) as col4 into ##TempTable from event_mgmt where entity is not null and facility is not null --update the Entity columns col1 update A set Col1 = B.Col1 from ##TempTable A join (select entity, col1 from ( select entity, col1, ROW_NUMBER() OVER ( partition by entity order by eventTime desc) rn from event_mgmt where entity is not null and col1 is not null) A where rn = 1) B on A.Entity = B.Entity --update the Entity columns col2 update A set Col2 = B.Col2 from ##TempTable A join (select entity, col2 from ( select entity, col2, ROW_NUMBER() OVER ( partition by entity order by eventTime desc) rn from event_mgmt where entity is not null and col2 is not null) A where rn = 1) B on A.Entity = B.Entity --update the facility columns col3 update A set Col3 = B.Col3 from ##TempTable A join (select facility, col3 from ( select facility, col3, ROW_NUMBER() OVER ( partition by facility order by eventTime desc) rn from event_mgmt where facility is not null and col3 is not null) A where rn = 1) B on A.facility = B.facility --update the facility columns col4 update A set Col4 = B.Col4 from ##TempTable A join (select facility, col4 from ( select facility, col4, ROW_NUMBER() OVER ( partition by facility order by eventTime desc) rn from event_mgmt where facility is not null and col4 is not null) A where rn = 1) B on A.facility = B.facility --select results from the temp table select * from ##TempTable --drop the temp table drop table ##TempTable This is use case 1. And i have several like this which i will start working on. Is it possible for a workaround for now(I tried but somehow unable to get rid off Join), as this will decide my phoenix usage extensively? Any help or timelines to get these features in phoenix will be helpful for me. |
Thanks, @jhanit for the detail - very helpful. We have support for joins in our master branch. Can you let us know if this together with upsert/select will meet your need in the short term? |
I am trying with join. Error:-Syntax error. Missing "EOF" at line 1, column 87.
|
Are you using the master branch? On Nov 18, 2013, at 6:41 AM, Nitin Kumar notifications@github.com wrote: I am trying with join. Error:-Syntax error. Missing "EOF" at line 1, column 87.
— |
Hi, I hit a road block with my approach. As per our earlier discussion (how to proceed with join and nested query), Issue:- Error: Joins not supported (state=,code=0) Where Join worked with select and UPSERT select worked in other cases.To my disappointment when i combine both it didn't work. I will be really happy if 'YES' is an answer for any of the above question.Eagerly waiting for reply :-) Thanks, |
FYI, for those interested in this feature, it will be in our 3.1/4.1 release and is available in our Apache Phoenix 3.0/4.0/master branches now. See https://issues.apache.org/jira/browse/PHOENIX-136 and https://issues.apache.org/jira/browse/PHOENIX-927 |
Add support for derived queries of the form:
SELECT * FROM ( SELECT company, revenue FROM Company ORDER BY revenue) LIMIT 10
Adding support for this requires a compile time change as well as a runtime execution change. The first version of the compile-time change could limit aggregation to only be allowed in the inner or the outer query, but not both. In this case, the inner and outer queries can be combined into a single query with the outer select becoming just a remapping of a subset of the projection from the inner select. The second version of the compile-time change could handle aggregation in the inner and outer select by performing client side (this is likely a less common scenario).
For the runtime execution, change the UngroupedAggregateRegionObserver would be modified to look for a new "TopNLimit" attribute with an int value in the Scan. This would control the maximum number of values for the coprocessor to hold on to as the scan is performed. Then the GroupedAggregatingResultIterator would be modified to handle keeping the topN values received back from all the child iterators.
The text was updated successfully, but these errors were encountered: