-
Notifications
You must be signed in to change notification settings - Fork 986
Create a Storage Plugin
Choose a name for your project. Let's call ours "example". Storage plugins typically go in the contrib module, in a subdirectory named storage-example.
To create the project in Eclipse:
- Select the
drill-contrib-parentnode in the Eclipse Package Explorer. - Choose Maven → New Maven Module Project from the context menu.
- Give your project the
storage-examplename. - Accept the other defaults and create the project.
- Edit the resulting
pom.xmlfile to add your needed dependencies. Use other storage plugins as a "cheat sheet" to see what is needed. - Edit
drill-contrib-parent/pom.xmlto verify your module appears in the module list. Add it if missing:
<modules>
...
<module>storage-example</module>
<module>data</module>
...
</modules>
- (Review this part.) Get Eclipse to know about your project. Use File → Import → Existing Maven Projects. Select the Drill root. Your project should now appear in the Package Explorer as
storage-example. (If this does not work, try selectingdrilland Maven → Update Project. - Eclipse named your new package
org.storage.example. Rename this package toorg.apache.drill.exec.store.example. - Do the same for the test package.
- Run the Maven-provided 'App' class to ensure everything works. Select the class name, then Debug as → Java Application from the context menu.
- Delete the example
AppandAppTestclasses.
The storage plugin class is Drill's main entry point to your plugin.
- Create the storage plugin class in Eclipse. The initial file should look like this:
public class SumoStoragePlugin extends AbstractStoragePlugin {
@Override
public StoragePluginConfig getConfig() {
// TODO Auto-generated method stub
return null;
}
@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent)
throws IOException {
// TODO Auto-generated method stub
}
}
We'll fill in each of these as we go. We'll start with a boilerplate method that says our plugin can read data:
@Override
public boolean supportsRead() { return true; }
Create the plugin's config file:
- Under your
srcfolder, create aresourcessubfolder. - Select the
resourcesfolder in the Package Explorer, then, from the context menu: Build Path → Use as Source Folder. - Under
resources, createdrill-module.conf(easiest to just copy from another storage plugin such as OpenTSDB):
drill.classpath.scanning: {
packages += "org.apache.drill.exec.store.example"
}
The above tells Drill about your storage plugin.
The config class provides all configuration information needed to execute your plugin, except the query-specific information.
- Create the
ExampleStoragePluginConfigclass:
@JsonTypeName(ExampleStoragePluginConfig.NAME)
public class ExampleStoragePluginConfig extends StoragePluginConfigBase {
public static final String NAME = "example";
public ExampleStoragePluginConfig() {
}
@Override
public boolean equals(Object o) {
return Objects.equal(null, null);
}
@Override
public int hashCode() {
return Objects.hashCode(null, null);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
//.add("foo", foo)
.toString();
}
}
Add the config fields needed by your plugin. You will need:
- The field itself, which must be public and should be a simple Java type such as an
intorString. (More complex types are possible, but can be tricky. Look at other config classes for examples.) - Add either a public
setFoomethod or add the field to the constructor. - Create a public
getFoomethod for each field. - Add the field to the
hashCode,equalsandtoStringmethods.
Add your config to the storage plugin class:
private final ExampleStoragePluginConfig config;
public SumoStoragePlugin(ExampleStoragePluginConfig config,
DrillbitContext context, String name) throws IOException {
super(context, name);
this.config = config;
}
@Override
public StoragePluginConfig getConfig() { return config; }
The constructor has special meaning to Drill: Drill uses the type of the first argument (here ExampleStoragePluginConfig ) to match a storage plugin class with a storage plugin config class.
Finally, create the default config, if any, you want for a newly-installed Drill. These defaults are also available to unit tests.
- Create the file
bootstrap-storage-plugins.jsonin yourresourcesfolder. - Put into the file the JSON-encoded version of your default configuration.
Or, if there is no good default, just omit this file. In this case, users will have to how to enter the JSON by hand in the Drill web console.