Skip to content

Commit f1eb2db

Browse files
committed
[FLINK-38532] make small changes to improve code readability
1 parent 2fa0b8f commit f1eb2db

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

docs/content/docs/dev/table/materialized-table/statements.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ CREATE MATERIALIZED TABLE my_materialized_table_continuous
223223
'partition.fields.ds.date-formatter' = 'yyyy-MM-dd'
224224
)
225225
FRESHNESS = INTERVAL '10' SECOND
226-
AS
227-
SELECT
226+
AS SELECT
228227
k.ds,
229228
k.user_id,
230229
COUNT(*) AS event_count,

flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/materializedtable/MaterializedTableManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ private void createMaterializedTableInFullMode(
259259
ResolvedCatalogMaterializedTable catalogMaterializedTable =
260260
createMaterializedTableOperation.getCatalogMaterializedTable();
261261

262-
// convert duration to cron expression
263262
final IntervalFreshness freshness = catalogMaterializedTable.getDefinitionFreshness();
264263
String cronExpression = convertFreshnessToCron(freshness);
265264
// create full refresh job

flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/ShowCreateUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static String extractFreshness(ResolvedCatalogMaterializedTable materializedTabl
321321
final IntervalFreshness definitionFreshness = materializedTable.getDefinitionFreshness();
322322
return String.format(
323323
"FRESHNESS = INTERVAL '%s' %s",
324-
definitionFreshness.getIntervalInt(), definitionFreshness.getTimeUnit());
324+
definitionFreshness.getInterval(), definitionFreshness.getTimeUnit());
325325
}
326326

327327
static String extractRefreshMode(ResolvedCatalogMaterializedTable materializedTable) {

flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/IntervalFreshness.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.flink.table.api.ValidationException;
2323

2424
import java.time.Duration;
25+
import java.time.temporal.ChronoUnit;
2526
import java.util.Objects;
2627

2728
/**
@@ -116,24 +117,17 @@ public Duration toDuration() {
116117
* Prefers larger units when possible (e.g., 60 seconds → 1 minute).
117118
*/
118119
public static IntervalFreshness fromDuration(Duration duration) {
119-
long totalSeconds = duration.getSeconds();
120-
121-
long days = duration.toDays();
122-
if (days * 24 * 60 * 60 == totalSeconds) {
123-
return IntervalFreshness.ofDay(String.valueOf(days));
120+
if (duration.equals(duration.truncatedTo(ChronoUnit.DAYS))) {
121+
return IntervalFreshness.ofDay(String.valueOf(duration.toDays()));
124122
}
125-
126-
long hours = duration.toHours();
127-
if (hours * 60 * 60 == totalSeconds) {
128-
return IntervalFreshness.ofHour(String.valueOf(hours));
123+
if (duration.equals(duration.truncatedTo(ChronoUnit.HOURS))) {
124+
return IntervalFreshness.ofHour(String.valueOf(duration.toHours()));
129125
}
130-
131-
long minutes = duration.toMinutes();
132-
if (minutes * 60 == totalSeconds) {
133-
return IntervalFreshness.ofMinute(String.valueOf(minutes));
126+
if (duration.equals(duration.truncatedTo(ChronoUnit.MINUTES))) {
127+
return IntervalFreshness.ofMinute(String.valueOf(duration.toMinutes()));
134128
}
135129

136-
return IntervalFreshness.ofSecond(String.valueOf(totalSeconds));
130+
return IntervalFreshness.ofSecond(String.valueOf(duration.getSeconds()));
137131
}
138132

139133
@Override

flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/SqlMaterializedTableNodeToOperationConverterTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ void testCreateMaterializedTable() {
130130
CreateMaterializedTableOperation op = (CreateMaterializedTableOperation) operation;
131131
ResolvedCatalogMaterializedTable materializedTable = op.getCatalogMaterializedTable();
132132

133-
Map<String, String> options = new HashMap<>();
134-
options.put("connector", "filesystem");
135-
options.put("format", "json");
133+
Map<String, String> options = Map.of("connector", "filesystem", "format", "json");
136134
CatalogMaterializedTable expected =
137135
CatalogMaterializedTable.newBuilder()
138136
.schema(
@@ -185,9 +183,7 @@ void testCreateMaterializedTableWithoutFreshness() {
185183
ResolvedCatalogMaterializedTable materializedTable = op.getCatalogMaterializedTable();
186184
assertThat(materializedTable).isInstanceOf(ResolvedCatalogMaterializedTable.class);
187185

188-
Map<String, String> options = new HashMap<>();
189-
options.put("connector", "filesystem");
190-
options.put("format", "json");
186+
Map<String, String> options = Map.of("connector", "filesystem", "format", "json");
191187

192188
CatalogMaterializedTable expected =
193189
CatalogMaterializedTable.newBuilder()
@@ -241,9 +237,7 @@ void testCreateMaterializedTableWithoutFreshnessAndRefreshMode() {
241237
ResolvedCatalogMaterializedTable materializedTable = op.getCatalogMaterializedTable();
242238
assertThat(materializedTable).isInstanceOf(ResolvedCatalogMaterializedTable.class);
243239

244-
Map<String, String> options = new HashMap<>();
245-
options.put("connector", "filesystem");
246-
options.put("format", "json");
240+
Map<String, String> options = Map.of("connector", "filesystem", "format", "json");
247241

248242
CatalogMaterializedTable expected =
249243
CatalogMaterializedTable.newBuilder()

0 commit comments

Comments
 (0)