Skip to content

Commit 8eadb2d

Browse files
committed
Clean up testCloseIdleWriters
1 parent 944c2ca commit 8eadb2d

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestCloseIdleWriters.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ protected QueryRunner createQueryRunner()
4848
@Test
4949
public void testCloseIdleWriters()
5050
{
51-
String tableName = "task_close_idle_writers_" + randomNameSuffix();
51+
String sourceTable = "tpch.\"sf0.1\".lineitem";
52+
String targetTable = "task_close_idle_writers_" + randomNameSuffix();
5253
try {
54+
String zeroShipModes = "'AIR', 'FOB', 'SHIP', 'TRUCK'";
55+
String oneShipModes = "'MAIL', 'RAIL', 'REG AIR'";
56+
String bothShipModes = zeroShipModes + ", " + oneShipModes;
57+
58+
long expectedCount = (long) computeScalar("SELECT count (*) FROM %s WHERE shipmode IN (%s)".formatted(sourceTable, bothShipModes));
59+
5360
// Create a table with two partitions (0 and 1). Using the order by trick we will write the partitions in
5461
// this order 0, 1, and then again 0. This way we are sure that during partition 1 write there will
5562
// be an idle writer for partition 0. Additionally, during second partition 0 write, there will be an idle
@@ -61,16 +68,16 @@ public void testCloseIdleWriters()
6168
discount, tax, returnflag, linestatus, commitdate, receiptdate, shipinstruct,
6269
comment, shipdate,
6370
CASE
64-
WHEN shipmode IN ('AIR', 'FOB', 'SHIP', 'TRUCK') THEN 0
65-
WHEN shipmode IN ('MAIL', 'RAIL', 'REG AIR') THEN 1
66-
ELSE 2
71+
WHEN shipmode IN (%s) THEN 0
72+
WHEN shipmode IN (%s) THEN 1
6773
END AS shipmodeVal
68-
FROM tpch.\"sf0.1\".lineitem
74+
FROM %s
75+
WHERE shipmode IN (%s)
6976
ORDER BY shipmode
70-
LIMIT 600571
71-
""".formatted(tableName);
77+
LIMIT %s
78+
""".formatted(targetTable, zeroShipModes, oneShipModes, sourceTable, bothShipModes, expectedCount);
7279

73-
// Disable all kind of scaling and set idle writer threshold to 10MB
80+
// Disable all kind of scaling and set low idle writer threshold
7481
assertUpdate(
7582
Session.builder(getSession())
7683
.setSystemProperty(SCALE_WRITERS, "false")
@@ -80,13 +87,13 @@ WHEN shipmode IN ('MAIL', 'RAIL', 'REG AIR') THEN 1
8087
.setSystemProperty(IDLE_WRITER_MIN_DATA_SIZE_THRESHOLD, "0.1MB")
8188
.build(),
8289
createTableSql,
83-
600571);
84-
long files = (long) computeScalar("SELECT count(DISTINCT \"$path\") FROM " + tableName);
90+
expectedCount);
91+
long files = (long) computeScalar("SELECT count(DISTINCT \"$path\") FROM " + targetTable);
8592
// There should more than 2 files since we triggered close idle writers.
8693
assertThat(files).isGreaterThan(2);
8794
}
8895
finally {
89-
assertUpdate("DROP TABLE IF EXISTS " + tableName);
96+
assertUpdate("DROP TABLE IF EXISTS " + targetTable);
9097
}
9198
}
9299
}

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestCloseIdleWriters.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ protected QueryRunner createQueryRunner()
4848
@Test
4949
public void testCloseIdleWriters()
5050
{
51-
String tableName = "task_close_idle_writers_" + randomNameSuffix();
51+
String sourceTable = "tpch.\"sf0.1\".lineitem";
52+
String targetTable = "task_close_idle_writers_" + randomNameSuffix();
5253
try {
54+
String zeroShipModes = "'AIR', 'FOB', 'SHIP', 'TRUCK'";
55+
String oneShipModes = "'MAIL', 'RAIL', 'REG AIR'";
56+
String bothShipModes = zeroShipModes + ", " + oneShipModes;
57+
58+
long expectedCount = (long) computeScalar("SELECT count (*) FROM %s WHERE shipmode IN (%s)".formatted(sourceTable, bothShipModes));
59+
5360
// Create a table with two partitions (0 and 1). Using the order by trick we will write the partitions in
5461
// this order 0, 1, and then again 0. This way we are sure that during partition 1 write there will
5562
// be an idle writer for partition 0. Additionally, during second partition 0 write, there will be an idle
@@ -61,16 +68,16 @@ public void testCloseIdleWriters()
6168
discount, tax, returnflag, linestatus, commitdate, receiptdate, shipinstruct,
6269
comment, shipdate,
6370
CASE
64-
WHEN shipmode IN ('AIR', 'FOB', 'SHIP', 'TRUCK') THEN 0
65-
WHEN shipmode IN ('MAIL', 'RAIL', 'REG AIR') THEN 1
66-
ELSE 2
71+
WHEN shipmode IN (%s) THEN 0
72+
WHEN shipmode IN (%s) THEN 1
6773
END AS shipmodeVal
68-
FROM tpch.\"sf0.1\".lineitem
74+
FROM %s
75+
WHERE shipmode IN (%s)
6976
ORDER BY shipmode
70-
LIMIT 600571
71-
""".formatted(tableName);
77+
LIMIT %s
78+
""".formatted(targetTable, zeroShipModes, oneShipModes, sourceTable, bothShipModes, expectedCount);
7279

73-
// Disable all kind of scaling and set idle writer threshold to 5MB
80+
// Disable all kind of scaling and set low idle writer threshold
7481
assertUpdate(
7582
Session.builder(getSession())
7683
.setSystemProperty(SCALE_WRITERS, "false")
@@ -80,13 +87,13 @@ WHEN shipmode IN ('MAIL', 'RAIL', 'REG AIR') THEN 1
8087
.setSystemProperty(IDLE_WRITER_MIN_DATA_SIZE_THRESHOLD, "0.1MB")
8188
.build(),
8289
createTableSql,
83-
600571);
84-
long files = (long) computeScalar("SELECT count(DISTINCT \"$path\") FROM " + tableName);
90+
expectedCount);
91+
long files = (long) computeScalar("SELECT count(DISTINCT \"$path\") FROM " + targetTable);
8592
// There should more than 2 files since we triggered close idle writers.
8693
assertThat(files).isGreaterThan(2);
8794
}
8895
finally {
89-
assertUpdate("DROP TABLE IF EXISTS " + tableName);
96+
assertUpdate("DROP TABLE IF EXISTS " + targetTable);
9097
}
9198
}
9299
}

0 commit comments

Comments
 (0)