diqiu50 commented on code in PR #6657:
URL: https://github.com/apache/gravitino/pull/6657#discussion_r2051879447
##########
api/src/main/java/org/apache/gravitino/rel/types/Types.java:
##########
@@ -346,36 +369,82 @@ public Name name() {
@Override
public String simpleString() {
- return "time";
+ if (!precision.isPresent()) {
+ return "time";
+ }
+ return String.format("time(%d)", precision.get());
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TimeType)) return false;
+ TimeType that = (TimeType) o;
+ return Objects.equals(precision, that.precision);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(precision);
}
}
/** The timestamp type in Gravitino. */
public static class TimestampType extends Type.DateTimeType {
- private static final TimestampType INSTANCE_WITHOUT_TIME_ZONE = new
TimestampType(false);
- private static final TimestampType INSTANCE_WITH_TIME_ZONE = new
TimestampType(true);
+ private static final TimestampType INSTANCE_WITHOUT_TIME_ZONE =
+ new TimestampType(false, Optional.empty());
+ private static final TimestampType INSTANCE_WITH_TIME_ZONE =
+ new TimestampType(true, Optional.empty());
+
+ /** @return A {@link TimestampType} without time zone. */
+ public static TimestampType withoutTimeZone() {
+ return INSTANCE_WITHOUT_TIME_ZONE;
+ }
/** @return A {@link TimestampType} with time zone. */
public static TimestampType withTimeZone() {
return INSTANCE_WITH_TIME_ZONE;
}
- /** @return A {@link TimestampType} without time zone. */
- public static TimestampType withoutTimeZone() {
- return INSTANCE_WITHOUT_TIME_ZONE;
+ /**
+ * @param precision The precision of the timestamp type.
+ * @return A {@link TimestampType} with the given precision and without
time zone.
+ */
+ public static TimestampType withoutTimeZone(Integer precision) {
+ return new TimestampType(false, Optional.ofNullable(precision));
+ }
+
+ /**
+ * @param precision The precision of the timestamp type.
+ * @return A {@link TimestampType} with the given precision and time zone.
+ */
+ public static TimestampType withTimeZone(Integer precision) {
+ return new TimestampType(true, Optional.ofNullable(precision));
}
private final boolean withTimeZone;
+ private final Optional<Integer> precision;
- private TimestampType(boolean withTimeZone) {
+ private TimestampType(boolean withTimeZone, Optional<Integer> precision) {
this.withTimeZone = withTimeZone;
+ this.precision = precision;
}
/** @return True if the timestamp type has time zone, false otherwise. */
public boolean hasTimeZone() {
return withTimeZone;
}
+ /** @return True if the timestamp type has precision specified, false
otherwise. */
+ public boolean hasPrecision() {
+ return precision.isPresent();
+ }
+
+ /** @return The precision of the timestamp type. */
+ public Integer precision() {
Review Comment:
Is it better to return Option<Integer>?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]