Skip to content

Commit

Permalink
make order of table properties in sql formatter deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudum committed Jun 29, 2015
1 parent 3ec02b1 commit 8162b19
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions sql-parser/src/main/java/io/crate/sql/SqlFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,20 @@ public Void visitClusteredBy(ClusteredBy node, Integer indent) {
@Override
public Void visitGenericProperties(GenericProperties node, Integer indent) {
int count = 0, max = node.properties().size();
builder.append("WITH (\n");
for (Map.Entry<String, Expression> propertyEntry : node.properties().entrySet()) {
builder.append(indentString(indent+1));
builder.append(propertyEntry.getKey())
.append(" = ");
propertyEntry.getValue().accept(this, indent);
if (++count < max) builder.append(",");
builder.append("\n");
if (max > 0) {
builder.append("WITH (\n");
@SuppressWarnings("unchecked")
TreeMap<String, Expression> sortedMap = new TreeMap(node.properties());
for (Map.Entry<String, Expression> propertyEntry : sortedMap.entrySet()) {
builder.append(indentString(indent+1));
builder.append(propertyEntry.getKey())
.append(" = ");
propertyEntry.getValue().accept(this, indent);
if (++count < max) builder.append(",");
builder.append("\n");
}
append(indent, ")");
}
append(indent, ")");
return null;
}

Expand Down

0 comments on commit 8162b19

Please sign in to comment.