10.3. Example HTTP Connector

    The Example HTTP connector can be found in the directory in the root of the Presto source tree.

    The plugin implementation in the Example HTTP connector looks verysimilar to other plugin implementations. Most of the implementation isdevoted to handling optional configuration and the only function ofinterest is the following:

    As with all connectors, this plugin overrides the getConnectorFactories() methodand returns an ExampleConnectorFactory.

    In Presto, the primary object that handles the connection betweenPresto and a particular type of data source is the Connector object,which are created using .

    This implementation is available in the class ExampleConnectorFactory.The first thing the connector factory implementation does is specify thename of this connector. This is the same string used to reference thisconnector in Presto configuration.

    The real work in a connector factory happens in the create()method. In the ExampleConnectorFactory class, the create() methodconfigures the connector and then asks Guice to create the object.This is the meat of the method without parameter validationand exception handling:

    This class allows Presto to obtain references to the various servicesprovided by the connector.

    This class is responsible for reporting table names, table metadata,column names, column metadata and other information about the schemasthat are provided by this connector. ConnectorMetadata is also calledby Presto to ensure that a particular connector can understand andhandle a given table name.

    The ExampleMetadata implementation delegates many of these calls toExampleClient, a class that implements much of the core functionalityof the connector.

    The record set provider creates a record set which in turn creates arecord cursor that returns the actual data to Presto.ExampleRecordCursor reads data from a URI via HTTP. Each linecorresponds to a single row. Lines are split on comma into individualfield values which are then returned to Presto.