Search in sources :

Example 41 with Metadata

use of com.facebook.presto.metadata.Metadata in project presto by prestodb.

the class CreateFunctionTask method createSqlInvokedFunction.

private SqlInvokedFunction createSqlInvokedFunction(CreateFunction statement, Metadata metadata, Analysis analysis) {
    QualifiedObjectName functionName = statement.isTemporary() ? QualifiedObjectName.valueOf(SESSION_NAMESPACE, statement.getFunctionName().getSuffix()) : qualifyObjectName(statement.getFunctionName());
    List<Parameter> parameters = statement.getParameters().stream().map(parameter -> new Parameter(parameter.getName().toString(), parseTypeSignature(parameter.getType()))).collect(toImmutableList());
    TypeSignature returnType = parseTypeSignature(statement.getReturnType());
    String description = statement.getComment().orElse("");
    RoutineCharacteristics routineCharacteristics = RoutineCharacteristics.builder().setLanguage(new RoutineCharacteristics.Language(statement.getCharacteristics().getLanguage().getLanguage())).setDeterminism(RoutineCharacteristics.Determinism.valueOf(statement.getCharacteristics().getDeterminism().name())).setNullCallClause(RoutineCharacteristics.NullCallClause.valueOf(statement.getCharacteristics().getNullCallClause().name())).build();
    RoutineBody body = statement.getBody();
    if (statement.getBody() instanceof Return) {
        Expression bodyExpression = ((Return) statement.getBody()).getExpression();
        Type bodyType = analysis.getType(bodyExpression);
        // Coerce expressions in body if necessary
        bodyExpression = ExpressionTreeRewriter.rewriteWith(new ExpressionRewriter<Void>() {

            @Override
            public Expression rewriteExpression(Expression expression, Void context, ExpressionTreeRewriter<Void> treeRewriter) {
                Expression rewritten = treeRewriter.defaultRewrite(expression, null);
                Type coercion = analysis.getCoercion(expression);
                if (coercion != null) {
                    return new Cast(rewritten, coercion.getTypeSignature().toString(), false, analysis.isTypeOnlyCoercion(expression));
                }
                return rewritten;
            }
        }, bodyExpression, null);
        if (!bodyType.equals(metadata.getType(returnType))) {
            // Casting is safe here, since we have verified at analysis time that the actual type of the body is coercible to declared return type.
            bodyExpression = new Cast(bodyExpression, statement.getReturnType());
        }
        body = new Return(bodyExpression);
    }
    return new SqlInvokedFunction(functionName, parameters, returnType, description, routineCharacteristics, formatSql(body, Optional.empty()), notVersioned());
}
Also used : ExpressionTreeRewriter(com.facebook.presto.sql.tree.ExpressionTreeRewriter) WarningCollector(com.facebook.presto.spi.WarningCollector) Parameter(com.facebook.presto.spi.function.Parameter) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SESSION_NAMESPACE(com.facebook.presto.metadata.SessionFunctionHandle.SESSION_NAMESPACE) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) PrestoException(com.facebook.presto.spi.PrestoException) CreateFunction(com.facebook.presto.sql.tree.CreateFunction) TypeSignature(com.facebook.presto.common.type.TypeSignature) Inject(javax.inject.Inject) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Cast(com.facebook.presto.sql.tree.Cast) SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) TransactionManager(com.facebook.presto.transaction.TransactionManager) FunctionAndTypeManager.qualifyObjectName(com.facebook.presto.metadata.FunctionAndTypeManager.qualifyObjectName) Type(com.facebook.presto.common.type.Type) RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) RoutineBody(com.facebook.presto.sql.tree.RoutineBody) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) String.format(java.lang.String.format) SqlParser(com.facebook.presto.sql.parser.SqlParser) ExpressionRewriter(com.facebook.presto.sql.tree.ExpressionRewriter) List(java.util.List) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Expression(com.facebook.presto.sql.tree.Expression) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) Return(com.facebook.presto.sql.tree.Return) FunctionVersion.notVersioned(com.facebook.presto.spi.function.FunctionVersion.notVersioned) SqlFormatter.formatSql(com.facebook.presto.sql.SqlFormatter.formatSql) Analysis(com.facebook.presto.sql.analyzer.Analysis) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) Cast(com.facebook.presto.sql.tree.Cast) ExpressionTreeRewriter(com.facebook.presto.sql.tree.ExpressionTreeRewriter) Return(com.facebook.presto.sql.tree.Return) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Type(com.facebook.presto.common.type.Type) ExpressionRewriter(com.facebook.presto.sql.tree.ExpressionRewriter) RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) Expression(com.facebook.presto.sql.tree.Expression) Parameter(com.facebook.presto.spi.function.Parameter) RoutineBody(com.facebook.presto.sql.tree.RoutineBody)

