Make identifier formatting methods public
@@ -98,6 +98,7 @@ import static com.facebook.presto.sql.SqlFormatter.formatSql;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Iterables.getOnlyElement;
import static java.lang.String.format;
+import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public final class ExpressionFormatter
@@ -112,6 +113,18 @@ public final class ExpressionFormatter
return new Formatter(parameters).process(expression, null);
}
+ public static String formatQualifiedName(QualifiedName name)
+ {
+ return name.getParts().stream()
+ .map(ExpressionFormatter::formatIdentifier)
+ .collect(joining("."));
+ }
+
+ public static String formatIdentifier(String s)
+ {
+ return '"' + s.replace("\"", "\"\"") + '"';
+ }
+
public static class Formatter
extends AstVisitor<String, Void>
{
@@ -330,15 +343,6 @@ public final class ExpressionFormatter
return baseString + "." + process(node.getField());
}
- private static String formatQualifiedName(QualifiedName name)
- {
- List<String> parts = new ArrayList<>();
- for (String part : name.getParts()) {
- parts.add(formatIdentifier(part));
- }
- return Joiner.on('.').join(parts);
- }
-
@Override
public String visitFieldReference(FieldReference node, Void context)
{
@@ -683,12 +687,6 @@ public final class ExpressionFormatter
.map((e) -> process(e, null))
.iterator());
}
-
- private static String formatIdentifier(String s)
- {
- // TODO: handle escaping properly
- return '"' + s + '"';
- }
}
static String formatStringLiteral(String s)
