Search in sources :

Example 56 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class PluginManager method installPluginInternal.

private void installPluginInternal(Plugin plugin, Function<CatalogName, ClassLoader> duplicatePluginClassLoaderFactory) {
    for (BlockEncoding blockEncoding : plugin.getBlockEncodings()) {
        log.info("Registering block encoding %s", blockEncoding.getName());
        blockEncodingManager.addBlockEncoding(blockEncoding);
    }
    for (Type type : plugin.getTypes()) {
        log.info("Registering type %s", type.getTypeSignature());
        typeRegistry.addType(type);
    }
    for (ParametricType parametricType : plugin.getParametricTypes()) {
        log.info("Registering parametric type %s", parametricType.getName());
        typeRegistry.addParametricType(parametricType);
    }
    for (ConnectorFactory connectorFactory : plugin.getConnectorFactories()) {
        log.info("Registering connector %s", connectorFactory.getName());
        connectorManager.addConnectorFactory(connectorFactory, duplicatePluginClassLoaderFactory);
    }
    Set<Class<?>> functions = plugin.getFunctions();
    if (!functions.isEmpty()) {
        log.info("Registering functions from %s", plugin.getClass().getSimpleName());
        InternalFunctionBundleBuilder builder = InternalFunctionBundle.builder();
        functions.forEach(builder::functions);
        globalFunctionCatalog.addFunctions(builder.build());
    }
    for (SessionPropertyConfigurationManagerFactory sessionConfigFactory : plugin.getSessionPropertyConfigurationManagerFactories()) {
        log.info("Registering session property configuration manager %s", sessionConfigFactory.getName());
        sessionPropertyDefaults.addConfigurationManagerFactory(sessionConfigFactory);
    }
    for (ResourceGroupConfigurationManagerFactory configurationManagerFactory : plugin.getResourceGroupConfigurationManagerFactories()) {
        log.info("Registering resource group configuration manager %s", configurationManagerFactory.getName());
        resourceGroupManager.addConfigurationManagerFactory(configurationManagerFactory);
    }
    for (SystemAccessControlFactory accessControlFactory : plugin.getSystemAccessControlFactories()) {
        log.info("Registering system access control %s", accessControlFactory.getName());
        accessControlManager.addSystemAccessControlFactory(accessControlFactory);
    }
    passwordAuthenticatorManager.ifPresent(authenticationManager -> {
        for (PasswordAuthenticatorFactory authenticatorFactory : plugin.getPasswordAuthenticatorFactories()) {
            log.info("Registering password authenticator %s", authenticatorFactory.getName());
            authenticationManager.addPasswordAuthenticatorFactory(authenticatorFactory);
        }
    });
    for (CertificateAuthenticatorFactory authenticatorFactory : plugin.getCertificateAuthenticatorFactories()) {
        log.info("Registering certificate authenticator %s", authenticatorFactory.getName());
        certificateAuthenticatorManager.addCertificateAuthenticatorFactory(authenticatorFactory);
    }
    headerAuthenticatorManager.ifPresent(authenticationManager -> {
        for (HeaderAuthenticatorFactory authenticatorFactory : plugin.getHeaderAuthenticatorFactories()) {
            log.info("Registering header authenticator %s", authenticatorFactory.getName());
            authenticationManager.addHeaderAuthenticatorFactory(authenticatorFactory);
        }
    });
    for (EventListenerFactory eventListenerFactory : plugin.getEventListenerFactories()) {
        log.info("Registering event listener %s", eventListenerFactory.getName());
        eventListenerManager.addEventListenerFactory(eventListenerFactory);
    }
    for (GroupProviderFactory groupProviderFactory : plugin.getGroupProviderFactories()) {
        log.info("Registering group provider %s", groupProviderFactory.getName());
        groupProviderManager.addGroupProviderFactory(groupProviderFactory);
    }
    for (ExchangeManagerFactory exchangeManagerFactory : plugin.getExchangeManagerFactories()) {
        log.info("Registering exchange manager %s", exchangeManagerFactory.getName());
        exchangeManagerRegistry.addExchangeManagerFactory(exchangeManagerFactory);
    }
}
Also used : ResourceGroupConfigurationManagerFactory(io.trino.spi.resourcegroups.ResourceGroupConfigurationManagerFactory) HeaderAuthenticatorFactory(io.trino.spi.security.HeaderAuthenticatorFactory) EventListenerFactory(io.trino.spi.eventlistener.EventListenerFactory) SystemAccessControlFactory(io.trino.spi.security.SystemAccessControlFactory) Type(io.trino.spi.type.Type) ParametricType(io.trino.spi.type.ParametricType) PasswordAuthenticatorFactory(io.trino.spi.security.PasswordAuthenticatorFactory) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) InternalFunctionBundleBuilder(io.trino.metadata.InternalFunctionBundle.InternalFunctionBundleBuilder) ParametricType(io.trino.spi.type.ParametricType) SessionPropertyConfigurationManagerFactory(io.trino.spi.session.SessionPropertyConfigurationManagerFactory) BlockEncoding(io.trino.spi.block.BlockEncoding) CertificateAuthenticatorFactory(io.trino.spi.security.CertificateAuthenticatorFactory) GroupProviderFactory(io.trino.spi.security.GroupProviderFactory) ExchangeManagerFactory(io.trino.spi.exchange.ExchangeManagerFactory)

Example 57 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class SimplifyExpressions method rewrite.

public static Expression rewrite(Expression expression, Session session, SymbolAllocator symbolAllocator, PlannerContext plannerContext, TypeAnalyzer typeAnalyzer) {
    requireNonNull(plannerContext, "plannerContext is null");
    requireNonNull(typeAnalyzer, "typeAnalyzer is null");
    if (expression instanceof SymbolReference) {
        return expression;
    }
    Map<NodeRef<Expression>, Type> expressionTypes = typeAnalyzer.getTypes(session, symbolAllocator.getTypes(), expression);
    expression = pushDownNegations(plannerContext.getMetadata(), expression, expressionTypes);
    expression = extractCommonPredicates(plannerContext.getMetadata(), expression);
    expression = normalizeOrExpression(expression);
    expressionTypes = typeAnalyzer.getTypes(session, symbolAllocator.getTypes(), expression);
    ExpressionInterpreter interpreter = new ExpressionInterpreter(expression, plannerContext, session, expressionTypes);
    Object optimized = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
    return new LiteralEncoder(plannerContext).toExpression(session, optimized, expressionTypes.get(NodeRef.of(expression)));
}
Also used : NodeRef(io.trino.sql.tree.NodeRef) Type(io.trino.spi.type.Type) SymbolReference(io.trino.sql.tree.SymbolReference) LiteralEncoder(io.trino.sql.planner.LiteralEncoder) ExpressionInterpreter(io.trino.sql.planner.ExpressionInterpreter)

Example 58 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class PushProjectionThroughUnion method apply.

@Override
public Result apply(ProjectNode parent, Captures captures, Context context) {
    UnionNode source = captures.get(CHILD);
    // OutputLayout of the resultant Union, will be same as the layout of the Project
    List<Symbol> outputLayout = parent.getOutputSymbols();
    // Mapping from the output symbol to ordered list of symbols from each of the sources
    ImmutableListMultimap.Builder<Symbol, Symbol> mappings = ImmutableListMultimap.builder();
    // sources for the resultant UnionNode
    ImmutableList.Builder<PlanNode> outputSources = ImmutableList.builder();
    for (int i = 0; i < source.getSources().size(); i++) {
        // Map: output of union -> input of this source to the union
        Map<Symbol, SymbolReference> outputToInput = source.sourceSymbolMap(i);
        // assignments for the new ProjectNode
        Assignments.Builder assignments = Assignments.builder();
        // mapping from current ProjectNode to new ProjectNode, used to identify the output layout
        Map<Symbol, Symbol> projectSymbolMapping = new HashMap<>();
        // Translate the assignments in the ProjectNode using symbols of the source of the UnionNode
        for (Map.Entry<Symbol, Expression> entry : parent.getAssignments().entrySet()) {
            Expression translatedExpression = inlineSymbols(outputToInput, entry.getValue());
            Type type = context.getSymbolAllocator().getTypes().get(entry.getKey());
            Symbol symbol = context.getSymbolAllocator().newSymbol(translatedExpression, type);
            assignments.put(symbol, translatedExpression);
            projectSymbolMapping.put(entry.getKey(), symbol);
        }
        outputSources.add(new ProjectNode(context.getIdAllocator().getNextId(), source.getSources().get(i), assignments.build()));
        outputLayout.forEach(symbol -> mappings.put(symbol, projectSymbolMapping.get(symbol)));
    }
    return Result.ofPlanNode(new UnionNode(parent.getId(), outputSources.build(), mappings.build(), ImmutableList.copyOf(mappings.build().keySet())));
}
Also used : HashMap(java.util.HashMap) Symbol(io.trino.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) SymbolReference(io.trino.sql.tree.SymbolReference) Assignments(io.trino.sql.planner.plan.Assignments) Type(io.trino.spi.type.Type) PlanNode(io.trino.sql.planner.plan.PlanNode) UnionNode(io.trino.sql.planner.plan.UnionNode) Expression(io.trino.sql.tree.Expression) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ProjectNode(io.trino.sql.planner.plan.ProjectNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 59 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class UnwrapSingleColumnRowInApply method unwrapSingleColumnRow.

private Optional<Unwrapping> unwrapSingleColumnRow(Context context, Expression value, Expression list, BiFunction<Symbol, Symbol, Expression> function) {
    Type type = typeAnalyzer.getType(context.getSession(), context.getSymbolAllocator().getTypes(), value);
    if (type instanceof RowType) {
        RowType rowType = (RowType) type;
        if (rowType.getFields().size() == 1) {
            Type elementType = rowType.getTypeParameters().get(0);
            Symbol valueSymbol = context.getSymbolAllocator().newSymbol("input", elementType);
            Symbol listSymbol = context.getSymbolAllocator().newSymbol("subquery", elementType);
            Assignment inputAssignment = new Assignment(valueSymbol, new SubscriptExpression(value, new LongLiteral("1")));
            Assignment nestedPlanAssignment = new Assignment(listSymbol, new SubscriptExpression(list, new LongLiteral("1")));
            Expression comparison = function.apply(valueSymbol, listSymbol);
            return Optional.of(new Unwrapping(comparison, inputAssignment, nestedPlanAssignment));
        }
    }
    return Optional.empty();
}
Also used : Assignment(io.trino.sql.planner.plan.Assignments.Assignment) RowType(io.trino.spi.type.RowType) Type(io.trino.spi.type.Type) LongLiteral(io.trino.sql.tree.LongLiteral) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) Expression(io.trino.sql.tree.Expression) Symbol(io.trino.sql.planner.Symbol) RowType(io.trino.spi.type.RowType) SubscriptExpression(io.trino.sql.tree.SubscriptExpression)

Example 60 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class ExampleRecordCursor method checkFieldType.

private void checkFieldType(int field, Type expected) {
    Type actual = getType(field);
    checkArgument(actual.equals(expected), "Expected field %s to be type %s but is %s", field, expected, actual);
}
Also used : Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType)

Aggregations

Type (io.trino.spi.type.Type)688 Test (org.testng.annotations.Test)266 ArrayType (io.trino.spi.type.ArrayType)218 ImmutableList (com.google.common.collect.ImmutableList)191 RowType (io.trino.spi.type.RowType)177 List (java.util.List)155 VarcharType (io.trino.spi.type.VarcharType)134 Page (io.trino.spi.Page)126 ArrayList (java.util.ArrayList)126 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)114 Block (io.trino.spi.block.Block)110 MapType (io.trino.spi.type.MapType)107 DecimalType (io.trino.spi.type.DecimalType)102 TrinoException (io.trino.spi.TrinoException)98 Optional (java.util.Optional)98 Map (java.util.Map)97 ImmutableMap (com.google.common.collect.ImmutableMap)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)92 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)86 BlockBuilder (io.trino.spi.block.BlockBuilder)72