Example 42 with Metadata

use of com.facebook.presto.metadata.Metadata in project presto by prestodb.

the class TestRowBasedSerialization method setUp.

@BeforeClass
public void setUp() {
    Metadata metadata = MetadataManager.createTestMetadataManager();
    this.functionAndTypeManager = metadata.getFunctionAndTypeManager();
}
Also used : Metadata(com.facebook.presto.metadata.Metadata) BeforeClass(org.testng.annotations.BeforeClass)

Example 43 with Metadata

use of com.facebook.presto.metadata.Metadata in project presto by prestodb.

the class PropertyDerivations method deriveProperties.

public static ActualProperties deriveProperties(PlanNode node, List<ActualProperties> inputProperties, Metadata metadata, Session session, TypeProvider types, SqlParser parser) {
    ActualProperties output = node.accept(new Visitor(metadata, session, types, parser), inputProperties);
    output.getNodePartitioning().ifPresent(partitioning -> verify(node.getOutputVariables().containsAll(partitioning.getVariableReferences()), "Node-level partitioning properties contain columns not present in node's output"));
    verify(node.getOutputVariables().containsAll(output.getConstants().keySet()), "Node-level constant properties contain columns not present in node's output");
    Set<VariableReferenceExpression> localPropertyColumns = output.getLocalProperties().stream().flatMap(property -> property.getColumns().stream()).collect(Collectors.toSet());
    verify(node.getOutputVariables().containsAll(localPropertyColumns), "Node-level local properties contain columns not present in node's output");
    return output;
}
Also used : AggregationNode(com.facebook.presto.spi.plan.AggregationNode) ExplainAnalyzeNode(com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode) RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) SpatialJoinNode(com.facebook.presto.sql.planner.plan.SpatialJoinNode) SortNode(com.facebook.presto.sql.planner.plan.SortNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableWriterNode(com.facebook.presto.sql.planner.plan.TableWriterNode) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toMap(java.util.stream.Collectors.toMap) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) TopNRowNumberNode(com.facebook.presto.sql.planner.plan.TopNRowNumberNode) Map(java.util.Map) LocalProperty(com.facebook.presto.spi.LocalProperty) IndexSourceNode(com.facebook.presto.sql.planner.plan.IndexSourceNode) Global.singleStreamPartition(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global.singleStreamPartition) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) RowExpressionInterpreter(com.facebook.presto.sql.planner.RowExpressionInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) RowNumberNode(com.facebook.presto.sql.planner.plan.RowNumberNode) ImmutableMap(com.google.common.collect.ImmutableMap) Global.arbitraryPartition(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global.arbitraryPartition) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TablePartitioning(com.facebook.presto.metadata.TableLayout.TablePartitioning) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SqlParser(com.facebook.presto.sql.parser.SqlParser) Preconditions.checkState(com.google.common.base.Preconditions.checkState) LimitNode(com.facebook.presto.spi.plan.LimitNode) SystemSessionProperties.isSpillEnabled(com.facebook.presto.SystemSessionProperties.isSpillEnabled) List(java.util.List) Global.streamPartitionedOn(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global.streamPartitionedOn) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) Global(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global) SampleNode(com.facebook.presto.sql.planner.plan.SampleNode) Optional(java.util.Optional) Global.coordinatorSingleStreamPartition(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global.coordinatorSingleStreamPartition) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) AssignUniqueId(com.facebook.presto.sql.planner.plan.AssignUniqueId) TupleDomain.toLinkedMap(com.facebook.presto.common.predicate.TupleDomain.toLinkedMap) MarkDistinctNode(com.facebook.presto.spi.plan.MarkDistinctNode) ARBITRARY_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.ARBITRARY_DISTRIBUTION) Iterables(com.google.common.collect.Iterables) Global.partitionedOn(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global.partitionedOn) GroupIdNode(com.facebook.presto.sql.planner.plan.GroupIdNode) HashMap(java.util.HashMap) DistinctLimitNode(com.facebook.presto.spi.plan.DistinctLimitNode) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) TableWriterMergeNode(com.facebook.presto.sql.planner.plan.TableWriterMergeNode) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) FilterNode(com.facebook.presto.spi.plan.FilterNode) ImmutableList(com.google.common.collect.ImmutableList) SortingProperty(com.facebook.presto.spi.SortingProperty) Verify.verify(com.google.common.base.Verify.verify) BASIC_COLUMN_EXTRACTOR(com.facebook.presto.spi.relation.DomainTranslator.BASIC_COLUMN_EXTRACTOR) SystemSessionProperties.isJoinSpillingEnabled(com.facebook.presto.SystemSessionProperties.isJoinSpillingEnabled) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) UnnestNode(com.facebook.presto.sql.planner.plan.UnnestNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) TableLayout(com.facebook.presto.metadata.TableLayout) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) Session(com.facebook.presto.Session) GroupingProperty(com.facebook.presto.spi.GroupingProperty) ConstantProperty(com.facebook.presto.spi.ConstantProperty) SystemSessionProperties.planWithTableNodePartitioning(com.facebook.presto.SystemSessionProperties.planWithTableNodePartitioning) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) OPTIMIZED(com.facebook.presto.spi.relation.ExpressionOptimizer.Level.OPTIMIZED) PlanNode(com.facebook.presto.spi.plan.PlanNode) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) TopNNode(com.facebook.presto.spi.plan.TopNNode) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode) Metadata(com.facebook.presto.metadata.Metadata) EnforceSingleRowNode(com.facebook.presto.sql.planner.plan.EnforceSingleRowNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) StatisticsWriterNode(com.facebook.presto.sql.planner.plan.StatisticsWriterNode) Global.partitionedOnCoalesce(com.facebook.presto.sql.planner.optimizations.ActualProperties.Global.partitionedOnCoalesce) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression)

