Skip to content

Commit

Permalink
Remove unnecessary DataDefinitionTask execute arguments
Browse files Browse the repository at this point in the history
TransactionManager, Metadata, and AccessControl are available via
injection, so are not needed as arguments.
  • Loading branch information
dain committed Nov 28, 2021
1 parent 8065aa8 commit eb5b77d
Show file tree
Hide file tree
Showing 60 changed files with 512 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import io.trino.sql.tree.AddColumn;
import io.trino.sql.tree.ColumnDefinition;
import io.trino.sql.tree.Expression;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

import java.util.List;
import java.util.Map;
Expand All @@ -49,10 +50,21 @@
import static io.trino.sql.analyzer.TypeSignatureTranslator.toTypeSignature;
import static io.trino.type.UnknownType.UNKNOWN;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class AddColumnTask
implements DataDefinitionTask<AddColumn>
{
private final Metadata metadata;
private final AccessControl accessControl;

@Inject
public AddColumnTask(Metadata metadata, AccessControl accessControl)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
}

@Override
public String getName()
{
Expand All @@ -62,9 +74,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
AddColumn statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
18 changes: 15 additions & 3 deletions core/trino-main/src/main/java/io/trino/execution/CallTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import io.trino.sql.tree.Parameter;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -63,10 +65,23 @@
import static io.trino.sql.analyzer.SemanticExceptions.semanticException;
import static io.trino.sql.planner.ExpressionInterpreter.evaluateConstantExpression;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;

public class CallTask
implements DataDefinitionTask<Call>
{
private final TransactionManager transactionManager;
private final Metadata metadata;
private final AccessControl accessControl;

@Inject
public CallTask(TransactionManager transactionManager, Metadata metadata, AccessControl accessControl)
{
this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
}

@Override
public String getName()
{
Expand All @@ -76,9 +91,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
Call call,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
17 changes: 13 additions & 4 deletions core/trino-main/src/main/java/io/trino/execution/CommentTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import io.trino.sql.tree.Comment;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.QualifiedName;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

import java.util.List;
import java.util.Map;
Expand All @@ -37,10 +38,21 @@
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.StandardErrorCode.TABLE_NOT_FOUND;
import static io.trino.sql.analyzer.SemanticExceptions.semanticException;
import static java.util.Objects.requireNonNull;

public class CommentTask
implements DataDefinitionTask<Comment>
{
private final Metadata metadata;
private final AccessControl accessControl;

@Inject
public CommentTask(Metadata metadata, AccessControl accessControl)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
}

@Override
public String getName()
{
Expand All @@ -50,9 +62,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
Comment statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
16 changes: 11 additions & 5 deletions core/trino-main/src/main/java/io/trino/execution/CommitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@
import com.google.common.util.concurrent.ListenableFuture;
import io.trino.Session;
import io.trino.execution.warnings.WarningCollector;
import io.trino.metadata.Metadata;
import io.trino.security.AccessControl;
import io.trino.spi.TrinoException;
import io.trino.sql.tree.Commit;
import io.trino.sql.tree.Expression;
import io.trino.transaction.TransactionId;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

import java.util.List;

import static io.trino.spi.StandardErrorCode.NOT_IN_TRANSACTION;
import static java.util.Objects.requireNonNull;

public class CommitTask
implements DataDefinitionTask<Commit>
{
private final TransactionManager transactionManager;

@Inject
public CommitTask(TransactionManager transactionManager)
{
this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
}

@Override
public String getName()
{
Expand All @@ -40,9 +49,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
Commit statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.NodeRef;
import io.trino.sql.tree.Parameter;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

Expand All @@ -51,13 +50,17 @@
public class CreateMaterializedViewTask
implements DataDefinitionTask<CreateMaterializedView>
{
private final Metadata metadata;
private final AccessControl accessControl;
private final SqlParser sqlParser;
private final GroupProvider groupProvider;
private final StatsCalculator statsCalculator;

@Inject
public CreateMaterializedViewTask(SqlParser sqlParser, GroupProvider groupProvider, StatsCalculator statsCalculator)
public CreateMaterializedViewTask(Metadata metadata, AccessControl accessControl, SqlParser sqlParser, GroupProvider groupProvider, StatsCalculator statsCalculator)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
this.groupProvider = requireNonNull(groupProvider, "groupProvider is null");
this.statsCalculator = requireNonNull(statsCalculator, "statsCalculator is null");
Expand All @@ -72,9 +75,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
CreateMaterializedView statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import io.trino.sql.tree.CreateRole;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.Identifier;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

import java.util.List;
import java.util.Optional;
Expand All @@ -34,10 +35,21 @@
import static io.trino.spi.StandardErrorCode.ROLE_ALREADY_EXISTS;
import static io.trino.sql.analyzer.SemanticExceptions.semanticException;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class CreateRoleTask
implements DataDefinitionTask<CreateRole>
{
private final Metadata metadata;
private final AccessControl accessControl;

@Inject
public CreateRoleTask(Metadata metadata, AccessControl accessControl)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
}

@Override
public String getName()
{
Expand All @@ -47,9 +59,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
CreateRole statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import io.trino.spi.security.TrinoPrincipal;
import io.trino.sql.tree.CreateSchema;
import io.trino.sql.tree.Expression;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

import java.util.List;
import java.util.Map;
Expand All @@ -42,10 +43,21 @@
import static io.trino.sql.NodeUtils.mapFromProperties;
import static io.trino.sql.ParameterUtils.parameterExtractor;
import static io.trino.sql.analyzer.SemanticExceptions.semanticException;
import static java.util.Objects.requireNonNull;

public class CreateSchemaTask
implements DataDefinitionTask<CreateSchema>
{
private final Metadata metadata;
private final AccessControl accessControl;

@Inject
public CreateSchemaTask(Metadata metadata, AccessControl accessControl)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
}

@Override
public String getName()
{
Expand All @@ -55,9 +67,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
CreateSchema statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import io.trino.sql.tree.NodeRef;
import io.trino.sql.tree.Parameter;
import io.trino.sql.tree.TableElement;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

Expand Down Expand Up @@ -80,15 +79,20 @@
import static io.trino.sql.tree.LikeClause.PropertiesOption.INCLUDING;
import static io.trino.type.UnknownType.UNKNOWN;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class CreateTableTask
implements DataDefinitionTask<CreateTable>
{
private final Metadata metadata;
private final AccessControl accessControl;
private final boolean disableSetPropertiesSecurityCheckForCreateDdl;

@Inject
public CreateTableTask(FeaturesConfig featuresConfig)
public CreateTableTask(Metadata metadata, AccessControl accessControl, FeaturesConfig featuresConfig)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
this.disableSetPropertiesSecurityCheckForCreateDdl = featuresConfig.isDisableSetPropertiesSecurityCheckForCreateDdl();
}

Expand All @@ -101,18 +105,15 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
CreateTable statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
{
return internalExecute(statement, metadata, accessControl, stateMachine.getSession(), parameters, output -> stateMachine.setOutput(Optional.of(output)));
return internalExecute(statement, stateMachine.getSession(), parameters, output -> stateMachine.setOutput(Optional.of(output)));
}

@VisibleForTesting
ListenableFuture<Void> internalExecute(CreateTable statement, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, Consumer<Output> outputConsumer)
ListenableFuture<Void> internalExecute(CreateTable statement, Session session, List<Expression> parameters, Consumer<Output> outputConsumer)
{
checkArgument(!statement.getElements().isEmpty(), "no columns for table");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.trino.sql.parser.SqlParser;
import io.trino.sql.tree.CreateView;
import io.trino.sql.tree.Expression;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

Expand All @@ -47,13 +46,17 @@
public class CreateViewTask
implements DataDefinitionTask<CreateView>
{
private final Metadata metadata;
private final AccessControl accessControl;
private final SqlParser sqlParser;
private final GroupProvider groupProvider;
private final StatsCalculator statsCalculator;

@Inject
public CreateViewTask(SqlParser sqlParser, GroupProvider groupProvider, StatsCalculator statsCalculator)
public CreateViewTask(Metadata metadata, AccessControl accessControl, SqlParser sqlParser, GroupProvider groupProvider, StatsCalculator statsCalculator)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.accessControl = requireNonNull(accessControl, "accessControl is null");
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
this.groupProvider = requireNonNull(groupProvider, "groupProvider is null");
this.statsCalculator = requireNonNull(statsCalculator, "statsCalculator is null");
Expand All @@ -68,9 +71,6 @@ public String getName()
@Override
public ListenableFuture<Void> execute(
CreateView statement,
TransactionManager transactionManager,
Metadata metadata,
AccessControl accessControl,
QueryStateMachine stateMachine,
List<Expression> parameters,
WarningCollector warningCollector)
Expand Down
Loading

0 comments on commit eb5b77d

Please sign in to comment.