Class Timestamp
java.lang.Object
org.apache.beam.sdk.schemas.logicaltypes.Timestamp
- All Implemented Interfaces:
Serializable,Schema.LogicalType<Instant,Row>
A timestamp represented with configurable precision.
This logical type stores timestamps as a Row with two fields:
- seconds: INT64 - seconds since Unix epoch (can be negative)
- subseconds: INT16 or INT32 - always non-negative (0 to 10^precision - 1)
The subseconds field is always non-negative, even for timestamps before the epoch. For
example, -1.5 seconds is represented as {seconds: -2, subseconds: 500000} for microsecond
precision. This matches Java's Instant internal representation.
Note for users converting from single-integer timestamp representations: If you have timestamps stored as a single long value (e.g., microseconds since epoch), you must handle negative modulo correctly when converting:
long timestampMicros = -1_500_000;
long seconds = timestampMicros / 1_000_000;
long micros = timestampMicros % 1_000_000;
if (micros < 0) {
micros += 1_000_000;
seconds -= 1;
}
Instant instant = Instant.ofEpochSecond(seconds, micros * 1000);
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAn optional argument to configure the type.A schema type representing how to interpret the argument.The baseSchema.FieldTypeused to store values of this type.The unique identifier for this type.static Timestampof(int precision) toBaseType(Instant input) Convert the input type to the type Java type used by the baseSchema.FieldType.toInputType(@NonNull Row base) Convert the Java type used by the baseSchema.FieldTypeto the input type.
-
Field Details
-
IDENTIFIER
- See Also:
-
MILLIS
-
MICROS
-
NANOS
-
-
Constructor Details
-
Timestamp
public Timestamp(int precision)
-
-
Method Details
-
of
-
getIdentifier
Description copied from interface:Schema.LogicalTypeThe unique identifier for this type.- Specified by:
getIdentifierin interfaceSchema.LogicalType<Instant,Row>
-
getArgumentType
Description copied from interface:Schema.LogicalTypeA schema type representing how to interpret the argument.nullindicates this logical type is not parameterized by an argument.- Specified by:
getArgumentTypein interfaceSchema.LogicalType<Instant,Row>
-
getArgument
Description copied from interface:Schema.LogicalTypeAn optional argument to configure the type.- Specified by:
getArgumentin interfaceSchema.LogicalType<Instant,Row>
-
getBaseType
Description copied from interface:Schema.LogicalTypeThe baseSchema.FieldTypeused to store values of this type.- Specified by:
getBaseTypein interfaceSchema.LogicalType<Instant,Row>
-
toBaseType
Description copied from interface:Schema.LogicalTypeConvert the input type to the type Java type used by the baseSchema.FieldType.- Specified by:
toBaseTypein interfaceSchema.LogicalType<Instant,Row>
-
toInputType
Description copied from interface:Schema.LogicalTypeConvert the Java type used by the baseSchema.FieldTypeto the input type.- Specified by:
toInputTypein interfaceSchema.LogicalType<Instant,Row>
-