10.1. SPI Overview

When you implement a new Presto plugin, you implement interfaces andoverride methods defined by the SPI.

Plugins can provide additional Connectors, Types,Functions and System Access Control.In particular, connectors are the source of all data for queries inPresto: they back each catalog available to Presto.

Code

The SPI source can be found in the presto-spi directory in theroot of the Presto source tree.

Plugin Metadata

Each plugin identifies an entry point: an implementation of thePlugin interface. This class name is provided to Presto viathe standard Java ServiceLoader interface: the classpath containsa resource file named com.facebook.presto.spi.Plugin in theMETA-INF/services directory. The content of this file is asingle line listing the name of the plugin class:

  1. com.facebook.presto.example.ExamplePlugin

For a built-in plugin that is included in the Presto source code,this resource file is created whenever the pom.xml file of a plugincontains the following line:

  1. <packaging>presto-plugin</packaging>

Plugin

The Plugin interface is a good starting place for developers lookingto understand the Presto SPI. It contains access methods to retrievevarious classes that a Plugin can provide. For example, the getConnectorFactories()method is a top-level function that Presto calls to retrieve a ConnectorFactory when Prestois ready to create an instance of a connector to back a catalog. There are similarmethods for Type, ParametricType, Function, SystemAccessControl, andEventListenerFactory objects.

Building Plugins via Maven

Plugins depend on the SPI from Presto:

  1. <dependency>
  2. <groupId>com.facebook.presto</groupId>
  3. <artifactId>presto-spi</artifactId>
  4. <scope>provided</scope>
  5. </dependency>

The plugin uses the Maven provided scope because Presto providesthe classes from the SPI at runtime and thus the plugin should notinclude them in the plugin assembly.

There are a few other dependencies that are provided by Presto,including Slice and Jackson annotations. In particular, Jackson isused for serializing connector handles and thus plugins must use theannotations version provided by Presto.

All other dependencies are based on what the plugin needs for itsown implementation. Plugins are loaded in a separate class loaderto provide isolation and to allow plugins to use a different versionof a library that Presto uses internally.

For an example pom.xml file, see the example HTTP connector in thepresto-example-http directory in the root of the Presto source tree.

Deploying a Custom Plugin

In order to add a custom plugin to a Presto installation, create a directoryfor that plugin in the Presto plugin directory and add all the necessary jarsfor the plugin to that directory. For example, for a plugin calledmy-functions, you would create a directory my-functions in the Prestoplugin directory and add the relevant jars to that directory.

By default, the plugin directory is the plugin directory relative to thedirectory in which Presto is installed, but it is configurable using theconfiguration variable catalog.config-dir. In order for Presto to pick upthe new plugin, you must restart Presto.

Plugins must be installed on all nodes in the Presto cluster (coordinator and workers).