-
Notifications
You must be signed in to change notification settings - Fork 25.3k
SQL: Add text formatting support for multivalue #68606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f118767
1ac7972
fc3fe72
37c3c19
4f16e1b
5e5ffb9
78a39df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.util.Collection; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; | ||
|
@@ -166,6 +168,23 @@ public static String toString(Object value, SqlVersion sqlVersion) { | |
return sb.toString(); | ||
} | ||
|
||
// multivalue | ||
if (value instanceof Collection) { | ||
final StringJoiner sj = new StringJoiner(",", "[", "]"); | ||
Collection<?> values = (Collection<?>) value; | ||
values.forEach(x -> { | ||
// quote strings and `\`-escape the `"` character inside them | ||
if (x instanceof String) { // TODO: IPs should ideally not be quoted. | ||
sj.add('"' + ((String) x).replace("\"", "\\\"") + '"'); | ||
} else if (x == null) { | ||
sj.add("NULL"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpicky: we return uppercase There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, GH only updated the page with your comment after I hit merge. As extra context: |
||
} else { | ||
sj.add(toString(x, sqlVersion)); | ||
} | ||
}); | ||
return sj.toString(); | ||
} | ||
|
||
return Objects.toString(value); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 nice!