Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EXECUTE prepared statements
Syntax: EXECUTE <name> Executes the prepared statement named name. Does not yet support parameters.
- Loading branch information
1 parent
9417bb9
commit 49de083
Showing
13 changed files
with
238 additions
and
5 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
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
70 changes: 70 additions & 0 deletions
70
presto-main/src/test/java/com/facebook/presto/execution/TestUnwrapExecute.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,70 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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.facebook.presto.execution; | ||
|
||
import com.facebook.presto.Session; | ||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.sql.parser.SqlParser; | ||
import com.facebook.presto.sql.tree.AllColumns; | ||
import com.facebook.presto.sql.tree.QualifiedName; | ||
import com.facebook.presto.sql.tree.Statement; | ||
import org.testng.annotations.Test; | ||
|
||
import static com.facebook.presto.SessionTestUtils.TEST_SESSION; | ||
import static com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement; | ||
import static com.facebook.presto.spi.StandardErrorCode.NOT_FOUND; | ||
import static com.facebook.presto.sql.QueryUtil.selectList; | ||
import static com.facebook.presto.sql.QueryUtil.simpleQuery; | ||
import static com.facebook.presto.sql.QueryUtil.table; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.fail; | ||
|
||
public class TestUnwrapExecute | ||
{ | ||
private static final SqlParser SQL_PARSER = new SqlParser(); | ||
|
||
@Test | ||
public void testSelectStatement() | ||
throws Exception | ||
{ | ||
Statement statement = SQL_PARSER.createStatement("SELECT * FROM foo"); | ||
assertEquals(unwrapExecuteStatement(statement, SQL_PARSER, TEST_SESSION), | ||
simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")))); | ||
} | ||
|
||
@Test | ||
public void testExecuteStatement() | ||
throws Exception | ||
{ | ||
Session session = TEST_SESSION.withPreparedStatement("my_query", "SELECT * FROM foo"); | ||
Statement statement = SQL_PARSER.createStatement("EXECUTE my_query"); | ||
assertEquals(unwrapExecuteStatement(statement, SQL_PARSER, session), | ||
simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")))); | ||
} | ||
|
||
@Test | ||
public void testExecuteStatementDoesNotExist() | ||
throws Exception | ||
{ | ||
try { | ||
Statement statement = SQL_PARSER.createStatement("execute my_query"); | ||
unwrapExecuteStatement(statement, SQL_PARSER, TEST_SESSION); | ||
fail("expected exception"); | ||
} | ||
catch (PrestoException e) { | ||
assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode()); | ||
} | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
presto-parser/src/main/java/com/facebook/presto/sql/tree/Execute.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,80 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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.facebook.presto.sql.tree; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import static com.google.common.base.MoreObjects.toStringHelper; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class Execute | ||
extends Statement | ||
{ | ||
private final String name; | ||
|
||
public Execute(NodeLocation location, String name) | ||
{ | ||
this(Optional.of(location), name); | ||
} | ||
|
||
public Execute(String name) | ||
{ | ||
this(Optional.empty(), name); | ||
} | ||
|
||
private Execute(Optional<NodeLocation> location, String name) | ||
{ | ||
super(location); | ||
this.name = requireNonNull(name, "name is null"); | ||
} | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(AstVisitor<R, C> visitor, C context) | ||
{ | ||
return visitor.visitExecute(this, context); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) | ||
{ | ||
if (this == obj) { | ||
return true; | ||
} | ||
if ((obj == null) || (getClass() != obj.getClass())) { | ||
return false; | ||
} | ||
Execute o = (Execute) obj; | ||
return Objects.equals(name, o.name); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return toStringHelper(this) | ||
.add("name", name) | ||
.toString(); | ||
} | ||
} |
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
Oops, something went wrong.