Skip to content

Commit cafe523

Browse files
committed
Add the option to not quote date/time values in text outputs.
1 parent 5cee2a5 commit cafe523

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

query-engine/docs/query-engine-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ services:
5050
- 16686:16686
5151

5252
query-engine:
53-
image: ghcr.io/yaytay/query-engine-design-mode:0.0.72-main
53+
image: ghcr.io/yaytay/query-engine-design-mode:0.0.72-1-main
5454
ports:
5555
- 2000:8080
5656
volumes:

query-engine/src/main/java/uk/co/spudsoft/query/defn/FormatDelimited.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class FormatDelimited implements Format {
4747

4848
private final boolean bom;
4949
private final boolean headerRow;
50+
private final boolean quoteTemporal;
5051
private final String delimiter;
5152
private final String openQuote;
5253
private final String closeQuote;
@@ -229,6 +230,20 @@ public boolean hasHeaderRow() {
229230
return headerRow;
230231
}
231232

233+
/**
234+
* If true (the default) date/time values will be surrounded by quotes, otherwise they will not.
235+
* @return true if date/time values should be surrounded by quotes, otherwise they will not.
236+
*/
237+
@Schema(description = """
238+
If true date/time values will be surrounded by quotes, otherwise they will not.
239+
"""
240+
, defaultValue = "true"
241+
, requiredMode = Schema.RequiredMode.NOT_REQUIRED
242+
)
243+
public boolean isQuoteTemporal() {
244+
return quoteTemporal;
245+
}
246+
232247
/**
233248
* The delimiter between field values in the output.
234249
* @return the delimiter between field values in the output.
@@ -340,6 +355,7 @@ public static class Builder {
340355
private boolean hidden = false;
341356
private boolean bom = false;
342357
private boolean headerRow = true;
358+
private boolean quoteTemporal = true;
343359
private String delimiter = ",";
344360
private String openQuote = "\"";
345361
private String closeQuote = "\"";
@@ -423,6 +439,17 @@ public Builder hidden(final boolean hidden) {
423439
return this;
424440
}
425441

442+
/**
443+
* Set the quoteTemporal property of the format.
444+
*
445+
* @param quoteTemporal the {@link FormatDelimited#isQuoteTemporal()} property of the format.
446+
* @return this Builder instance.
447+
*/
448+
public Builder quoteTemporal(final boolean quoteTemporal) {
449+
this.quoteTemporal = quoteTemporal;
450+
return this;
451+
}
452+
426453
/**
427454
* Set the {@link FormatDelimited#bom} value in the builder.
428455
* @param value The value for the {@link FormatDelimited#bom}.
@@ -508,7 +535,7 @@ public Builder newline(final String value) {
508535
* @return a new instance of the FormatDelimited class.
509536
*/
510537
public FormatDelimited build() {
511-
return new FormatDelimited(type, name, description, extension, filename, mediaType, hidden, bom, headerRow, delimiter, openQuote, closeQuote, escapeCloseQuote, replaceCloseQuote, newline);
538+
return new FormatDelimited(type, name, description, extension, filename, mediaType, hidden, bom, headerRow, quoteTemporal, delimiter, openQuote, closeQuote, escapeCloseQuote, replaceCloseQuote, newline);
512539
}
513540
}
514541

@@ -529,6 +556,7 @@ private FormatDelimited(final FormatType type
529556
, final boolean hidden
530557
, final boolean bom
531558
, final boolean headerRow
559+
, final boolean quoteTemporal
532560
, final String delimiter
533561
, final String openQuote
534562
, final String closeQuote
@@ -546,6 +574,7 @@ private FormatDelimited(final FormatType type
546574
this.hidden = hidden;
547575
this.bom = bom;
548576
this.headerRow = headerRow;
577+
this.quoteTemporal = quoteTemporal;
549578
this.delimiter = delimiter;
550579
this.openQuote = openQuote;
551580
this.closeQuote = closeQuote;

query-engine/src/main/java/uk/co/spudsoft/query/exec/fmts/text/FormatDelimitedInstance.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,18 @@ private Future<Void> outputRow(DataRow row) {
146146
case Date:
147147
case DateTime:
148148
case Time:
149+
if (defn.isQuoteTemporal()) {
150+
outputRow.append(defn.getOpenQuote());
151+
outputRow.append(encodeCloseQuote(defn, v.toString()));
152+
outputRow.append(defn.getCloseQuote());
153+
} else {
154+
outputRow.append(v.toString());
155+
}
156+
break;
149157
case String:
150158
default:
151159
outputRow.append(defn.getOpenQuote());
152-
String string = v.toString();
153-
string = encodeCloseQuote(defn, string);
154-
outputRow.append(string);
160+
outputRow.append(encodeCloseQuote(defn, v.toString()));
155161
outputRow.append(defn.getCloseQuote());
156162
break;
157163
}

query-engine/src/main/java/uk/co/spudsoft/query/main/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class Version {
3434
/**
3535
* The project version, as set in the Maven pom.xml.
3636
*/
37-
public static final String MAVEN_PROJECT_VERSION = "0.0.72-main";
37+
public static final String MAVEN_PROJECT_VERSION = "0.0.72-1-main";
3838

3939
private Version() {
4040
}

0 commit comments

Comments
 (0)