Merge branch 'cassandra-4.1' into cassandra-5.0

This commit is contained in:
Stefan Miklosovic 2024-04-23 00:53:59 +02:00
commit 93692a4b17
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
4 changed files with 23 additions and 17 deletions

View File

@ -39,6 +39,7 @@ Merged from 4.1:
* Memoize Cassandra verion and add a backoff interval for failed schema pulls (CASSANDRA-18902)
* Fix StackOverflowError on ALTER after many previous schema changes (CASSANDRA-19166)
Merged from 4.0:
* Fix CQL tojson timestamp output on negative timestamp values before Gregorian calendar reform in 1582 (CASSANDRA-19566)
* Fix few types issues and implement types compatibility tests (CASSANDRA-19479)
* Change logging to TRACE when failing to get peer certificate (CASSANDRA-19508)
* Push LocalSessions info logs to debug (CASSANDRA-18335)

View File

@ -99,7 +99,7 @@ public class DateType extends AbstractType<Date>
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer)) + '"';
return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer).toInstant()) + '"';
}
@Override

View File

@ -124,7 +124,7 @@ public class TimestampType extends TemporalType<Date>
private String toString(Date date)
{
return date != null ? TimestampSerializer.getJsonDateFormatter().format(date) : "";
return date != null ? TimestampSerializer.getJsonDateFormatter().format(date.toInstant()) : "";
}
@Override

View File

@ -22,7 +22,7 @@ import org.apache.cassandra.db.marshal.ValueAccessor;
import org.apache.cassandra.utils.ByteBufferUtil;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.text.Format;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@ -32,7 +32,6 @@ import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.regex.Pattern;
import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis;
@ -105,23 +104,29 @@ public class TimestampSerializer extends TypeSerializer<Date>
private static final Pattern timestampPattern = Pattern.compile("^-?\\d+$");
private static final FastThreadLocal<SimpleDateFormat> FORMATTER_UTC = new FastThreadLocal<SimpleDateFormat>()
private static final FastThreadLocal<Format> FORMATTER_UTC = new FastThreadLocal<>()
{
protected SimpleDateFormat initialValue()
protected java.text.Format initialValue()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf;
return new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX")
.parseDefaulting(ChronoField.NANO_OF_DAY, 0)
.toFormatter()
.withZone(ZoneId.of("UTC"))
.toFormat();
}
};
private static final FastThreadLocal<SimpleDateFormat> FORMATTER_TO_JSON = new FastThreadLocal<SimpleDateFormat>()
private static final FastThreadLocal<Format> FORMATTER_TO_JSON = new FastThreadLocal<>()
{
protected SimpleDateFormat initialValue()
protected java.text.Format initialValue()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSX");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf;
return new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd HH:mm:ss.SSSX")
.parseDefaulting(ChronoField.NANO_OF_DAY, 0)
.toFormatter()
.withZone(ZoneId.of("UTC"))
.toFormat();
}
};
@ -171,7 +176,7 @@ public class TimestampSerializer extends TypeSerializer<Date>
throw new MarshalException(String.format("Unable to parse a date/time from '%s'", source));
}
public static SimpleDateFormat getJsonDateFormatter()
public static Format getJsonDateFormatter()
{
return FORMATTER_TO_JSON.get();
}
@ -189,7 +194,7 @@ public class TimestampSerializer extends TypeSerializer<Date>
public String toStringUTC(Date value)
{
return value == null ? "" : FORMATTER_UTC.get().format(value);
return value == null ? "" : FORMATTER_UTC.get().format(value.toInstant());
}
public Class<Date> getType()
@ -206,6 +211,6 @@ public class TimestampSerializer extends TypeSerializer<Date>
@Override
protected String toCQLLiteralNonNull(ByteBuffer buffer)
{
return FORMATTER_UTC.get().format(deserialize(buffer));
return FORMATTER_UTC.get().format(deserialize(buffer).toInstant());
}
}