Skip to content

Commit

Permalink
[doris][starrocks] remove SimpleDateFormat usage in Doris/StarRock co…
Browse files Browse the repository at this point in the history
…nnector because it's not thread safe.
  • Loading branch information
lvyanquan committed Jan 2, 2024
1 parent 7ab1e87 commit 59dcbe8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 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 @@ -22,24 +22,8 @@
import com.ververica.cdc.common.event.TableId;
import com.ververica.cdc.common.schema.Column;
import com.ververica.cdc.common.schema.Schema;
import com.ververica.cdc.common.types.BigIntType;
import com.ververica.cdc.common.types.BooleanType;
import com.ververica.cdc.common.types.CharType;
import com.ververica.cdc.common.types.DataType;
import com.ververica.cdc.common.types.DataTypeDefaultVisitor;
import com.ververica.cdc.common.types.DateType;
import com.ververica.cdc.common.types.DecimalType;
import com.ververica.cdc.common.types.DoubleType;
import com.ververica.cdc.common.types.FloatType;
import com.ververica.cdc.common.types.IntType;
import com.ververica.cdc.common.types.LocalZonedTimestampType;
import com.ververica.cdc.common.types.SmallIntType;
import com.ververica.cdc.common.types.TimestampType;
import com.ververica.cdc.common.types.TinyIntType;
import com.ververica.cdc.common.types.VarCharType;

import java.sql.Date;
import java.text.SimpleDateFormat;
import com.ververica.cdc.common.types.*;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -112,7 +96,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 +153,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 59dcbe8

Please sign in to comment.