Class AbstractSqlDialect

  • All Implemented Interfaces:
    SqlDialect, AutoCloseable

    public abstract class AbstractSqlDialect
    extends Object
    implements SqlDialect
    Abstract implementation of a dialect. We recommend that every dialect should extend this abstract class.
    • Field Detail

      • connectionFactory

        protected final ConnectionFactory connectionFactory
        Factory that creates JDBC connection to the data source
      • omitParenthesesMap

        protected final Set<com.exasol.adapter.sql.ScalarFunction> omitParenthesesMap
        Set of functions for which the adapter should omit parentheses
      • properties

        protected final com.exasol.adapter.AdapterProperties properties
        Adapter properties
      • exaMetadata

        protected final com.exasol.ExaMetadata exaMetadata
        Metadata of the Exasol database
    • Constructor Detail

      • AbstractSqlDialect

        protected AbstractSqlDialect​(JDBCAdapterContext context,
                                     Set<String> dialectSpecificProperties)
        Create a new instance of an AbstractSqlDialect.
        Parameters:
        context - the context for the SQL dialect
        dialectSpecificProperties - a set of properties that dialect supports additionally to the common set COMMON_SUPPORTED_PROPERTIES
      • AbstractSqlDialect

        protected AbstractSqlDialect​(JDBCAdapterContext context,
                                     Set<String> dialectSpecificProperties,
                                     Collection<PropertyValidator> dialectSpecificPropertyValidators)
        Create a new instance of an AbstractSqlDialect.
        Parameters:
        context - the context for the SQL dialect
        dialectSpecificProperties - a set of properties that dialect supports additionally to the common set COMMON_SUPPORTED_PROPERTIES
        dialectSpecificPropertyValidators - a collection of property validators the dialect wants to apply additionally to the common validators
    • Method Detail

      • addAdditionalSupportedProperties

        protected void addAdditionalSupportedProperties​(List<String> additionalPropertiesToSupport)
        Add additional dialect-specific supported properties that are not in the COMMON_SUPPORTED_PROPERTIES set.
        Parameters:
        additionalPropertiesToSupport - list of properties names
      • createRemoteMetadataReader

        protected abstract RemoteMetadataReader createRemoteMetadataReader()
        Create the RemoteMetadataReader that is used to get the database metadata from the remote source.

        Override this method in the concrete SQL dialect implementation to choose the right metadata reader.

        Returns:
        metadata reader
      • createQueryRewriter

        protected abstract QueryRewriter createQueryRewriter()
        Create the QueryRewriter that is used to create the final SQL query sent back from the Virtual Schema backend to the Virtual Schema frontend in a push-down scenario.

        Override this method in the concrete SQL dialect implementation to choose the right query rewriter.

        Returns:
        query rewriter
      • getTableCatalogAndSchemaSeparator

        public String getTableCatalogAndSchemaSeparator()
        Specified by:
        getTableCatalogAndSchemaSeparator in interface SqlDialect
        Returns:
        String that is used to separate the catalog and/or the schema from the table name. In many cases this is a dot.
      • omitParentheses

        public boolean omitParentheses​(com.exasol.adapter.sql.ScalarFunction function)
        Description copied from interface: SqlDialect
        Check whether a parentheses should be omitted for a function.
        Specified by:
        omitParentheses in interface SqlDialect
        Parameters:
        function - function for which the necessity of parentheses is evaluated
        Returns:
        Returns true for functions with zero arguments if they do not require parentheses (e.g. SYSDATE).
      • getSqlGenerator

        public SqlGenerator getSqlGenerator​(SqlGenerationContext context)
        Description copied from interface: SqlDialect
        Returns the Visitor to be used for SQL generation. Use this only if you need to, i.e. if you have requirements which cannot be realized via the other methods provided by SqlDialect.
        Specified by:
        getSqlGenerator in interface SqlDialect
        Parameters:
        context - context information for the SQL generation visitor
        Returns:
        the SqlGenerationVisitor to be used for this dialect
      • getScalarFunctionAliases

        public Map<com.exasol.adapter.sql.ScalarFunction,​String> getScalarFunctionAliases()
        Specified by:
        getScalarFunctionAliases in interface SqlDialect
        Returns:
        aliases for scalar functions. To be defined for each function that has the same semantic but a different name in the data source. If an alias for the same function is defined in SqlDialect.getBinaryInfixFunctionAliases(), than the infix alias will be ignored.
      • getAggregateFunctionAliases

        public Map<com.exasol.adapter.sql.AggregateFunction,​String> getAggregateFunctionAliases()
        Specified by:
        getAggregateFunctionAliases in interface SqlDialect
        Returns:
        aliases for aggregate functions. To be defined for each function that has the same semantic but a different name in the data source.
      • getBinaryInfixFunctionAliases

        public Map<com.exasol.adapter.sql.ScalarFunction,​String> getBinaryInfixFunctionAliases()
        Specified by:
        getBinaryInfixFunctionAliases in interface SqlDialect
        Returns:
        Defines which binary scalar functions should be treated infix and how. E.g. a map entry ("ADD", "+") causes a function call "ADD(1,2)" to be written as "1 + 2".
      • getPrefixFunctionAliases

        public Map<com.exasol.adapter.sql.ScalarFunction,​String> getPrefixFunctionAliases()
        Specified by:
        getPrefixFunctionAliases in interface SqlDialect
        Returns:
        Defines which unary scalar functions should be treated prefix and how. E.g. a map entry ("NEG", "-") causes a function call "NEG(2)" to be written as "-2".
      • rewriteQuery

        public String rewriteQuery​(com.exasol.adapter.sql.SqlStatement statement,
                                   List<com.exasol.adapter.metadata.DataType> selectListDataTypes,
                                   com.exasol.ExaMetadata exaMetadata)
                            throws com.exasol.adapter.AdapterException,
                                   SQLException
        Description copied from interface: SqlDialect
        Rewrite the given query so that data from the remote data source is imported into Exasol when that query is executed on the Virtual Schema frontend.
        Specified by:
        rewriteQuery in interface SqlDialect
        Parameters:
        statement - original query as sent by the Virtual Schema frontend
        selectListDataTypes - expected datatypes of the result set
        exaMetadata - Exasol metadata
        Returns:
        rewritten query
        Throws:
        com.exasol.adapter.AdapterException - if rewriting the query failed
        SQLException - if execution of any SQL command on the remote data source failed
      • readSchemaMetadata

        public com.exasol.adapter.metadata.SchemaMetadata readSchemaMetadata()
        Description copied from interface: SqlDialect
        Read the remote schema metadata for all tables from the remote source.
        Specified by:
        readSchemaMetadata in interface SqlDialect
        Returns:
        remote schema metadata
      • readSchemaMetadata

        public com.exasol.adapter.metadata.SchemaMetadata readSchemaMetadata​(List<String> tables)
        Description copied from interface: SqlDialect
        Read the remote schema metadata for selected tables from the remote source.
        Specified by:
        readSchemaMetadata in interface SqlDialect
        Parameters:
        tables - selected tables for which the metadata should be read
        Returns:
        remote schema metadata
      • quoteLiteralStringWithSingleQuote

        public String quoteLiteralStringWithSingleQuote​(String value)
        Quote a string literal with single quotes.
        Parameters:
        value - string literal
        Returns:
        quoted string
      • quoteIdentifierWithDoubleQuotes

        protected String quoteIdentifierWithDoubleQuotes​(String identifier)
        Quote an identifier with double quotes.
        Parameters:
        identifier - identifier to quote
        Returns:
        quoted identifier
      • getSupportedProperties

        public Set<String> getSupportedProperties()
        Get a set of adapter properties that the dialect supports.
        Returns:
        set of supported properties