Skip to content

Commit

Permalink
[MONDRIAN-1512] Implements generateInline for Impala. Also turns on D…
Browse files Browse the repository at this point in the history
…DL support since Impala does support temporary tables.
  • Loading branch information
lucboudreau committed Aug 22, 2013
1 parent f6bbf71 commit 24c8e73
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/main/mondrian/spi/impl/ImpalaDialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,29 @@ public String generateInline(
List<String> columnTypes,
List<String[]> valueList)
{
// TODO: fix this, when Impala has the necessary features. See bug
// http://jira.pentaho.com/browse/MONDRIAN-1512.
return "";
// Impala supports a syntax like:
// SELECT * FROM (VALUES <list of tuples>) AS T
final StringBuilder buf = new StringBuilder();
buf.append("SELECT * FROM (VALUES");
for (int i = 0; i < valueList.size(); i++) {
if (i > 0) {
buf.append(", ");
}
String[] values = valueList.get(i);
buf.append("(");
for (int j = 0; j < values.length; j++) {
String value = values[j];
if (j > 0) {
buf.append(", ");
}
final String columnType = columnTypes.get(j);
Datatype datatype = Datatype.valueOf(columnType);
quote(buf, value, datatype);
}
buf.append(")");
}
buf.append(") AS T");
return buf.toString();
}

public boolean allowsJoinOn() {
Expand All @@ -149,17 +169,14 @@ public void quoteStringLiteral(
StringBuilder buf,
String value)
{
// REVIEW: Are Impala's rules for string literals so very different
// from the standard? Or from Hive's?
String quote = "\'";
String s0 = value;

if (value.contains("'")) {
quote = "\"";
if (s0.contains("\\")) {
s0.replaceAll("\\\\", "\\\\");
}

if (value.contains(quote)) {
s0 = value.replaceAll(quote, "\\\\" + quote);
if (s0.contains(quote)) {
s0 = s0.replaceAll(quote, "\\\\" + quote);
}

buf.append(quote);
Expand Down Expand Up @@ -223,5 +240,9 @@ public String generateRegularExpression(
}
return sb.toString();
}

public boolean allowsDdl() {
return true;
}
}
// End ImpalaDialect.java

0 comments on commit 24c8e73

Please sign in to comment.