Skip to content

Commit

Permalink
Add special cases for Exasol VS Local modus: explicit cast to utf8 in…
Browse files Browse the repository at this point in the history
… the case of char and varchar datatypes
  • Loading branch information
pj-spoelders committed Mar 28, 2024
1 parent aa62e3c commit cd744f7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ExasolLocalQueryRewriter implements QueryRewriter {
public String rewrite(final SqlStatement statement, final List<DataType> selectListDataTypes,
final ExaMetadata exaMetadata, final AdapterProperties properties) throws AdapterException {
final SqlGenerationContext context = new SqlGenerationContext(properties.getCatalogName(),
properties.getSchemaName(), false);
properties.getSchemaName(), true);
final SqlGenerator sqlGeneratorVisitor = this.dialect.getSqlGenerator(context);
final String selectStatement = sqlGeneratorVisitor.generateSqlFor(statement);
LOGGER.finer(() -> "SELECT push-down statement:\n" + selectStatement);
Expand Down
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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ public String getStringLiteral(final String value) {

@Override
public SqlGenerator getSqlGenerator(final SqlGenerationContext context) {
return new ExasolSqlGenerationVisitor(this, context);
if (context.isLocal()){
return new ExasolLocalSqlGenerationVisitor(this, context);
} else {
return new ExasolSqlGenerationVisitor(this, context);
}

}

/**
Expand Down

0 comments on commit cd744f7

Please sign in to comment.