Skip to content

Commit

Permalink
[pipeline-connector][doris][starrocks] Remove SimpleDateFormat for th…
Browse files Browse the repository at this point in the history
…read safe (apache#2954)
  • Loading branch information
lvyanquan authored and joyCurry30 committed Mar 22, 2024
1 parent be1d601 commit d645367
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
Expand All @@ -50,7 +49,8 @@ public class DorisEventSerializer implements DorisRecordSerializer<Event> {
private Map<TableId, Schema> schemaMaps = new HashMap<>();

/** Format DATE type data. */
public static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
public static final DateTimeFormatter DATE_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd");

/** Format timestamp-related type data. */
public static final DateTimeFormatter DATE_TIME_FORMATTER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import java.io.IOException;
import java.io.Serializable;
import java.sql.Date;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -100,8 +99,7 @@ static SerializationConverter createExternalConverter(DataType type, ZoneId pipe
return (index, val) -> val.getDouble(index);
case DATE:
return (index, val) ->
DATE_FORMATTER.format(
Date.valueOf(LocalDate.ofEpochDay(val.getInt(index))));
LocalDate.ofEpochDay(val.getInt(index)).format(DATE_FORMATTER);
case TIMESTAMP_WITHOUT_TIME_ZONE:
return (index, val) ->
val.getTimestamp(index, DataTypeChecks.getPrecision(type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import com.ververica.cdc.common.types.TinyIntType;
import com.ververica.cdc.common.types.VarCharType;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -112,7 +110,8 @@ public static void toStarRocksDataType(Column cdcColumn, StarRocksColumn.Builder
}

/** Format DATE type data. */
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
private static final DateTimeFormatter DATE_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd");

/** Format timestamp-related type data. */
private static final DateTimeFormatter DATETIME_FORMATTER =
Expand Down Expand Up @@ -168,9 +167,8 @@ record ->
case DATE:
fieldGetter =
record ->
DATE_FORMATTER.format(
Date.valueOf(
LocalDate.ofEpochDay(record.getInt(fieldPos))));
LocalDate.ofEpochDay(record.getInt(fieldPos))
.format(DATE_FORMATTER);
break;
case TIMESTAMP_WITHOUT_TIME_ZONE:
fieldGetter =
Expand Down

0 comments on commit d645367

Please sign in to comment.