[
https://issues.apache.org/jira/browse/FLINK-22588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17341737#comment-17341737
]
Yao Zhang commented on FLINK-22588:
-----------------------------------
I reviewed some relevant codes in
flink-core/src/main/java/org/apache/flink/util/TimeUtils.java:
```java
public static Duration parseDuration(String text) {
checkNotNull(text);
final String trimmed = text.trim();
checkArgument(!trimmed.isEmpty(), "argument is an empty- or
whitespace-only string");
final int len = trimmed.length();
int pos = 0;
char current;
while (pos < len && (current = trimmed.charAt(pos)) >= '0' && current
<= '9') {
pos++;
}
final String number = trimmed.substring(0, pos);
final String unitLabel =
trimmed.substring(pos).trim().toLowerCase(Locale.US);
if (number.isEmpty()) {
throw new NumberFormatException("text does not start with a
number");
}
final long value;
try {
value = Long.parseLong(number); // this throws a
NumberFormatException on overflow
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"The value '"
+ number
+ "' cannot be re represented as 64bit number
(numeric overflow).");
}
if (unitLabel.isEmpty()) {
return Duration.of(value, ChronoUnit.MILLIS);
}
ChronoUnit unit = LABEL_TO_UNIT_MAP.get(unitLabel);
if (unit != null) {
return Duration.of(value, unit);
} else {
throw new IllegalArgumentException(
"Time interval unit label '"
+ unitLabel
+ "' does not match any of the recognized units: "
+ TimeUnit.getAllUnits());
}
}
```
Both number and unit label parts are trimmed before parsing the expression to
Duration.
Some unit tests can be found in:
flink-core/src/test/java/org/apache/flink/util/TimeUtilsTest.java
```java
@Test
public void testParseDurationHours() {
assertEquals(987654, TimeUtils.parseDuration("987654h").toHours());
assertEquals(987654, TimeUtils.parseDuration("987654hour").toHours());
assertEquals(987654, TimeUtils.parseDuration("987654hours").toHours());
assertEquals(987654, TimeUtils.parseDuration("987654 h").toHours());
}
```
As shown above no matter there is a space between the number and the time unit
or not, TimeUtils can always get the right value.
But the inconsistencies in docs seem to be informal, and should be corrected.
> There is a configuration description error in the document
> ----------------------------------------------------------
>
> Key: FLINK-22588
> URL: https://issues.apache.org/jira/browse/FLINK-22588
> Project: Flink
> Issue Type: Bug
> Components: Connectors / FileSystem, Documentation, Table SQL /
> Ecosystem
> Affects Versions: 1.13.0
> Reporter: forideal
> Priority: Minor
>
> origin:
> ‘sink.partition-commit.delay’=‘1h’
> correct:
> ‘sink.partition-commit.delay’=‘1 h’
> [One space missing here]
> https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/connectors/table/filesystem/
--
This message was sent by Atlassian Jira
(v8.3.4#803005)