Package com.exasol.adapter.dialects
Class AbstractSqlDialect
- java.lang.Object
-
- com.exasol.adapter.dialects.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.exasol.adapter.dialects.SqlDialect
SqlDialect.ExceptionHandlingMode, SqlDialect.NullSorting, SqlDialect.StructureElementSupport
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionFactoryconnectionFactoryFactory that creates JDBC connection to the data sourceprotected com.exasol.ExaMetadataexaMetadataMetadata of the Exasol databaseprotected Set<com.exasol.adapter.sql.ScalarFunction>omitParenthesesMapSet of functions for which the adapter should omit parenthesesprotected com.exasol.adapter.AdapterPropertiespropertiesAdapter properties
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSqlDialect(JDBCAdapterContext context, Set<String> dialectSpecificProperties)Create a new instance of anAbstractSqlDialect.protectedAbstractSqlDialect(JDBCAdapterContext context, Set<String> dialectSpecificProperties, Collection<PropertyValidator> dialectSpecificPropertyValidators)Create a new instance of anAbstractSqlDialect.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddAdditionalSupportedProperties(List<String> additionalPropertiesToSupport)Add additional dialect-specific supported properties that are not in theCOMMON_SUPPORTED_PROPERTIESset.protected abstract QueryRewritercreateQueryRewriter()Create theQueryRewriterthat 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.protected abstract RemoteMetadataReadercreateRemoteMetadataReader()Create theRemoteMetadataReaderthat is used to get the database metadata from the remote source.Map<com.exasol.adapter.sql.AggregateFunction,String>getAggregateFunctionAliases()Map<com.exasol.adapter.sql.ScalarFunction,String>getBinaryInfixFunctionAliases()Map<com.exasol.adapter.sql.ScalarFunction,String>getPrefixFunctionAliases()Map<com.exasol.adapter.sql.ScalarFunction,String>getScalarFunctionAliases()SqlGeneratorgetSqlGenerator(SqlGenerationContext context)Returns the Visitor to be used for SQL generation.Set<String>getSupportedProperties()Get a set of adapter properties that the dialect supports.StringgetTableCatalogAndSchemaSeparator()booleanomitParentheses(com.exasol.adapter.sql.ScalarFunction function)Check whether a parentheses should be omitted for a function.protected StringquoteIdentifierWithDoubleQuotes(String identifier)Quote an identifier with double quotes.StringquoteLiteralStringWithSingleQuote(String value)Quote a string literal with single quotes.com.exasol.adapter.metadata.SchemaMetadatareadSchemaMetadata()Read the remote schema metadata for all tables from the remote source.com.exasol.adapter.metadata.SchemaMetadatareadSchemaMetadata(List<String> tables)Read the remote schema metadata for selected tables from the remote source.StringrewriteQuery(com.exasol.adapter.sql.SqlStatement statement, List<com.exasol.adapter.metadata.DataType> selectListDataTypes, com.exasol.ExaMetadata exaMetadata)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.voidvalidateProperties()Validate user-defined properties and throw exception if they are incorrect.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.exasol.adapter.dialects.SqlDialect
applyQuote, close, getCapabilities, getDefaultNullSorting, getName, getStringLiteral, requiresCatalogQualifiedTableNames, requiresSchemaQualifiedTableNames, supportsJdbcCatalogs, supportsJdbcSchemas
-
-
-
-
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 anAbstractSqlDialect.- Parameters:
context- the context for the SQL dialectdialectSpecificProperties- a set of properties that dialect supports additionally to the common setCOMMON_SUPPORTED_PROPERTIES
-
AbstractSqlDialect
protected AbstractSqlDialect(JDBCAdapterContext context, Set<String> dialectSpecificProperties, Collection<PropertyValidator> dialectSpecificPropertyValidators)
Create a new instance of anAbstractSqlDialect.- Parameters:
context- the context for the SQL dialectdialectSpecificProperties- a set of properties that dialect supports additionally to the common setCOMMON_SUPPORTED_PROPERTIESdialectSpecificPropertyValidators- 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 theCOMMON_SUPPORTED_PROPERTIESset.- Parameters:
additionalPropertiesToSupport- list of properties names
-
createRemoteMetadataReader
protected abstract RemoteMetadataReader createRemoteMetadataReader()
Create theRemoteMetadataReaderthat 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 theQueryRewriterthat 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:
getTableCatalogAndSchemaSeparatorin interfaceSqlDialect- 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:SqlDialectCheck whether a parentheses should be omitted for a function.- Specified by:
omitParenthesesin interfaceSqlDialect- 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:SqlDialectReturns 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 bySqlDialect.- Specified by:
getSqlGeneratorin interfaceSqlDialect- 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:
getScalarFunctionAliasesin interfaceSqlDialect- 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:
getAggregateFunctionAliasesin interfaceSqlDialect- 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:
getBinaryInfixFunctionAliasesin interfaceSqlDialect- 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:
getPrefixFunctionAliasesin interfaceSqlDialect- 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:SqlDialectRewrite 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:
rewriteQueryin interfaceSqlDialect- Parameters:
statement- original query as sent by the Virtual Schema frontendselectListDataTypes- expected datatypes of the result setexaMetadata- Exasol metadata- Returns:
- rewritten query
- Throws:
com.exasol.adapter.AdapterException- if rewriting the query failedSQLException- if execution of any SQL command on the remote data source failed
-
readSchemaMetadata
public com.exasol.adapter.metadata.SchemaMetadata readSchemaMetadata()
Description copied from interface:SqlDialectRead the remote schema metadata for all tables from the remote source.- Specified by:
readSchemaMetadatain interfaceSqlDialect- Returns:
- remote schema metadata
-
readSchemaMetadata
public com.exasol.adapter.metadata.SchemaMetadata readSchemaMetadata(List<String> tables)
Description copied from interface:SqlDialectRead the remote schema metadata for selected tables from the remote source.- Specified by:
readSchemaMetadatain interfaceSqlDialect- 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
-
validateProperties
public void validateProperties() throws PropertyValidationExceptionDescription copied from interface:SqlDialectValidate user-defined properties and throw exception if they are incorrect.- Specified by:
validatePropertiesin interfaceSqlDialect- Throws:
PropertyValidationException- if some properties are used incorrectly
-
-