Skip to content

Commit

Permalink
Make tableName required in QueryBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
caithagoras0 authored and mbasmanova committed Dec 4, 2019
1 parent ed547be commit 2d3a241
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@
import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;

public class QueryBundle
{
private final Optional<QualifiedName> tableName;
private final QualifiedName tableName;
private final List<Statement> setupQueries;
private final Statement query;
private final List<Statement> teardownQueries;
private final ClusterType cluster;

public QueryBundle(
Optional<QualifiedName> tableName,
QualifiedName tableName,
List<Statement> setupQueries,
Statement query,
List<Statement> teardownQueries,
Expand All @@ -47,8 +45,7 @@ public QueryBundle(

public QualifiedName getTableName()
{
checkState(tableName.isPresent(), "tableName is missing");
return tableName.get();
return tableName;
}

public List<Statement> getSetupQueries()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static com.facebook.presto.verifier.framework.QueryStage.REWRITE;
import static com.facebook.presto.verifier.framework.QueryType.Category.DATA_PRODUCING;
import static com.facebook.presto.verifier.framework.VerifierUtil.PARSING_OPTIONS;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
Expand Down Expand Up @@ -76,16 +77,15 @@ public QueryBundle rewriteQuery(@Language("SQL") String query, ClusterType clust
{
checkState(prefixes.containsKey(clusterType), "Unsupported cluster type: %s", clusterType);
Statement statement = sqlParser.createStatement(query, PARSING_OPTIONS);
if (QueryType.of(statement).getCategory() != DATA_PRODUCING) {
return new QueryBundle(Optional.empty(), ImmutableList.of(), statement, ImmutableList.of(), clusterType);
}
QueryType queryType = QueryType.of(statement);
checkArgument(queryType.getCategory() == DATA_PRODUCING, "Unsupported statement type: %s", queryType);

QualifiedName prefix = prefixes.get(clusterType);
if (statement instanceof CreateTableAsSelect) {
CreateTableAsSelect createTableAsSelect = (CreateTableAsSelect) statement;
QualifiedName temporaryTableName = generateTemporaryTableName(Optional.of(createTableAsSelect.getName()), prefix);
return new QueryBundle(
Optional.of(temporaryTableName),
temporaryTableName,
ImmutableList.of(),
new CreateTableAsSelect(
temporaryTableName,
Expand All @@ -103,7 +103,7 @@ public QueryBundle rewriteQuery(@Language("SQL") String query, ClusterType clust
QualifiedName originalTableName = insert.getTarget();
QualifiedName temporaryTableName = generateTemporaryTableName(Optional.of(originalTableName), prefix);
return new QueryBundle(
Optional.of(temporaryTableName),
temporaryTableName,
ImmutableList.of(
new CreateTable(
temporaryTableName,
Expand All @@ -121,7 +121,7 @@ public QueryBundle rewriteQuery(@Language("SQL") String query, ClusterType clust
if (statement instanceof Query) {
QualifiedName temporaryTableName = generateTemporaryTableName(Optional.empty(), prefix);
return new QueryBundle(
Optional.of(temporaryTableName),
temporaryTableName,
ImmutableList.of(),
new CreateTableAsSelect(
temporaryTableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private LimitQueryDeterminismAnalysis analyze(String query)
{
return analyzer.analyze(
new QueryBundle(
Optional.of(TABLE_NAME),
TABLE_NAME,
ImmutableList.of(),
sqlParser.createStatement(query, PARSING_OPTIONS),
ImmutableList.of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public <R> QueryResult<R> execute(Statement statement, QueryStage queryStage, Re
private static final String TABLE_NAME = "test";
private static final int MAX_BUCKETS_PER_WRITER = 100;
private static final QueryBundle TEST_BUNDLE = new QueryBundle(
Optional.of(QualifiedName.of(TABLE_NAME)),
QualifiedName.of(TABLE_NAME),
ImmutableList.of(),
new SqlParser(new SqlParserOptions().allowIdentifierSymbol(AT_SIGN, COLON)).createStatement(
"INSERT INTO test SELECT * FROM source",
Expand Down

0 comments on commit 2d3a241

Please sign in to comment.