-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathspi-overview.html
151 lines (138 loc) · 7.95 KB
/
spi-overview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>10.1. SPI Overview — Presto 0.204 Documentation</title>
<link rel="stylesheet" href="../_static/presto.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.204',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Presto 0.204 Documentation" href="../index.html" />
<link rel="up" title="10. Developer Guide" href="../develop.html" />
<link rel="next" title="10.2. Connectors" href="connectors.html" />
<link rel="prev" title="10. Developer Guide" href="../develop.html" />
</head>
<body role="document">
<div class="header">
<h1 class="heading"><a href="../index.html">
<span>Presto 0.204 Documentation</span></a></h1>
<h2 class="heading"><span>10.1. SPI Overview</span></h2>
</div>
<div class="topnav">
<p class="nav">
<span class="left">
« <a href="../develop.html">10. Developer Guide</a>
</span>
<span class="right">
<a href="connectors.html">10.2. Connectors</a> »
</span>
</p>
</div>
<div class="content">
<div class="section" id="spi-overview">
<h1>10.1. SPI Overview</h1>
<p>When you implement a new Presto plugin, you implement interfaces and
override methods defined by the SPI.</p>
<p>Plugins can provide additional <a class="reference internal" href="connectors.html"><span class="doc">Connectors</span></a>, <a class="reference internal" href="types.html"><span class="doc">Types</span></a>,
<a class="reference internal" href="functions.html"><span class="doc">Functions</span></a> and <a class="reference internal" href="system-access-control.html"><span class="doc">System Access Control</span></a>.
In particular, connectors are the source of all data for queries in
Presto: they back each catalog available to Presto.</p>
<div class="section" id="code">
<h2>Code</h2>
<p>The SPI source can be found in the <code class="docutils literal"><span class="pre">presto-spi</span></code> directory in the
root of the Presto source tree.</p>
</div>
<div class="section" id="plugin-metadata">
<h2>Plugin Metadata</h2>
<p>Each plugin identifies an entry point: an implementation of the
<code class="docutils literal"><span class="pre">Plugin</span></code> interface. This class name is provided to Presto via
the standard Java <code class="docutils literal"><span class="pre">ServiceLoader</span></code> interface: the classpath contains
a resource file named <code class="docutils literal"><span class="pre">com.facebook.presto.spi.Plugin</span></code> in the
<code class="docutils literal"><span class="pre">META-INF/services</span></code> directory. The content of this file is a
single line listing the name of the plugin class:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>com.facebook.presto.example.ExamplePlugin
</pre></div>
</div>
<p>For a built-in plugin that is included in the Presto source code,
this resource file is created whenever the <code class="docutils literal"><span class="pre">pom.xml</span></code> file of a plugin
contains the following line:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span><packaging>presto-plugin</packaging>
</pre></div>
</div>
</div>
<div class="section" id="plugin">
<h2>Plugin</h2>
<p>The <code class="docutils literal"><span class="pre">Plugin</span></code> interface is a good starting place for developers looking
to understand the Presto SPI. It contains access methods to retrieve
various classes that a Plugin can provide. For example, the <code class="docutils literal"><span class="pre">getConnectorFactories()</span></code>
method is a top-level function that Presto calls to retrieve a <code class="docutils literal"><span class="pre">ConnectorFactory</span></code> when Presto
is ready to create an instance of a connector to back a catalog. There are similar
methods for <code class="docutils literal"><span class="pre">Type</span></code>, <code class="docutils literal"><span class="pre">ParametricType</span></code>, <code class="docutils literal"><span class="pre">Function</span></code>, <code class="docutils literal"><span class="pre">SystemAccessControl</span></code>, and
<code class="docutils literal"><span class="pre">EventListenerFactory</span></code> objects.</p>
</div>
<div class="section" id="building-plugins-via-maven">
<h2>Building Plugins via Maven</h2>
<p>Plugins depend on the SPI from Presto:</p>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt"><dependency></span>
<span class="nt"><groupId></span>com.facebook.presto<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>presto-spi<span class="nt"></artifactId></span>
<span class="nt"><scope></span>provided<span class="nt"></scope></span>
<span class="nt"></dependency></span>
</pre></div>
</div>
<p>The plugin uses the Maven <code class="docutils literal"><span class="pre">provided</span></code> scope because Presto provides
the classes from the SPI at runtime and thus the plugin should not
include them in the plugin assembly.</p>
<p>There are a few other dependencies that are provided by Presto,
including Slice and Jackson annotations. In particular, Jackson is
used for serializing connector handles and thus plugins must use the
annotations version provided by Presto.</p>
<p>All other dependencies are based on what the plugin needs for its
own implementation. Plugins are loaded in a separate class loader
to provide isolation and to allow plugins to use a different version
of a library that Presto uses internally.</p>
<p>For an example <code class="docutils literal"><span class="pre">pom.xml</span></code> file, see the example HTTP connector in the
<code class="docutils literal"><span class="pre">presto-example-http</span></code> directory in the root of the Presto source tree.</p>
</div>
<div class="section" id="deploying-a-custom-plugin">
<h2>Deploying a Custom Plugin</h2>
<p>In order to add a custom plugin to a Presto installation, create a directory
for that plugin in the Presto plugin directory and add all the necessary jars
for the plugin to that directory. For example, for a plugin called
<code class="docutils literal"><span class="pre">my-functions</span></code>, you would create a directory <code class="docutils literal"><span class="pre">my-functions</span></code> in the Presto
plugin directory and add the relevant jars to that directory.</p>
<p>By default, the plugin directory is the <code class="docutils literal"><span class="pre">plugin</span></code> directory relative to the
directory in which Presto is installed, but it is configurable using the
configuration variable <code class="docutils literal"><span class="pre">catalog.config-dir</span></code>. In order for Presto to pick up
the new plugin, you must restart Presto.</p>
<p>Plugins must be installed on all nodes in the Presto cluster (coordinator and workers).</p>
</div>
</div>
</div>
<div class="bottomnav">
<p class="nav">
<span class="left">
« <a href="../develop.html">10. Developer Guide</a>
</span>
<span class="right">
<a href="connectors.html">10.2. Connectors</a> »
</span>
</p>
</div>
<div class="footer" role="contentinfo">
</div>
</body>
</html>