Skip to content

Commit cdb1856

Browse files
authored
[Hotfix] Fix DEFAULT TABLE problem (#6352)
1 parent fd2a57d commit cdb1856

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

Diff for: pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<groupId>org.apache</groupId>
2222
<artifactId>apache</artifactId>
2323
<version>31</version>
24+
<relativePath />
2425
</parent>
2526

2627
<groupId>org.apache.seatunnel</groupId>

Diff for: seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtil.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ public static List<CatalogTable> getCatalogTables(
115115
return optionalCatalog
116116
.map(
117117
c -> {
118-
long startTime = System.currentTimeMillis();
119118
try (Catalog catalog = c) {
119+
long startTime = System.currentTimeMillis();
120120
catalog.open();
121121
List<CatalogTable> catalogTables =
122122
catalog.getTables(readonlyConfig);
123123
log.info(
124124
String.format(
125-
"Get catalog tables, cost time: %d",
125+
"Get catalog tables, cost time: %d ms",
126126
System.currentTimeMillis() - startTime));
127127
if (catalogTables.isEmpty()) {
128128
throw new SeaTunnelException(

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/mysql/MysqlDialect.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ public Long approximateRowCntStatement(Connection connection, JdbcSourceTable ta
174174
// 2. If a query is configured but does not contain a WHERE clause and tablePath is
175175
// configured , use TABLE STATUS.
176176
// 3. If a query is configured with a WHERE clause, or a query statement is configured but
177-
// tablePath is not, use COUNT(*).
177+
// tablePath is TablePath.DEFAULT, use COUNT(*).
178178

179179
boolean useTableStats =
180180
StringUtils.isBlank(table.getQuery())
181181
|| (!table.getQuery().toLowerCase().contains("where")
182-
&& table.getTablePath() != null);
182+
&& table.getTablePath() != null
183+
&& !TablePath.DEFAULT
184+
.getFullName()
185+
.equals(table.getTablePath().getFullName()));
186+
183187
if (useTableStats) {
184188
// The statement used to get approximate row count which is less
185189
// accurate than COUNT(*), but is more efficient for large table.

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/oracle/OracleDialect.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,16 @@ public Long approximateRowCntStatement(Connection connection, JdbcSourceTable ta
184184
// 2. If a query is configured but does not contain a WHERE clause and tablePath is
185185
// configured, use TABLE STATUS.
186186
// 3. If a query is configured with a WHERE clause, or a query statement is configured but
187-
// tablePath is not, use COUNT(*).
187+
// tablePath is TablePath.DEFAULT, use COUNT(*).
188188

189189
boolean useTableStats =
190190
StringUtils.isBlank(table.getQuery())
191191
|| (!table.getQuery().toLowerCase().contains("where")
192-
&& table.getTablePath() != null);
192+
&& table.getTablePath() != null
193+
&& !TablePath.DEFAULT
194+
.getFullName()
195+
.equals(table.getTablePath().getFullName()));
196+
193197
if (useTableStats) {
194198
TablePath tablePath = table.getTablePath();
195199
String analyzeTable =

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresDialect.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,15 @@ public Long approximateRowCntStatement(Connection connection, JdbcSourceTable ta
155155
// 2. If a query is configured but does not contain a WHERE clause and tablePath is
156156
// configured, use TABLE STATUS.
157157
// 3. If a query is configured with a WHERE clause, or a query statement is configured but
158-
// tablePath is not, use COUNT(*).
158+
// tablePath is TablePath.DEFAULT, use COUNT(*).
159159

160160
boolean useTableStats =
161161
StringUtils.isBlank(table.getQuery())
162162
|| (!table.getQuery().toLowerCase().contains("where")
163-
&& table.getTablePath() != null);
163+
&& table.getTablePath() != null
164+
&& !TablePath.DEFAULT
165+
.getFullName()
166+
.equals(table.getTablePath().getFullName()));
164167
if (useTableStats) {
165168
String rowCountQuery =
166169
String.format(

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ public Long approximateRowCntStatement(Connection connection, JdbcSourceTable ta
165165
// 2. If a query is configured but does not contain a WHERE clause and tablePath is
166166
// configured, use TABLE STATUS.
167167
// 3. If a query is configured with a WHERE clause, or a query statement is configured but
168-
// tablePath is not, use COUNT(*).
168+
// tablePath is TablePath.DEFAULT, use COUNT(*).
169169

170170
boolean useTableStats =
171171
StringUtils.isBlank(table.getQuery())
172172
|| (!table.getQuery().toLowerCase().contains("where")
173-
&& table.getTablePath() != null);
173+
&& table.getTablePath() != null
174+
&& !TablePath.DEFAULT
175+
.getFullName()
176+
.equals(table.getTablePath().getFullName()));
177+
174178
if (useTableStats) {
175179
TablePath tablePath = table.getTablePath();
176180
try (Statement stmt = connection.createStatement()) {

Diff for: seatunnel-e2e/seatunnel-connector-v2-e2e/connector-amazondynamodb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/amazondynamodb/AmazondynamodbIT.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ public class AmazondynamodbIT extends TestSuiteBase implements TestResource {
9494

9595
@TestTemplate
9696
public void testAmazondynamodb(TestContainer container) throws Exception {
97+
assertHasData(SOURCE_TABLE);
9798
Container.ExecResult execResult = container.executeJob(AMAZONDYNAMODB_JOB_CONFIG);
9899
Assertions.assertEquals(0, execResult.getExitCode());
99-
assertHasData();
100+
assertHasData(SOURCE_TABLE);
101+
assertHasData(SINK_TABLE);
100102
compareResult();
101103
clearSinkTable();
102104
}
@@ -168,10 +170,10 @@ private void clearSinkTable() {
168170
createTable(dynamoDbClient, SINK_TABLE);
169171
}
170172

171-
private void assertHasData() {
172-
ScanResponse scan =
173-
dynamoDbClient.scan(ScanRequest.builder().tableName(SINK_TABLE).build());
174-
Assertions.assertTrue(scan.hasItems(), "sink table is empty.");
173+
private void assertHasData(String tableName) {
174+
ScanResponse scan = dynamoDbClient.scan(ScanRequest.builder().tableName(tableName).build());
175+
Assertions.assertTrue(
176+
!scan.items().isEmpty(), String.format("table %s is empty.", tableName));
175177
}
176178

177179
private void compareResult() {

0 commit comments

Comments
 (0)