This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support subquery in FROM clause in new engine (#822)
* support subquery in from * update * added java doc * added unit test * added comparison test cases * skipped a broken test in SubqueryIT.java due to different schema in new engine * added case for issue #375 * update * update * address comments * address comments * put the context push after subquery analysis recursion
- Loading branch information
Showing
14 changed files
with
222 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/tree/RelationSubquery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.ast.tree; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.ast.AbstractNodeVisitor; | ||
import com.amazon.opendistroforelasticsearch.sql.exception.SemanticCheckException; | ||
import com.google.common.collect.ImmutableList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Logical plan node of RelationSubquery. | ||
*/ | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
@RequiredArgsConstructor | ||
@ToString | ||
public class RelationSubquery extends UnresolvedPlan { | ||
private UnresolvedPlan query; | ||
private String alias; | ||
|
||
/** | ||
* Take subquery alias as table name. | ||
*/ | ||
public String getAliasAsTableName() { | ||
return alias; | ||
} | ||
|
||
@Override | ||
public List<UnresolvedPlan> getChild() { | ||
return ImmutableList.of(query); | ||
} | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitRelationSubquery(this, context); | ||
} | ||
|
||
@Override | ||
public UnresolvedPlan attach(UnresolvedPlan child) { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT flights.TEMP1 AS a, flights.TEMP2 AS b FROM (SELECT COUNT(*) AS TEMP1, SUM(AvgTicketPrice) AS TEMP2 FROM kibana_sample_data_flights) flights | ||
SELECT flights.origin AS a FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights GROUP BY origin, price) flights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SELECT Origin FROM (SELECT * FROM kibana_sample_data_flights) AS f | ||
SELECT f.Origin FROM (SELECT * FROM kibana_sample_data_flights) AS f | ||
SELECT f.o FROM (SELECT Origin AS o FROM kibana_sample_data_flights) AS f | ||
SELECT origin FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights WHERE AvgTicketPrice > 100) AS f | ||
SELECT origin FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights) AS f WHERE f.price > 100 | ||
SELECT origin FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights) AS f WHERE price > 100 | ||
SELECT origin FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights WHERE AvgTicketPrice > 100) AS f WHERE price < 1000 | ||
SELECT origin FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights) AS f ORDER BY f.price | ||
SELECT origin FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights) AS f ORDER BY price DESC | ||
SELECT origin, price FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights GROUP BY origin, price) AS f | ||
SELECT origin, price FROM (SELECT Origin AS origin, AvgTicketPrice AS price FROM kibana_sample_data_flights) AS f GROUP BY origin, price | ||
SELECT origin, price FROM (SELECT Origin AS origin, Dest AS dest, AvgTicketPrice AS price FROM kibana_sample_data_flights GROUP BY origin, dest, price) AS f GROUP BY origin, price | ||
SELECT origin, price FROM (SELECT Origin AS origin, Dest AS dest, AvgTicketPrice AS price FROM kibana_sample_data_flights GROUP BY 1, 2, 3) AS f GROUP BY 1, 2 | ||
SELECT ABS(AvgTicketPrice) FROM (SELECT AvgTicketPrice FROM kibana_sample_data_flights) AS flights GROUP BY ABS(AvgTicketPrice) | ||
SELECT Origin, Dest FROM (SELECT * FROM kibana_sample_data_flights WHERE AvgTicketPrice > 100 GROUP BY Origin, Dest, AvgTicketPrice) AS flights WHERE AvgTicketPrice < 1000 ORDER BY AvgTicketPrice | ||
SELECT Origin, MIN(AvgTicketPrice) FROM (SELECT * FROM kibana_sample_data_flights) AS flights GROUP BY Origin ORDER BY MAX(AvgTicketPrice) | ||
SELECT Origin FROM (SELECT Origin, AvgTicketPrice FROM kibana_sample_data_flights) AS flights GROUP BY Origin HAVING MIN(AvgTicketPrice) > 500 | ||
SELECT avg_price FROM (SELECT AVG(AvgTicketPrice) AS avg_price FROM kibana_sample_data_flights) AS flights | ||
SELECT Dest FROM (SELECT Dest, OriginWeather FROM (SELECT Dest, OriginWeather, AvgTicketPrice FROM (SELECT Dest, Origin, OriginWeather, AvgTicketPrice FROM kibana_sample_data_flights WHERE Origin = 'Zurich Airport') AS flights_data WHERE AvgTicketPrice < 10000) AS flights WHERE OriginWeather = 'Clear') AS f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters