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);
}
}
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)));
}
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())));
}
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();
}
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);
}
Aggregations