Class SqlEntity

  • All Implemented Interfaces:
    org.apache.druid.data.input.InputEntity

    public class SqlEntity
    extends Object
    implements org.apache.druid.data.input.InputEntity
    Represents a rdbms based input resource and knows how to read query results from the resource using SQL queries.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.druid.data.input.InputEntity

        org.apache.druid.data.input.InputEntity.CleanableFile
    • Field Summary

      • Fields inherited from interface org.apache.druid.data.input.InputEntity

        DEFAULT_FETCH_BUFFER_SIZE, DEFAULT_MAX_NUM_FETCH_TRIES
    • Constructor Summary

      Constructors 
      Constructor Description
      SqlEntity​(String sql, SQLFirehoseDatabaseConnector sqlFirehoseDatabaseConnector, boolean foldCase, com.fasterxml.jackson.databind.ObjectMapper objectMapper)  
    • Constructor Detail

      • SqlEntity

        public SqlEntity​(String sql,
                         SQLFirehoseDatabaseConnector sqlFirehoseDatabaseConnector,
                         boolean foldCase,
                         com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • Method Detail

      • getSql

        public String getSql()
      • getUri

        @Nullable
        public URI getUri()
        Specified by:
        getUri in interface org.apache.druid.data.input.InputEntity
      • open

        public InputStream open()
        Specified by:
        open in interface org.apache.druid.data.input.InputEntity
      • fetch

        public org.apache.druid.data.input.InputEntity.CleanableFile fetch​(File temporaryDirectory,
                                                                           byte[] fetchBuffer)
                                                                    throws IOException
        Specified by:
        fetch in interface org.apache.druid.data.input.InputEntity
        Throws:
        IOException
      • openCleanableFile

        public static org.apache.druid.data.input.InputEntity.CleanableFile openCleanableFile​(String sql,
                                                                                              SQLFirehoseDatabaseConnector sqlFirehoseDatabaseConnector,
                                                                                              com.fasterxml.jackson.databind.ObjectMapper objectMapper,
                                                                                              boolean foldCase,
                                                                                              File tempFile)
                                                                                       throws IOException
        Executes a SQL query on the specified database and fetches the result into the given file. The result file is deleted if the query execution or the file write fails.
        Parameters:
        sql - The SQL query to be executed
        sqlFirehoseDatabaseConnector - The database connector
        objectMapper - An object mapper, used for deserialization
        foldCase - A boolean flag used to enable or disabling case sensitivity while handling database column names
        Returns:
        A InputEntity.CleanableFile object that wraps the file containing the SQL results
        Throws:
        IOException