-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add special cases for Exasol VS Local modus: explicit cast to utf8 in…
… the case of char and varchar datatypes
- Loading branch information
1 parent
aa62e3c
commit cd744f7
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/exasol/adapter/dialects/exasol/ExasolLocalSqlGenerationVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.exasol.adapter.dialects.exasol; | ||
|
||
import com.exasol.adapter.AdapterException; | ||
import com.exasol.adapter.dialects.SqlDialect; | ||
import com.exasol.adapter.dialects.rewriting.SqlGenerationContext; | ||
import com.exasol.adapter.metadata.DataType; | ||
import com.exasol.adapter.sql.SqlColumn; | ||
|
||
public class ExasolLocalSqlGenerationVisitor extends ExasolSqlGenerationVisitor{ | ||
/** | ||
* Creates a new instance of the {@link ExasolSqlGenerationVisitor}. | ||
* | ||
* @param dialect {@link ExasolSqlDialect} dialect | ||
* @param context SQL generation context | ||
*/ | ||
ExasolLocalSqlGenerationVisitor(SqlDialect dialect, SqlGenerationContext context) { | ||
super(dialect, context); | ||
} | ||
@Override | ||
public String visit(final SqlColumn column) throws AdapterException { | ||
ExasolSqlDialect exasolSqlDialect = new ExasolSqlDialect(null,null); | ||
String tablePrefix = ""; | ||
if (column.hasTableAlias()) { | ||
tablePrefix = exasolSqlDialect.applyQuote(column.getTableAlias()) | ||
+ exasolSqlDialect.getTableCatalogAndSchemaSeparator(); | ||
} else if ((column.getTableName() != null) && !column.getTableName().isEmpty()) { | ||
tablePrefix = exasolSqlDialect.applyQuote(column.getTableName()) | ||
+ exasolSqlDialect.getTableCatalogAndSchemaSeparator(); | ||
} | ||
//PROVIDE A CAST TO CORRESPONDING DATATYPE WITH THE SAME LENGTH BUT WITH UTF8 AS CHARSET | ||
if (column.getMetadata().getType().getExaDataType() == DataType.ExaDataType.CHAR || // | ||
column.getMetadata().getType().getExaDataType() == DataType.ExaDataType.VARCHAR) { | ||
int size = column.getMetadata().getType().getSize(); | ||
String dataTypeStr = column.getMetadata().getType().getExaDataType() == DataType.ExaDataType.CHAR ? "CHAR":"VARCHAR"; | ||
return "CAST(" + tablePrefix + exasolSqlDialect.applyQuote(column.getName())+" AS "+ dataTypeStr+"("+size+") UTF8)"; | ||
} else { | ||
return tablePrefix + exasolSqlDialect.applyQuote(column.getName()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters