Package com.exasol.adapter.dialects
Interface SqlDialect
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractSqlDialect
public interface SqlDialect extends AutoCloseable
Interface for the implementation of a SQL dialect.Dialects define the capabilities and the behavior of the adapter implementation for a specific remote database.
For information about how the metadata of the remote data source is mapped, please refer to the list of interfaces below.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classSqlDialect.ExceptionHandlingModeThis enumeration specifies different exception handling strategies.static classSqlDialect.NullSortingStrategies for sortingNULLvalues.static classSqlDialect.StructureElementSupportMultiplicity that the remote data source supports for a structural element like catalogs or a schemas.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description StringapplyQuote(String identifier)default voidclose()Map<com.exasol.adapter.sql.AggregateFunction,String>getAggregateFunctionAliases()Map<com.exasol.adapter.sql.ScalarFunction,String>getBinaryInfixFunctionAliases()com.exasol.adapter.capabilities.CapabilitiesgetCapabilities()Get the capabilities the SQL dialect supports.SqlDialect.NullSortinggetDefaultNullSorting()StringgetName()Get the dialect name.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.StringgetStringLiteral(String value)StringgetTableCatalogAndSchemaSeparator()booleanomitParentheses(com.exasol.adapter.sql.ScalarFunction function)Check whether a parentheses should be omitted for a function.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.booleanrequiresCatalogQualifiedTableNames(SqlGenerationContext context)Check whether the dialect expects table identifiers to be qualified with the catalog.booleanrequiresSchemaQualifiedTableNames(SqlGenerationContext context)Check whether the dialect expects table identifiers to be qualified with the schema.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.SqlDialect.StructureElementSupportsupportsJdbcCatalogs()Define whether the remote source supports catalogs and if it does, check if it supports a single "pseudo" catalog or multiple catalogs.SqlDialect.StructureElementSupportsupportsJdbcSchemas()Define whether the remote source supports schemas and if it does, check if it supports a single "pseudo" schema or multiple schemas.voidvalidateProperties()Validate user-defined properties and throw exception if they are incorrect.
-
-
-
Method Detail
-
getName
String getName()
Get the dialect name.- Returns:
- name of the dialect
-
getCapabilities
com.exasol.adapter.capabilities.Capabilities getCapabilities()
Get the capabilities the SQL dialect supports.- Returns:
- set of capabilities supported by this SQL-Dialect
-
supportsJdbcCatalogs
SqlDialect.StructureElementSupport supportsJdbcCatalogs()
Define whether the remote source supports catalogs and if it does, check if it supports a single "pseudo" catalog or multiple catalogs.- Returns:
NONEif the dialect does not support catalogs at all,SINGLEif it supports exactly one (like e.g. Exasol) orMULTIPLEif real catalogs are supported.
-
supportsJdbcSchemas
SqlDialect.StructureElementSupport supportsJdbcSchemas()
Define whether the remote source supports schemas and if it does, check if it supports a single "pseudo" schema or multiple schemas.- Returns:
NONEif the dialect does not support schemas at all,SINGLEif it supports exactly one (like e.g. Exasol) orMULTIPLEif real schemas are supported.
-
applyQuote
String applyQuote(String identifier)
- Parameters:
identifier- The name of an identifier (table or column). If identifiers are case sensitive, the identifier must be passed case-sensitive of course.- Returns:
- the quoted identifier, also if quoting is not required
-
requiresCatalogQualifiedTableNames
boolean requiresCatalogQualifiedTableNames(SqlGenerationContext context)
Check whether the dialect expects table identifiers to be qualified with the catalog.Example:
SELECT * FROM MY_CATALOG.MY_TABLECan be combined with
requiresSchemaQualifiedTableNames(SqlGenerationContext).- Parameters:
context- context for SQL generation- Returns:
trueif table names must be catalog-qualified
-
requiresSchemaQualifiedTableNames
boolean requiresSchemaQualifiedTableNames(SqlGenerationContext context)
Check whether the dialect expects table identifiers to be qualified with the schema.Example:
SELECT * FROM MY_SCHEMA.MY_TABLECan be combined with
requiresCatalogQualifiedTableNames(SqlGenerationContext).- Parameters:
context- context for SQL generation- Returns:
trueif table names must be schema-qualified
-
getTableCatalogAndSchemaSeparator
String getTableCatalogAndSchemaSeparator()
- Returns:
- String that is used to separate the catalog and/or the schema from the table name. In many cases this is a dot.
-
getDefaultNullSorting
SqlDialect.NullSorting getDefaultNullSorting()
- Returns:
- The behavior how nulls are sorted in an ORDER BY. If the null sorting behavior is not
SqlDialect.NullSorting.NULLS_SORTED_AT_ENDand your dialects has the order by capability but you cannot explicitly specify NULLS FIRST or NULLS LAST, then you must overwrite the SQL generation to somehow obtain the desired semantic.
-
getStringLiteral
String getStringLiteral(String value)
- Parameters:
value- a string literal value- Returns:
- the string literal in valid SQL syntax, e.g. "value" becomes "'value'". This might include escaping.
-
getScalarFunctionAliases
Map<com.exasol.adapter.sql.ScalarFunction,String> getScalarFunctionAliases()
- 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
getBinaryInfixFunctionAliases(), than the infix alias will be ignored.
-
getBinaryInfixFunctionAliases
Map<com.exasol.adapter.sql.ScalarFunction,String> getBinaryInfixFunctionAliases()
- 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
Map<com.exasol.adapter.sql.ScalarFunction,String> getPrefixFunctionAliases()
- 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".
-
getAggregateFunctionAliases
Map<com.exasol.adapter.sql.AggregateFunction,String> getAggregateFunctionAliases()
- Returns:
- aliases for aggregate functions. To be defined for each function that has the same semantic but a different name in the data source.
-
omitParentheses
boolean omitParentheses(com.exasol.adapter.sql.ScalarFunction function)
Check whether a parentheses should be omitted for a function.- 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
SqlGenerator getSqlGenerator(SqlGenerationContext context)
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 bySqlDialect.- Parameters:
context- context information for the SQL generation visitor- Returns:
- the SqlGenerationVisitor to be used for this dialect
-
readSchemaMetadata
com.exasol.adapter.metadata.SchemaMetadata readSchemaMetadata() throws SQLExceptionRead the remote schema metadata for all tables from the remote source.- Returns:
- remote schema metadata
- Throws:
SQLException- if reading the remote metadata fails
-
readSchemaMetadata
com.exasol.adapter.metadata.SchemaMetadata readSchemaMetadata(List<String> tables)
Read the remote schema metadata for selected tables from the remote source.- Parameters:
tables- selected tables for which the metadata should be read- Returns:
- remote schema metadata
-
validateProperties
void validateProperties() throws PropertyValidationExceptionValidate user-defined properties and throw exception if they are incorrect.- Throws:
PropertyValidationException- if some properties are used incorrectly
-
rewriteQuery
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
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.- Parameters:
statement- original query as sent by the Virtual Schema frontendselectListDataTypes- expected datatypes of the result setexaMetadata- Exasol metadata- Returns:
- rewritten query
- Throws:
SQLException- if execution of any SQL command on the remote data source failedcom.exasol.adapter.AdapterException- if rewriting the query failed
-
close
default void close()
- Specified by:
closein interfaceAutoCloseable
-
-