Java 类com.facebook.presto.metadata.Metadata 实例源码

项目:presto    文件:DropTableTask.java   
@Override
public CompletableFuture<?> execute(DropTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());

    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        if (!statement.isExists()) {
            throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
        }
        return completedFuture(null);
    }

    accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    metadata.dropTable(session, tableHandle.get());

    return completedFuture(null);
}
项目:presto    文件:RenameTableTask.java   
@Override
public CompletableFuture<?> execute(RenameTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }

    QualifiedObjectName target = createQualifiedObjectName(session, statement, statement.getTarget());
    if (!metadata.getCatalogNames().containsKey(target.getCatalogName())) {
        throw new SemanticException(MISSING_CATALOG, statement, "Target catalog '%s' does not exist", target.getCatalogName());
    }
    if (metadata.getTableHandle(session, target).isPresent()) {
        throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Target table '%s' already exists", target);
    }
    if (!tableName.getCatalogName().equals(target.getCatalogName())) {
        throw new SemanticException(NOT_SUPPORTED, statement, "Table rename across catalogs is not supported");
    }
    accessControl.checkCanRenameTable(session.getRequiredTransactionId(), session.getIdentity(), tableName, target);

    metadata.renameTable(session, tableHandle.get(), target);

    return completedFuture(null);
}
项目:presto    文件:QueryExplainer.java   
@Inject
public QueryExplainer(
        List<PlanOptimizer> planOptimizers,
        Metadata metadata,
        AccessControl accessControl,
        SqlParser sqlParser,
        Map<Class<? extends Statement>, DataDefinitionTask<?>> dataDefinitionTask,
        FeaturesConfig featuresConfig)
{
    this(planOptimizers,
            metadata,
            accessControl,
            sqlParser,
            dataDefinitionTask,
            featuresConfig.isExperimentalSyntaxEnabled());
}
项目:presto    文件:CreateViewTask.java   
@Override
public CompletableFuture<?> execute(CreateView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());

    accessControl.checkCanCreateView(session.getRequiredTransactionId(), session.getIdentity(), name);

    String sql = getFormattedSql(statement);

    Analysis analysis = analyzeStatement(statement, session, metadata);

    List<ViewColumn> columns = analysis.getOutputDescriptor()
            .getVisibleFields().stream()
            .map(field -> new ViewColumn(field.getName().get(), field.getType()))
            .collect(toImmutableList());

    String data = codec.toJson(new ViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, Optional.of(session.getUser())));

    metadata.createView(session, name, data, statement.isReplace());

    return completedFuture(null);
}
项目:presto    文件:LocalExecutionPlanner.java   
private static TableFinisher createTableFinisher(Session session, TableFinishNode node, Metadata metadata)
{
    WriterTarget target = node.getTarget();
    return new TableFinisher()
    {
        @Override
        public void finishTable(Collection<Slice> fragments)
        {
            if (target instanceof CreateHandle) {
                metadata.finishCreateTable(session, ((CreateHandle) target).getHandle(), fragments);
            }
            else if (target instanceof InsertHandle) {
                metadata.finishInsert(session, ((InsertHandle) target).getHandle(), fragments);
            }
            else if (target instanceof DeleteHandle) {
                metadata.finishDelete(session, ((DeleteHandle) target).getHandle(), fragments);
            }
            else {
                throw new AssertionError("Unhandled target type: " + target.getClass().getName());
            }
        }
    };
}
项目:presto    文件:InterpretedProjectionFunction.java   
public InterpretedProjectionFunction(
        Expression expression,
        Map<Symbol, Type> symbolTypes,
        Map<Symbol, Integer> symbolToInputMappings,
        Metadata metadata,
        SqlParser sqlParser,
        Session session)
{
    // pre-compute symbol -> input mappings and replace the corresponding nodes in the tree
    Expression rewritten = ExpressionTreeRewriter.rewriteWith(new SymbolToInputRewriter(symbolToInputMappings), expression);

    // analyze expression so we can know the type of every expression in the tree
    ImmutableMap.Builder<Integer, Type> inputTypes = ImmutableMap.builder();
    for (Map.Entry<Symbol, Integer> entry : symbolToInputMappings.entrySet()) {
        inputTypes.put(entry.getValue(), symbolTypes.get(entry.getKey()));
    }
    IdentityHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(session, metadata, sqlParser, inputTypes.build(), rewritten);
    this.type = requireNonNull(expressionTypes.get(rewritten), "type is null");

    evaluator = ExpressionInterpreter.expressionInterpreter(rewritten, metadata, session, expressionTypes);
    InputReferenceExtractor inputReferenceExtractor = new InputReferenceExtractor();
    inputReferenceExtractor.process(rewritten, null);
    this.inputChannels = inputReferenceExtractor.getInputChannels();
    this.deterministic = DeterminismEvaluator.isDeterministic(expression);
}
项目:presto    文件:ExpressionInterpreter.java   
public static Object evaluateConstantExpression(Expression expression, Type expectedType, Metadata metadata, Session session)
{
    ExpressionAnalyzer analyzer = createConstantAnalyzer(metadata, session);
    analyzer.analyze(expression, new RelationType(), new AnalysisContext());

    Type actualType = analyzer.getExpressionTypes().get(expression);
    if (!canCoerce(actualType, expectedType)) {
        throw new SemanticException(SemanticErrorCode.TYPE_MISMATCH, expression, String.format("Cannot cast type %s to %s",
                expectedType.getTypeSignature(),
                actualType.getTypeSignature()));
    }

    IdentityHashMap<Expression, Type> coercions = new IdentityHashMap<>();
    coercions.putAll(analyzer.getExpressionCoercions());
    coercions.put(expression, expectedType);
    return evaluateConstantExpression(expression, coercions, metadata, session, ImmutableSet.of());
}
项目:presto    文件:StatementAnalyzer.java   
public StatementAnalyzer(
        Analysis analysis,
        Metadata metadata,
        SqlParser sqlParser,
        AccessControl accessControl, Session session,
        boolean experimentalSyntaxEnabled,
        Optional<QueryExplainer> queryExplainer)
{
    this.analysis = requireNonNull(analysis, "analysis is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
    this.accessControl = requireNonNull(accessControl, "accessControl is null");
    this.session = requireNonNull(session, "session is null");
    this.experimentalSyntaxEnabled = experimentalSyntaxEnabled;
    this.queryExplainer = requireNonNull(queryExplainer, "queryExplainer is null");
}
项目:presto    文件:IndexJoinOptimizer.java   
public static Optional<PlanNode> rewriteWithIndex(
        PlanNode planNode,
        Set<Symbol> lookupSymbols,
        SymbolAllocator symbolAllocator,
        PlanNodeIdAllocator idAllocator,
        Metadata metadata,
        Session session)
{
    AtomicBoolean success = new AtomicBoolean();
    IndexSourceRewriter indexSourceRewriter = new IndexSourceRewriter(symbolAllocator, idAllocator, metadata, session);
    PlanNode rewritten = SimplePlanRewriter.rewriteWith(indexSourceRewriter, planNode, new Context(lookupSymbols, success));
    if (success.get()) {
        return Optional.of(rewritten);
    }
    return Optional.empty();
}
项目:presto    文件:ExpressionAnalyzer.java   
public static ExpressionAnalysis analyzeExpressionsWithSymbols(
        Session session,
        Metadata metadata,
        SqlParser sqlParser,
        Map<Symbol, Type> types,
        Iterable<? extends Expression> expressions)
{
    List<Field> fields = DependencyExtractor.extractUnique(expressions).stream()
            .map(symbol -> {
                Type type = types.get(symbol);
                checkArgument(type != null, "No type for symbol %s", symbol);
                return Field.newUnqualified(symbol.getName(), type);
            })
            .collect(toImmutableList());

    return analyzeExpressions(session, metadata, sqlParser, new RelationType(fields), expressions);
}
项目:presto    文件:ExpressionAnalyzer.java   
private static ExpressionAnalysis analyzeExpressions(
        Session session,
        Metadata metadata,
        SqlParser sqlParser,
        RelationType tupleDescriptor,
        Iterable<? extends Expression> expressions)
{
    // expressions at this point can not have sub queries so deny all access checks
    // in the future, we will need a full access controller here to verify access to functions
    ExpressionAnalyzer analyzer = create(new Analysis(), session, metadata, sqlParser, new DenyAllAccessControl(), false);
    for (Expression expression : expressions) {
        analyzer.analyze(expression, tupleDescriptor, new AnalysisContext());
    }

    return new ExpressionAnalysis(
            analyzer.getExpressionTypes(),
            analyzer.getExpressionCoercions(),
            analyzer.getSubqueryInPredicates(),
            analyzer.getScalarSubqueries(),
            analyzer.getResolvedNames().keySet());
}
项目:presto    文件:TestHiveIntegrationSmokeTest.java   
private List<HivePartition> getPartitions(String tableName)
{
    Session session = getSession();
    Metadata metadata = ((DistributedQueryRunner) queryRunner).getCoordinator().getMetadata();

    return transaction(queryRunner.getTransactionManager())
            .readOnly()
            .execute(session, transactionSession -> {
                Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(HIVE_CATALOG, TPCH_SCHEMA, tableName));
                assertTrue(tableHandle.isPresent());

                List<TableLayoutResult> layouts = metadata.getLayouts(transactionSession, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty());
                TableLayout layout = Iterables.getOnlyElement(layouts).getLayout();
                return ((HiveTableLayoutHandle) layout.getHandle().getConnectorHandle()).getPartitions().get();
            });
}
项目:presto    文件:CodecSupplier.java   
public CodecSupplier(Class<T> clazz, Metadata metadata)
{
    this.clazz = clazz;
    this.metadata = metadata;
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.<Class<?>, JsonDeserializer<?>>of(Type.class, new TypeDeserializer()));
    this.codecFactory = new JsonCodecFactory(objectMapperProvider);
}
项目:presto    文件:CodecSupplier.java   
public CodecSupplier(Class<T> clazz, Metadata metadata)
{
    this.clazz = clazz;
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.<Class<?>, JsonDeserializer<?>>of(Type.class, new TypeDeserializer(metadata)));
    this.codecFactory = new JsonCodecFactory(objectMapperProvider);
}
项目:presto    文件:RedisQueryRunner.java   
private static Map<SchemaTableName, RedisTableDescription> createTpchTableDescriptions(Metadata metadata, Iterable<TpchTable<?>> tables, String dataFormat)
        throws Exception
{
    JsonCodec<RedisTableDescription> tableDescriptionJsonCodec = new CodecSupplier<>(RedisTableDescription.class, metadata).get();

    ImmutableMap.Builder<SchemaTableName, RedisTableDescription> tableDescriptions = ImmutableMap.builder();
    for (TpchTable<?> table : tables) {
        String tableName = table.getTableName();
        SchemaTableName tpchTable = new SchemaTableName(TPCH_SCHEMA, tableName);

        tableDescriptions.put(loadTpchTableDescription(tableDescriptionJsonCodec, tpchTable, dataFormat));
    }
    return tableDescriptions.build();
}
项目:presto    文件:AbstractTestQueryFramework.java   
private QueryExplainer getQueryExplainer()
{
    Metadata metadata = queryRunner.getMetadata();
    FeaturesConfig featuresConfig = new FeaturesConfig().setExperimentalSyntaxEnabled(true).setOptimizeHashGeneration(true);
    boolean forceSingleNode = queryRunner.getNodeCount() == 1;
    List<PlanOptimizer> optimizers = new PlanOptimizersFactory(metadata, sqlParser, featuresConfig, forceSingleNode).get();
    return new QueryExplainer(
            optimizers,
            metadata,
            queryRunner.getAccessControl(),
            sqlParser,
            ImmutableMap.of(),
            featuresConfig.isExperimentalSyntaxEnabled());
}
项目:presto    文件:InformationSchemaConnector.java   
public InformationSchemaConnector(String catalogName, NodeManager nodeManager, Metadata metadata)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(nodeManager, "nodeManager is null");
    requireNonNull(metadata, "metadata is null");

    this.metadata = new InformationSchemaMetadata(catalogName);
    this.splitManager = new InformationSchemaSplitManager(nodeManager);
    this.pageSourceProvider = new InformationSchemaPageSourceProvider(metadata);
}
项目:presto    文件:MetadataDeleteOperator.java   
public MetadataDeleteOperatorFactory(int operatorId, PlanNodeId planNodeId, TableLayoutHandle tableLayout, Metadata metadata, Session session, TableHandle tableHandle)
{
    this.operatorId = operatorId;
    this.planNodeId = requireNonNull(planNodeId, "planNodeId is null");
    this.tableLayout = requireNonNull(tableLayout, "tableLayout is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.session = requireNonNull(session, "session is null");
    this.tableHandle = requireNonNull(tableHandle, "tableHandle is null");
}
项目:presto    文件:MetadataDeleteOperator.java   
public MetadataDeleteOperator(OperatorContext operatorContext, TableLayoutHandle tableLayout, Metadata metadata, Session session, TableHandle tableHandle)
{
    this.operatorContext = requireNonNull(operatorContext, "operatorContext is null");
    this.tableLayout = requireNonNull(tableLayout, "tableLayout is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.session = requireNonNull(session, "session is null");
    this.tableHandle = requireNonNull(tableHandle, "tableHandle is null");
}
项目:presto    文件:ResetSessionTask.java   
@Override
public CompletableFuture<?> execute(ResetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    if (statement.getName().getParts().size() > 2) {
        throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", statement.getName());
    }

    // validate the property name
    metadata.getSessionPropertyManager().getSessionPropertyMetadata(statement.getName().toString());

    stateMachine.addResetSessionProperties(statement.getName().toString());

    return completedFuture(null);
}
项目:presto    文件:CommitTask.java   
@Override
public CompletableFuture<?> execute(Commit statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    if (!session.getTransactionId().isPresent()) {
        throw new PrestoException(NOT_IN_TRANSACTION, "No transaction in progress");
    }
    TransactionId transactionId = session.getTransactionId().get();

    stateMachine.clearTransactionId();
    return transactionManager.asyncCommit(transactionId);
}
项目:presto    文件:RenameColumnTask.java   
@Override
public CompletableFuture<?> execute(RenameColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTable());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);

    String source = statement.getSource().toLowerCase(ENGLISH);
    String target = statement.getTarget().toLowerCase(ENGLISH);

    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }
    accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle.get());
    if (!columnHandles.containsKey(source)) {
        throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
    }

    if (columnHandles.containsKey(target)) {
        throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", target);
    }
    metadata.renameColumn(session, tableHandle.get(), columnHandles.get(source), target);

    return completedFuture(null);
}
项目:presto    文件:SetSessionTask.java   
@Override
public CompletableFuture<?> execute(SetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedName propertyName = statement.getName();
    if (propertyName.getParts().size() > 2) {
        throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", propertyName);
    }

    PropertyMetadata<?> propertyMetadata = metadata.getSessionPropertyManager().getSessionPropertyMetadata(propertyName.toString());

    if (propertyName.getParts().size() == 1) {
        accessControl.checkCanSetSystemSessionProperty(session.getIdentity(), propertyName.getParts().get(0));
    }
    else if (propertyName.getParts().size() == 2) {
        accessControl.checkCanSetCatalogSessionProperty(session.getIdentity(), propertyName.getParts().get(0), propertyName.getParts().get(1));
    }

    Type type = propertyMetadata.getSqlType();
    Object objectValue;

    try {
        objectValue = evaluatePropertyValue(statement.getValue(), type, session, metadata);
    }
    catch (SemanticException e) {
        throw new PrestoException(StandardErrorCode.INVALID_SESSION_PROPERTY,
                format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getMessage()));
    }

    String value = serializeSessionProperty(type, objectValue);

    // verify the SQL value can be decoded by the property
    metadata.getSessionPropertyManager().decodeProperty(propertyName.toString(), value, propertyMetadata.getJavaType());
    stateMachine.addSetSessionProperties(propertyName.toString(), value);

    return completedFuture(null);
}
项目:presto    文件:CreateTableTask.java   
@Override
public CompletableFuture<?> execute(CreateTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    checkArgument(!statement.getElements().isEmpty(), "no columns for table");

    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (tableHandle.isPresent()) {
        if (!statement.isNotExists()) {
            throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Table '%s' already exists", tableName);
        }
        return completedFuture(null);
    }

    List<ColumnMetadata> columns = new ArrayList<>();
    for (TableElement element : statement.getElements()) {
        Type type = metadata.getType(parseTypeSignature(element.getType()));
        if ((type == null) || type.equals(UNKNOWN)) {
            throw new SemanticException(TYPE_MISMATCH, element, "Unknown type for column '%s' ", element.getName());
        }
        columns.add(new ColumnMetadata(element.getName(), type, false));
    }

    accessControl.checkCanCreateTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    Map<String, Object> properties = metadata.getTablePropertyManager().getTableProperties(
            tableName.getCatalogName(),
            statement.getProperties(),
            session,
            metadata);

    TableMetadata tableMetadata = new TableMetadata(
            tableName.getCatalogName(),
            new ConnectorTableMetadata(tableName.asSchemaTableName(), columns, properties, session.getUser(), false));

    metadata.createTable(session, tableName.getCatalogName(), tableMetadata);

    return completedFuture(null);
}
项目:presto    文件:SqlQueryExecution.java   
@Inject
SqlQueryExecutionFactory(QueryManagerConfig config,
        FeaturesConfig featuresConfig,
        Metadata metadata,
        AccessControl accessControl,
        SqlParser sqlParser,
        LocationFactory locationFactory,
        SplitManager splitManager,
        NodeScheduler nodeScheduler,
        List<PlanOptimizer> planOptimizers,
        RemoteTaskFactory remoteTaskFactory,
        TransactionManager transactionManager,
        @ForQueryExecution ExecutorService executor,
        NodeTaskMap nodeTaskMap,
        QueryExplainer queryExplainer,
        Map<String, ExecutionPolicy> executionPolicies)
{
    requireNonNull(config, "config is null");
    this.scheduleSplitBatchSize = config.getScheduleSplitBatchSize();
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.accessControl = requireNonNull(accessControl, "accessControl is null");
    this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
    this.locationFactory = requireNonNull(locationFactory, "locationFactory is null");
    this.splitManager = requireNonNull(splitManager, "splitManager is null");
    this.nodeScheduler = requireNonNull(nodeScheduler, "nodeScheduler is null");
    this.planOptimizers = requireNonNull(planOptimizers, "planOptimizers is null");
    this.remoteTaskFactory = requireNonNull(remoteTaskFactory, "remoteTaskFactory is null");
    this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
    requireNonNull(featuresConfig, "featuresConfig is null");
    this.experimentalSyntaxEnabled = featuresConfig.isExperimentalSyntaxEnabled();
    this.executor = requireNonNull(executor, "executor is null");
    this.nodeTaskMap = requireNonNull(nodeTaskMap, "nodeTaskMap is null");
    this.queryExplainer = requireNonNull(queryExplainer, "queryExplainer is null");

    this.executionPolicies = requireNonNull(executionPolicies, "schedulerPolicies is null");
}
项目:presto    文件:StartTransactionTask.java   
@Override
public CompletableFuture<?> execute(StartTransaction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    if (!session.isClientTransactionSupport()) {
        throw new PrestoException(StandardErrorCode.INCOMPATIBLE_CLIENT, "Client does not support transactions");
    }
    if (session.getTransactionId().isPresent()) {
        throw new PrestoException(StandardErrorCode.NOT_SUPPORTED, "Nested transactions not supported");
    }

    Optional<IsolationLevel> isolationLevel = extractIsolationLevel(statement);
    Optional<Boolean> readOnly = extractReadOnly(statement);

    TransactionId transactionId = transactionManager.beginTransaction(
            isolationLevel.orElse(TransactionManager.DEFAULT_ISOLATION),
            readOnly.orElse(TransactionManager.DEFAULT_READ_ONLY),
            false);

    stateMachine.setStartedTransactionId(transactionId);

    // Since the current session does not contain this new transaction ID, we need to manually mark it as inactive
    // when this statement completes.
    transactionManager.trySetInactive(transactionId);

    return completedFuture(null);
}
项目:presto    文件:RollbackTask.java   
@Override
public CompletableFuture<?> execute(Rollback statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    if (!session.getTransactionId().isPresent()) {
        throw new PrestoException(NOT_IN_TRANSACTION, "No transaction in progress");
    }
    TransactionId transactionId = session.getTransactionId().get();

    stateMachine.clearTransactionId();
    transactionManager.asyncAbort(transactionId);
    return completedFuture(null);
}
项目:presto    文件:AddColumnTask.java   
@Override
public CompletableFuture<?> execute(AddColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }

    accessControl.checkCanAddColumns(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle.get());

    TableElement element = statement.getColumn();
    Type type = metadata.getType(parseTypeSignature(element.getType()));
    if ((type == null) || type.equals(UNKNOWN)) {
        throw new SemanticException(TYPE_MISMATCH, element, "Unknown type for column '%s' ", element.getName());
    }
    if (columnHandles.containsKey(element.getName())) {
        throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", element.getName());
    }

    metadata.addColumn(session, tableHandle.get(), new ColumnMetadata(element.getName(), type, false));

    return completedFuture(null);
}
项目:presto    文件:DataDefinitionExecution.java   
private DataDefinitionExecution(
        DataDefinitionTask<T> task,
        T statement,
        TransactionManager transactionManager,
        Metadata metadata,
        AccessControl accessControl,
        QueryStateMachine stateMachine)
{
    this.task = requireNonNull(task, "task is null");
    this.statement = requireNonNull(statement, "statement is null");
    this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.accessControl = requireNonNull(accessControl, "accessControl is null");
    this.stateMachine = requireNonNull(stateMachine, "stateMachine is null");
}
项目:presto    文件:PrestoServer.java   
private static void updateDatasources(Announcer announcer, Metadata metadata, ServerConfig serverConfig, NodeSchedulerConfig schedulerConfig)
{
    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());

    // get existing sources
    String property = nullToEmpty(announcement.getProperties().get("datasources"));
    List<String> values = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(property);
    Set<String> datasources = new LinkedHashSet<>(values);

    // automatically build sources if not configured
    if (datasources.isEmpty()) {
        Set<String> catalogs = metadata.getCatalogNames().keySet();
        // if this is a dedicated coordinator, only add jmx
        if (serverConfig.isCoordinator() && !schedulerConfig.isIncludeCoordinator()) {
            if (catalogs.contains("jmx")) {
                datasources.add("jmx");
            }
        }
        else {
            datasources.addAll(catalogs);
        }
    }

    // build announcement with updated sources
    ServiceAnnouncementBuilder builder = serviceAnnouncement(announcement.getType());
    for (Map.Entry<String, String> entry : announcement.getProperties().entrySet()) {
        if (!entry.getKey().equals("datasources")) {
            builder.addProperty(entry.getKey(), entry.getValue());
        }
    }
    builder.addProperty("datasources", Joiner.on(',').join(datasources));

    // update announcement
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(builder.build());
}
项目:presto    文件:PluginManager.java   
@Inject
public PluginManager(Injector injector,
        NodeInfo nodeInfo,
        HttpServerInfo httpServerInfo,
        PluginManagerConfig config,
        ConnectorManager connectorManager,
        ConfigurationFactory configurationFactory,
        Metadata metadata,
        AccessControlManager accessControlManager,
        BlockEncodingManager blockEncodingManager,
        TypeRegistry typeRegistry)
{
    requireNonNull(injector, "injector is null");
    requireNonNull(nodeInfo, "nodeInfo is null");
    requireNonNull(httpServerInfo, "httpServerInfo is null");
    requireNonNull(config, "config is null");
    requireNonNull(configurationFactory, "configurationFactory is null");

    this.injector = injector;
    installedPluginsDir = config.getInstalledPluginsDir();
    if (config.getPlugins() == null) {
        this.plugins = ImmutableList.of();
    }
    else {
        this.plugins = ImmutableList.copyOf(config.getPlugins());
    }
    this.resolver = new ArtifactResolver(config.getMavenLocalRepository(), config.getMavenRemoteRepository());

    Map<String, String> optionalConfig = new TreeMap<>(configurationFactory.getProperties());
    optionalConfig.put("node.id", nodeInfo.getNodeId());
    // TODO: make this work with and without HTTP and HTTPS
    optionalConfig.put("http-server.http.port", Integer.toString(httpServerInfo.getHttpUri().getPort()));
    this.optionalConfig = ImmutableMap.copyOf(optionalConfig);

    this.connectorManager = requireNonNull(connectorManager, "connectorManager is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.accessControlManager = requireNonNull(accessControlManager, "accessControlManager is null");
    this.blockEncodingManager = requireNonNull(blockEncodingManager, "blockEncodingManager is null");
    this.typeRegistry = requireNonNull(typeRegistry, "typeRegistry is null");
}
项目:presto    文件:PlanPrinter.java   
private PlanPrinter(PlanNode plan, Map<Symbol, Type> types, Metadata metadata, Session session, int indent)
{
    requireNonNull(plan, "plan is null");
    requireNonNull(types, "types is null");
    requireNonNull(metadata, "metadata is null");

    this.metadata = metadata;

    Visitor visitor = new Visitor(types, session);
    plan.accept(visitor, indent);
}
项目:presto    文件:PlanPrinter.java   
public static String textDistributedPlan(SubPlan plan, Metadata metadata, Session session)
{
    StringBuilder builder = new StringBuilder();
    for (PlanFragment fragment : plan.getAllFragments()) {
        builder.append(format("Fragment %s [%s]\n",
                fragment.getId(),
                fragment.getDistribution()));

        builder.append(indentString(1))
                .append(format("Output layout: [%s]\n",
                        Joiner.on(", ").join(fragment.getOutputLayout())));

        if (fragment.getPartitionFunction().isPresent()) {
            PartitionFunctionBinding partitionFunction = fragment.getPartitionFunction().get();
            PartitionFunctionHandle outputPartitioning = partitionFunction.getFunctionHandle();
            boolean replicateNulls = partitionFunction.isReplicateNulls();
            List<Symbol> symbols = partitionFunction.getPartitioningColumns();
            builder.append(indentString(1));
            if (replicateNulls) {
                builder.append(format("Output partitioning: %s (replicate nulls) [%s]\n",
                        outputPartitioning,
                        Joiner.on(", ").join(symbols)));
            }
            else {
                builder.append(format("Output partitioning: %s [%s]\n",
                        outputPartitioning,
                        Joiner.on(", ").join(symbols)));
            }
        }

        builder.append(textLogicalPlan(fragment.getRoot(), fragment.getSymbols(), metadata, session, 1))
                .append("\n");
    }

    return builder.toString();
}
项目:presto    文件:AbstractTestFunctions.java   
protected void registerScalar(Class<?> clazz)
{
    Metadata metadata = functionAssertions.getMetadata();
    List<SqlFunction> functions = new FunctionListBuilder(metadata.getTypeManager())
            .scalar(clazz)
            .getFunctions();
    metadata.getFunctionRegistry().addFunctions(functions);
}
项目:presto    文件:QueryPlanner.java   
QueryPlanner(Analysis analysis, SymbolAllocator symbolAllocator, PlanNodeIdAllocator idAllocator, Metadata metadata, Session session)
{
    requireNonNull(analysis, "analysis is null");
    requireNonNull(symbolAllocator, "symbolAllocator is null");
    requireNonNull(idAllocator, "idAllocator is null");
    requireNonNull(metadata, "metadata is null");
    requireNonNull(session, "session is null");

    this.analysis = analysis;
    this.symbolAllocator = symbolAllocator;
    this.idAllocator = idAllocator;
    this.metadata = metadata;
    this.session = session;
}
项目:presto    文件:LocalExecutionPlanner.java   
@Inject
public LocalExecutionPlanner(
        Metadata metadata,
        SqlParser sqlParser,
        PageSourceProvider pageSourceProvider,
        IndexManager indexManager,
        PageSinkManager pageSinkManager,
        ExchangeClientSupplier exchangeClientSupplier,
        ExpressionCompiler compiler,
        IndexJoinLookupStats indexJoinLookupStats,
        CompilerConfig compilerConfig,
        TaskManagerConfig taskManagerConfig)
{
    requireNonNull(compilerConfig, "compilerConfig is null");
    this.pageSourceProvider = requireNonNull(pageSourceProvider, "pageSourceProvider is null");
    this.indexManager = requireNonNull(indexManager, "indexManager is null");
    this.exchangeClientSupplier = exchangeClientSupplier;
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
    this.pageSinkManager = requireNonNull(pageSinkManager, "pageSinkManager is null");
    this.compiler = requireNonNull(compiler, "compiler is null");
    this.indexJoinLookupStats = requireNonNull(indexJoinLookupStats, "indexJoinLookupStats is null");
    this.maxIndexMemorySize = requireNonNull(taskManagerConfig, "taskManagerConfig is null").getMaxIndexMemoryUsage();
    this.maxPartialAggregationMemorySize = taskManagerConfig.getMaxPartialAggregationMemoryUsage();

    interpreterEnabled = compilerConfig.isInterpreterEnabled();
}
项目:presto    文件:LogicalPlanner.java   
public LogicalPlanner(Session session,
        List<PlanOptimizer> planOptimizers,
        PlanNodeIdAllocator idAllocator,
        Metadata metadata)
{
    requireNonNull(session, "session is null");
    requireNonNull(planOptimizers, "planOptimizers is null");
    requireNonNull(idAllocator, "idAllocator is null");
    requireNonNull(metadata, "metadata is null");

    this.session = session;
    this.planOptimizers = planOptimizers;
    this.idAllocator = idAllocator;
    this.metadata = metadata;
}
项目:presto    文件:LiteralInterpreter.java   
public static Object evaluate(Metadata metadata, ConnectorSession session, Expression node)
{
    if (!(node instanceof Literal)) {
        throw new IllegalArgumentException("node must be a Literal");
    }
    return new LiteralVisitor(metadata).process(node, session);
}
项目:presto    文件:ExpressionInterpreter.java   
public static ExpressionInterpreter expressionInterpreter(Expression expression, Metadata metadata, Session session, IdentityHashMap<Expression, Type> expressionTypes)
{
    requireNonNull(expression, "expression is null");
    requireNonNull(metadata, "metadata is null");
    requireNonNull(session, "session is null");

    return new ExpressionInterpreter(expression, metadata, session, expressionTypes, false);
}
项目:presto    文件:ExpressionInterpreter.java   
public static ExpressionInterpreter expressionOptimizer(Expression expression, Metadata metadata, Session session, IdentityHashMap<Expression, Type> expressionTypes)
{
    requireNonNull(expression, "expression is null");
    requireNonNull(metadata, "metadata is null");
    requireNonNull(session, "session is null");

    return new ExpressionInterpreter(expression, metadata, session, expressionTypes, true);
}