aloyszhang commented on code in PR #9900:
URL: https://github.com/apache/inlong/pull/9900#discussion_r1544148260
##########
inlong-common/src/main/java/org/apache/inlong/common/msg/InLongMsgAttrBuilder.java:
##########
@@ -257,41 +259,48 @@ public String buildAttr() throws Exception {
}
if (t != null) {
String tstr = null;
- if (tt != null && tt == TimeType.NORMAL) {
- if (makeSureTimeNormal(t)) {
- tstr = t;
- }
+ if (tt != null && tt == TimeType.NORMAL &&
makeSureTimeNormal(t)) {
+ tstr = t;
} else {
if (this.p == null) {
this.p = PartitionUnit.HOUR;
}
Date d = transData(tt, t);
- if (this.p == PartitionUnit.DAY) {
- SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
- tstr = f.format(d);
- } else if (this.p == PartitionUnit.HOUR) {
- SimpleDateFormat f = new
SimpleDateFormat("yyyyMMddHH");
- tstr = f.format(d);
- } else if (this.p == PartitionUnit.HALFHOUR) {
- int idx =
- (int) ((d.getTime() % (60L * 60 * 1000)) /
(30L * 60 * 1000));
- SimpleDateFormat f = new
SimpleDateFormat("yyyyMMddHH");
- tstr = f.format(d) + "n" + idx;
- } else if (this.p == PartitionUnit.QUARTER) {
- int idx =
- (int) ((d.getTime() % (60L * 60 * 1000)) /
(15L * 60 * 1000));
- SimpleDateFormat f = new
SimpleDateFormat("yyyyMMddHH");
- tstr = f.format(d) + "q" + idx;
- } else if (this.p == PartitionUnit.TENMINS) {
- int idx =
- (int) ((d.getTime() % (60L * 60 * 1000)) /
(10L * 60 * 1000));
- SimpleDateFormat f = new
SimpleDateFormat("yyyyMMddHH");
- tstr = f.format(d) + "t" + idx;
- } else if (this.p == PartitionUnit.FIVEMINS) {
- int idx =
- (int) ((d.getTime() % (60L * 60 * 1000)) / (5L
* 60 * 1000));
+ if (d != null) {
+ SimpleDateFormat fd = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat f = new
SimpleDateFormat("yyyyMMddHH");
- tstr = f.format(d) + "f" + idx;
+ switch (this.p) {
+ case DAY:
+ tstr = fd.format(d);
+ break;
+ case HOUR:
+ tstr = f.format(d);
+ break;
+ case HALFHOUR: {
+ int idx =
+ (int) ((d.getTime() % (60L * 60 *
1000)) / (30L * 60 * 1000));
+ tstr = f.format(d) + "n" + idx;
+ }
+ break;
+ case QUARTER: {
+ int idx =
+ (int) ((d.getTime() % (60L * 60 *
1000)) / (15L * 60 * 1000));
+ tstr = f.format(d) + "q" + idx;
+ }
+ break;
+ case TENMINS: {
+ int idx =
+ (int) ((d.getTime() % (60L * 60 *
1000)) / (10L * 60 * 1000));
+ tstr = f.format(d) + "t" + idx;
+ }
+ break;
+ case FIVEMINS: {
+ int idx =
+ (int) ((d.getTime() % (60L * 60 *
1000)) / (5L * 60 * 1000));
+ tstr = f.format(d) + "f" + idx;
+ }
+ break;
+ }
Review Comment:
```suggestion
switch (this.p) {
case DAY:
tstr = fd.format(d);
break;
case HOUR:
tstr = f.format(d);
break;
case HALFHOUR:
int idx = (int) ((d.getTime() % (60L * 60 * 1000)) /
(30L * 60 * 1000));
tstr = f.format(d) + "n" + idx;
break;
case QUARTER:
idx = (int) ((d.getTime() % (60L * 60 * 1000)) / (15L *
60 * 1000));
tstr = f.format(d) + "q" + idx;
break;
case TENMINS:
idx = (int) ((d.getTime() % (60L * 60 * 1000)) / (10L *
60 * 1000));
tstr = f.format(d) + "t" + idx;
break;
case FIVEMINS:
idx = (int) ((d.getTime() % (60L * 60 * 1000)) / (5L *
60 * 1000));
tstr = f.format(d) + "f" + idx;
break;
}
```
--
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]