Skip to content

Commit

Permalink
[core] Support seconds-long in record level time field type (apache#4133
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chenxinwei authored Sep 5, 2024
1 parent 8193b86 commit aa04090
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/content/primary-key-table/compaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ In compaction, you can configure record-Level expire time to expire records, you

1. `'record-level.expire-time'`: time retain for records.
2. `'record-level.time-field'`: time field for record level expire.
3. `'record-level.time-field-type'`: time field type for record level expire, it can be seconds-int or millis-long.
3. `'record-level.time-field-type'`: time field type for record level expire, it can be seconds-int,seconds-long or millis-long.

Expiration happens in compaction, and there is no strong guarantee to expire records in time.

Expand Down
2 changes: 1 addition & 1 deletion docs/layouts/shortcodes/generated/core_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
<td><h5>record-level.time-field-type</h5></td>
<td style="word-wrap: break-word;">seconds-int</td>
<td><p>Enum</p></td>
<td>Time field type for record level expire, it can be seconds-int or millis-long.<br /><br />Possible values:<ul><li>"seconds-int": Timestamps in seconds should be INT type.</li><li>"millis-long": Timestamps in milliseconds should be BIGINT type.</li></ul></td>
<td>Time field type for record level expire, it can be seconds-int,seconds-long or millis-long.<br /><br />Possible values:<ul><li>"seconds-int": Timestamps in seconds with INT field type.</li><li>"seconds-long": Timestamps in seconds with BIGINT field type.</li><li>"millis-long": Timestamps in milliseconds with BIGINT field type.</li></ul></td>
</tr>
<tr>
<td><h5>rowkind.field</h5></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ public class CoreOptions implements Serializable {
.enumType(TimeFieldType.class)
.defaultValue(TimeFieldType.SECONDS_INT)
.withDescription(
"Time field type for record level expire, it can be seconds-int or millis-long.");
"Time field type for record level expire, it can be seconds-int,seconds-long or millis-long.");

public static final ConfigOption<String> FIELDS_DEFAULT_AGG_FUNC =
key(FIELDS_PREFIX + "." + DEFAULT_AGG_FUNCTION)
Expand Down Expand Up @@ -2728,9 +2728,11 @@ public InlineElement getDescription() {

/** Time field type for record level expire. */
public enum TimeFieldType implements DescribedEnum {
SECONDS_INT("seconds-int", "Timestamps in seconds should be INT type."),
SECONDS_INT("seconds-int", "Timestamps in seconds with INT field type."),

MILLIS_LONG("millis-long", "Timestamps in milliseconds should be BIGINT type.");
SECONDS_LONG("seconds-long", "Timestamps in seconds with BIGINT field type."),

MILLIS_LONG("millis-long", "Timestamps in milliseconds with BIGINT field type.");

private final String value;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ public static RecordLevelExpire create(CoreOptions options, RowType rowType) {
DataField field = rowType.getField(timeField);
if (!((timeFieldType == CoreOptions.TimeFieldType.SECONDS_INT
&& field.type() instanceof IntType)
|| (timeFieldType == CoreOptions.TimeFieldType.SECONDS_LONG
&& field.type() instanceof BigIntType)
|| (timeFieldType == CoreOptions.TimeFieldType.MILLIS_LONG
&& field.type() instanceof BigIntType))) {
throw new IllegalArgumentException(
String.format(
"Record level time field should be INT type, but is %s.",
field.type()));
"The record level time field type should be one of SECONDS_INT,SECONDS_LONG or MILLIS_LONG, "
+ "but time field type is %s, field type is %s.",
timeFieldType, field.type()));
}

return new RecordLevelExpire(fieldIndex, (int) expireTime.getSeconds(), timeFieldType);
Expand Down Expand Up @@ -98,6 +101,9 @@ private RecordReader<KeyValue> wrap(RecordReader<KeyValue> reader) {
case SECONDS_INT:
recordTime = kv.value().getInt(timeField);
break;
case SECONDS_LONG:
recordTime = (int) kv.value().getLong(timeField);
break;
case MILLIS_LONG:
recordTime = (int) (kv.value().getLong(timeField) / 1000);
break;
Expand Down

0 comments on commit aa04090

Please sign in to comment.