Example 44 with Metadata

use of com.facebook.presto.metadata.Metadata in project presto by prestodb.

the class TranslateExpressions method createRewriter.

private static PlanRowExpressionRewriter createRewriter(Metadata metadata, SqlParser sqlParser) {
    return new PlanRowExpressionRewriter() {

        @Override
        public RowExpression rewrite(RowExpression expression, Rule.Context context) {
            // special treatment of the CallExpression in Aggregation
            if (expression instanceof CallExpression && ((CallExpression) expression).getArguments().stream().anyMatch(OriginalExpressionUtils::isExpression)) {
                return removeOriginalExpressionArguments((CallExpression) expression, context.getSession(), context.getVariableAllocator());
            }
            return removeOriginalExpression(expression, context);
        }

        private RowExpression removeOriginalExpressionArguments(CallExpression callExpression, Session session, PlanVariableAllocator variableAllocator) {
            Map<NodeRef<Expression>, Type> types = analyzeCallExpressionTypes(callExpression, session, variableAllocator.getTypes());
            return new CallExpression(callExpression.getSourceLocation(), callExpression.getDisplayName(), callExpression.getFunctionHandle(), callExpression.getType(), callExpression.getArguments().stream().map(expression -> removeOriginalExpression(expression, session, types)).collect(toImmutableList()));
        }

        private Map<NodeRef<Expression>, Type> analyzeCallExpressionTypes(CallExpression callExpression, Session session, TypeProvider typeProvider) {
            List<LambdaExpression> lambdaExpressions = callExpression.getArguments().stream().filter(OriginalExpressionUtils::isExpression).map(OriginalExpressionUtils::castToExpression).filter(LambdaExpression.class::isInstance).map(LambdaExpression.class::cast).collect(toImmutableList());
            ImmutableMap.Builder<NodeRef<Expression>, Type> builder = ImmutableMap.<NodeRef<Expression>, Type>builder();
            if (!lambdaExpressions.isEmpty()) {
                List<FunctionType> functionTypes = metadata.getFunctionAndTypeManager().getFunctionMetadata(callExpression.getFunctionHandle()).getArgumentTypes().stream().filter(typeSignature -> typeSignature.getBase().equals(FunctionType.NAME)).map(typeSignature -> (FunctionType) (metadata.getFunctionAndTypeManager().getType(typeSignature))).collect(toImmutableList());
                InternalAggregationFunction internalAggregationFunction = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(callExpression.getFunctionHandle());
                List<Class> lambdaInterfaces = internalAggregationFunction.getLambdaInterfaces();
                verify(lambdaExpressions.size() == functionTypes.size());
                verify(lambdaExpressions.size() == lambdaInterfaces.size());
                for (int i = 0; i < lambdaExpressions.size(); i++) {
                    LambdaExpression lambdaExpression = lambdaExpressions.get(i);
                    FunctionType functionType = functionTypes.get(i);
                    // To compile lambda, LambdaDefinitionExpression needs to be generated from LambdaExpression,
                    // which requires the types of all sub-expressions.
                    // 
                    // In project and filter expression compilation, ExpressionAnalyzer.getExpressionTypesFromInput
                    // is used to generate the types of all sub-expressions. (see visitScanFilterAndProject and visitFilter)
                    // 
                    // This does not work here since the function call representation in final aggregation node
                    // is currently a hack: it takes intermediate type as input, and may not be a valid
                    // function call in Presto.
                    // 
                    // TODO: Once the final aggregation function call representation is fixed,
                    // the same mechanism in project and filter expression should be used here.
                    verify(lambdaExpression.getArguments().size() == functionType.getArgumentTypes().size());
                    Map<NodeRef<Expression>, Type> lambdaArgumentExpressionTypes = new HashMap<>();
                    Map<String, Type> lambdaArgumentSymbolTypes = new HashMap<>();
                    for (int j = 0; j < lambdaExpression.getArguments().size(); j++) {
                        LambdaArgumentDeclaration argument = lambdaExpression.getArguments().get(j);
                        Type type = functionType.getArgumentTypes().get(j);
                        lambdaArgumentExpressionTypes.put(NodeRef.of(argument), type);
                        lambdaArgumentSymbolTypes.put(argument.getName().getValue(), type);
                    }
                    // the lambda expression itself
                    builder.put(NodeRef.of(lambdaExpression), functionType).putAll(lambdaArgumentExpressionTypes).putAll(getExpressionTypes(session, metadata, sqlParser, TypeProvider.copyOf(lambdaArgumentSymbolTypes), lambdaExpression.getBody(), emptyList(), NOOP));
                }
            }
            for (RowExpression argument : callExpression.getArguments()) {
                if (!isExpression(argument) || castToExpression(argument) instanceof LambdaExpression) {
                    continue;
                }
                builder.putAll(analyze(castToExpression(argument), session, typeProvider));
            }
            return builder.build();
        }

        private Map<NodeRef<Expression>, Type> analyze(Expression expression, Session session, TypeProvider typeProvider) {
            return getExpressionTypes(session, metadata, sqlParser, typeProvider, expression, emptyList(), NOOP);
        }

        private RowExpression toRowExpression(Expression expression, Session session, Map<NodeRef<Expression>, Type> types) {
            return SqlToRowExpressionTranslator.translate(expression, types, ImmutableMap.of(), metadata.getFunctionAndTypeManager(), session);
        }

        private RowExpression removeOriginalExpression(RowExpression expression, Rule.Context context) {
            if (isExpression(expression)) {
                return toRowExpression(castToExpression(expression), context.getSession(), analyze(castToExpression(expression), context.getSession(), context.getVariableAllocator().getTypes()));
            }
            return expression;
        }

        private RowExpression removeOriginalExpression(RowExpression rowExpression, Session session, Map<NodeRef<Expression>, Type> types) {
            if (isExpression(rowExpression)) {
                Expression expression = castToExpression(rowExpression);
                return toRowExpression(expression, session, types);
            }
            return rowExpression;
        }
    };
}
Also used : LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils) SqlToRowExpressionTranslator(com.facebook.presto.sql.relational.SqlToRowExpressionTranslator) OriginalExpressionUtils.isExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.isExpression) HashMap(java.util.HashMap) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) Verify.verify(com.google.common.base.Verify.verify) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) Map(java.util.Map) CallExpression(com.facebook.presto.spi.relation.CallExpression) Type(com.facebook.presto.common.type.Type) RowExpression(com.facebook.presto.spi.relation.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) Collections.emptyList(java.util.Collections.emptyList) Session(com.facebook.presto.Session) Rule(com.facebook.presto.sql.planner.iterative.Rule) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) FunctionType(com.facebook.presto.common.type.FunctionType) SqlParser(com.facebook.presto.sql.parser.SqlParser) NodeRef(com.facebook.presto.sql.tree.NodeRef) List(java.util.List) Expression(com.facebook.presto.sql.tree.Expression) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) NOOP(com.facebook.presto.spi.WarningCollector.NOOP) ExpressionAnalyzer.getExpressionTypes(com.facebook.presto.sql.analyzer.ExpressionAnalyzer.getExpressionTypes) Metadata(com.facebook.presto.metadata.Metadata) HashMap(java.util.HashMap) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) NodeRef(com.facebook.presto.sql.tree.NodeRef) LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) CallExpression(com.facebook.presto.spi.relation.CallExpression) FunctionType(com.facebook.presto.common.type.FunctionType) RowExpression(com.facebook.presto.spi.relation.RowExpression) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) ImmutableMap(com.google.common.collect.ImmutableMap) Type(com.facebook.presto.common.type.Type) FunctionType(com.facebook.presto.common.type.FunctionType) OriginalExpressionUtils.isExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.isExpression) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) Expression(com.facebook.presto.sql.tree.Expression) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session)

