Skip to content

Commit

Permalink
#201: fixed 'order by' clause problems (#202)
Browse files Browse the repository at this point in the history
* #201: Fixed 'ORDER BY' clause problems
  • Loading branch information
AnastasiiaSergienko authored and redcatbear committed Jun 11, 2019
1 parent d2b3f6b commit e03748c
Show file tree
Hide file tree
Showing 6 changed files with 512 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ private void appendColumnValue(final StringBuilder builder, final ResultSet resu
case Types.TIMESTAMP:
appendTimestamp(builder, resultSet, columnName);
break;
case Types.VARBINARY:
case Types.TIME:
case Types.VARCHAR:
builder.append(this.dialect.getStringLiteral(resultSet.getString(columnName)));
break;
case Types.TIME:
case Types.VARBINARY:
default:
appendString(builder, resultSet, columnName);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,9 @@ public boolean requiresSchemaQualifiedTableNames(final SqlGenerationContext cont
public NullSorting getDefaultNullSorting() {
return NullSorting.NULLS_SORTED_AT_END;
}

@Override
public SqlGenerationVisitor getSqlGenerationVisitor(final SqlGenerationContext context) {
return new BigQuerySqlGenerationVisitor(this, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.exasol.adapter.dialects.bigquery;

import com.exasol.adapter.*;
import com.exasol.adapter.dialects.*;
import com.exasol.adapter.sql.*;

import java.util.*;

/**
* This class implements a Google-Big-Query-specific variant of a SQL generation visitor.
*/
public class BigQuerySqlGenerationVisitor extends SqlGenerationVisitor {
/**
* Create a new instance of {@link BigQuerySqlGenerationVisitor}.
*
* @param dialect SQL dialect
* @param context SQL generation context
*/
public BigQuerySqlGenerationVisitor(final SqlDialect dialect, final SqlGenerationContext context) {
super(dialect, context);
}

@Override
public String visit(final SqlOrderBy orderBy) throws AdapterException {
final List<String> sqlOrderElement = new ArrayList<>();
for (int i = 0; i < orderBy.getExpressions().size(); ++i) {
final boolean isAscending = orderBy.isAscending().get(i);
final String elementSql = orderBy.getExpressions().get(i).accept(this) + (isAscending ? "" : " DESC");
sqlOrderElement.add(elementSql);
}
return "ORDER BY " + String.join(", ", sqlOrderElement);
}
}
Loading

0 comments on commit e03748c

Please sign in to comment.