Skip to content

Commit 36167e2

Browse files
committed
Fix COPY TO command tests
1 parent 2744580 commit 36167e2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: src/main/java/com/ing/data/cassandra/jdbc/commands/CopyToCommandExecutor.java

+14
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
import java.sql.SQLException;
3737
import java.sql.SQLSyntaxErrorException;
3838
import java.sql.Statement;
39+
import java.sql.Timestamp;
3940
import java.sql.Types;
4041
import java.text.NumberFormat;
42+
import java.text.SimpleDateFormat;
4143
import java.util.Objects;
4244
import java.util.Properties;
4345
import java.util.stream.Stream;
@@ -46,6 +48,7 @@
4648
import static com.ing.data.cassandra.jdbc.commands.SpecialCommandsUtil.translateFilename;
4749
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.CANNOT_WRITE_CSV_FILE;
4850
import static org.apache.commons.lang3.StringUtils.EMPTY;
51+
import static org.apache.commons.lang3.time.TimeZones.GMT;
4952

5053
/**
5154
* Executor for special command copying table content to a CSV file.
@@ -249,6 +252,17 @@ private String applyFormatter(final NumberFormat formatter, final Number value)
249252
return Objects.toString(value, EMPTY);
250253
}
251254

255+
@Override
256+
protected String handleTimestamp(final Timestamp timestamp, final String timestampFormatString) {
257+
if (timestamp == null) {
258+
return null;
259+
}
260+
final SimpleDateFormat timeFormat = new SimpleDateFormat(timestampFormatString);
261+
// Use GMT time zone for the timestamp values to get consistent and machine-independent results.
262+
timeFormat.setTimeZone(GMT);
263+
return timeFormat.format(timestamp);
264+
}
265+
252266
private String getColumnValue(final java.sql.ResultSet rs, final int colType, final int colIndex,
253267
final boolean trim, final String dateFormatString,
254268
final String timestampFormatString) throws SQLException, IOException {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"table_key";"ascii_val";"bigint_val";"blob_val";"bool_val";"date_val";"decimal_val";"double_val";"duration_val";"float_val";"inet_val";"int_val";"list_val";"map_val";"set_val";"smallint_val";"time_val";"timeuuid_val";"tinyint_val";"ts_val";"tuple_val";"uuid_val";"varchar_val";"varint_val";"vector_val"
2-
"key1";"abc123";"12345678900000";"this is a blob";"true";"2023-03-25";"18.97";"2345.6";"3h15m";"21.3";"/127.0.0.1";"98";"[4, 6, 10]";"{8=eight, 3=three}";"[2, 3, 5]";"2";"12:30:45";"1f4b6fe0-f12b-11ef-8b6b-fdf7025e383c";"12";"2023-03-25 13:30:45+0100";"(5,'five')";"f26f86e6-d8ef-4d30-9d9e-4027d21e02a9";"varchar text";"4321";"[1, 3, 8, 6]"
2+
"key1";"abc123";"12345678900000";"this is a blob";"true";"2023-03-25";"18.97";"2345.6";"3h15m";"21.3";"/127.0.0.1";"98";"[4, 6, 10]";"{8=eight, 3=three}";"[2, 3, 5]";"2";"12:30:45";"1f4b6fe0-f12b-11ef-8b6b-fdf7025e383c";"12";"2023-03-25 12:30:45+0000";"(5,'five')";"f26f86e6-d8ef-4d30-9d9e-4027d21e02a9";"varchar text";"4321";"[1, 3, 8, 6]"

0 commit comments

Comments
 (0)