Example 45 with Metadata

use of com.facebook.presto.metadata.Metadata in project presto by prestodb.

the class AbstractAnalyzerTest method createTestingCatalog.

private Catalog createTestingCatalog(String catalogName, ConnectorId connectorId) {
    ConnectorId systemId = createSystemTablesConnectorId(connectorId);
    Connector connector = AbstractAnalyzerTest.createTestingConnector();
    InternalNodeManager nodeManager = new InMemoryNodeManager();
    return new Catalog(catalogName, connectorId, connector, createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl, ImmutableList.of()), systemId, new SystemConnector(systemId, nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId)));
}
Also used : SystemConnector(com.facebook.presto.connector.system.SystemConnector) WarningCollector(com.facebook.presto.spi.WarningCollector) Parameter(com.facebook.presto.spi.function.Parameter) JsonCodec(com.facebook.airlift.json.JsonCodec) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) SQL(com.facebook.presto.spi.function.RoutineCharacteristics.Language.SQL) TestingWarningCollectorConfig(com.facebook.presto.testing.TestingWarningCollectorConfig) APPLY_FUNCTION(com.facebook.presto.operator.scalar.ApplyFunction.APPLY_FUNCTION) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) PropertyMetadata(com.facebook.presto.spi.session.PropertyMetadata) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) SchemaTableName(com.facebook.presto.spi.SchemaTableName) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) TransactionBuilder.transaction(com.facebook.presto.transaction.TransactionBuilder.transaction) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) PropertyMetadata.stringProperty(com.facebook.presto.spi.session.PropertyMetadata.stringProperty) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) Collections.emptyList(java.util.Collections.emptyList) BeforeClass(org.testng.annotations.BeforeClass) DETERMINISTIC(com.facebook.presto.spi.function.RoutineCharacteristics.Determinism.DETERMINISTIC) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) RealType(com.facebook.presto.common.type.RealType) TestingMetadata(com.facebook.presto.testing.TestingMetadata) TestingWarningCollector(com.facebook.presto.testing.TestingWarningCollector) String.format(java.lang.String.format) SqlParser(com.facebook.presto.sql.parser.SqlParser) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) RETURNS_NULL_ON_NULL_INPUT(com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause.RETURNS_NULL_ON_NULL_INPUT) Catalog(com.facebook.presto.metadata.Catalog) Optional(java.util.Optional) SystemConnector(com.facebook.presto.connector.system.SystemConnector) ConnectorId(com.facebook.presto.spi.ConnectorId) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) StandardTypes(com.facebook.presto.common.type.StandardTypes) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) AccessControlManager(com.facebook.presto.security.AccessControlManager) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) ImmutableList(com.google.common.collect.ImmutableList) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId) ArrayType(com.facebook.presto.common.type.ArrayType) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Connector(com.facebook.presto.spi.connector.Connector) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) NodeLocation(com.facebook.presto.sql.tree.NodeLocation) Assert.fail(org.testng.Assert.fail) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) CatalogManager(com.facebook.presto.metadata.CatalogManager) Consumer(java.util.function.Consumer) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) FunctionVersion.notVersioned(com.facebook.presto.spi.function.FunctionVersion.notVersioned) PropertyMetadata.integerProperty(com.facebook.presto.spi.session.PropertyMetadata.integerProperty) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) RowType(com.facebook.presto.common.type.RowType) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) Statement(com.facebook.presto.sql.tree.Statement) SystemConnector(com.facebook.presto.connector.system.SystemConnector) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) Connector(com.facebook.presto.spi.connector.Connector) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) Catalog(com.facebook.presto.metadata.Catalog) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager)

Aggregations

Metadata (com.facebook.presto.metadata.Metadata)59 Optional (java.util.Optional)38 Session (com.facebook.presto.Session)35 List (java.util.List)35 Objects.requireNonNull (java.util.Objects.requireNonNull)29 Map (java.util.Map)26 ImmutableList (com.google.common.collect.ImmutableList)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)21 RowExpression (com.facebook.presto.spi.relation.RowExpression)19 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)18 Expression (com.facebook.presto.sql.tree.Expression)18 PlanNode (com.facebook.presto.spi.plan.PlanNode)17 SqlParser (com.facebook.presto.sql.parser.SqlParser)16 ImmutableMap (com.google.common.collect.ImmutableMap)16 Preconditions.checkState (com.google.common.base.Preconditions.checkState)15 Type (com.facebook.presto.common.type.Type)14 TableHandle (com.facebook.presto.spi.TableHandle)14 WarningCollector (com.facebook.presto.spi.WarningCollector)14 Set (java.util.Set)14