-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature][CDC] Support for preferring numeric fields as split keys #5384
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
273bbde
[Feature][CDC] Support for preferring numeric fields as split keys
c108cfe
[Feature][CDC] Support for preferring numeric fields as split keys
fd905b2
[Feature][cdc] Inclusive unique build
975bae7
Merge branch 'apache:dev' into cdc-jdbc
Carl-Zhou-CN 4c433c9
Merge branch 'apache:dev' into cdc-jdbc
Carl-Zhou-CN c6f73ef
[Feature][cdc] UT
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
...nnector-cdc/connector-cdc-base/src/test/java/jdbc/source/JdbcSourceChunkSplitterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jdbc.source; | ||
|
||
import org.apache.seatunnel.api.table.catalog.ConstraintKey; | ||
import org.apache.seatunnel.api.table.catalog.PrimaryKey; | ||
import org.apache.seatunnel.api.table.type.BasicType; | ||
import org.apache.seatunnel.api.table.type.DecimalType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelDataType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelRowType; | ||
import org.apache.seatunnel.connectors.cdc.base.config.JdbcSourceConfig; | ||
import org.apache.seatunnel.connectors.cdc.base.dialect.JdbcDataSourceDialect; | ||
import org.apache.seatunnel.connectors.cdc.base.relational.connection.JdbcConnectionPoolFactory; | ||
import org.apache.seatunnel.connectors.cdc.base.source.enumerator.splitter.AbstractJdbcSourceChunkSplitter; | ||
import org.apache.seatunnel.connectors.cdc.base.source.enumerator.splitter.ChunkSplitter; | ||
import org.apache.seatunnel.connectors.cdc.base.source.reader.external.FetchTask; | ||
import org.apache.seatunnel.connectors.cdc.base.source.reader.external.JdbcSourceFetchTaskContext; | ||
import org.apache.seatunnel.connectors.cdc.base.source.split.SourceSplitBase; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.debezium.jdbc.JdbcConnection; | ||
import io.debezium.relational.Column; | ||
import io.debezium.relational.Table; | ||
import io.debezium.relational.TableId; | ||
import io.debezium.relational.history.TableChanges; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class JdbcSourceChunkSplitterTest { | ||
|
||
@Test | ||
public void splitColumnTest() throws SQLException { | ||
TestJdbcSourceChunkSplitter testJdbcSourceChunkSplitter = | ||
new TestJdbcSourceChunkSplitter(null, new TestSourceDialect()); | ||
Column splitColumn = | ||
testJdbcSourceChunkSplitter.getSplitColumn( | ||
null, new TestSourceDialect(), new TableId("", "", "")); | ||
Assertions.assertEquals(splitColumn.typeName(), "tinyint"); | ||
} | ||
|
||
private class TestJdbcSourceChunkSplitter extends AbstractJdbcSourceChunkSplitter { | ||
|
||
public TestJdbcSourceChunkSplitter( | ||
JdbcSourceConfig sourceConfig, JdbcDataSourceDialect dialect) { | ||
super(sourceConfig, dialect); | ||
} | ||
|
||
@Override | ||
public Object[] queryMinMax(JdbcConnection jdbc, TableId tableId, String columnName) | ||
throws SQLException { | ||
return new Object[0]; | ||
} | ||
|
||
@Override | ||
public Object queryMin( | ||
JdbcConnection jdbc, TableId tableId, String columnName, Object excludedLowerBound) | ||
throws SQLException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object[] sampleDataFromColumn( | ||
JdbcConnection jdbc, TableId tableId, String columnName, int samplingRate) | ||
throws SQLException { | ||
return new Object[0]; | ||
} | ||
|
||
@Override | ||
public Object queryNextChunkMax( | ||
JdbcConnection jdbc, | ||
TableId tableId, | ||
String columnName, | ||
int chunkSize, | ||
Object includedLowerBound) | ||
throws SQLException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Long queryApproximateRowCnt(JdbcConnection jdbc, TableId tableId) | ||
throws SQLException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String buildSplitScanQuery( | ||
TableId tableId, | ||
SeaTunnelRowType splitKeyType, | ||
boolean isFirstSplit, | ||
boolean isLastSplit) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SeaTunnelDataType<?> fromDbzColumn(Column splitColumn) { | ||
String typeName = splitColumn.typeName(); | ||
switch (typeName) { | ||
case "varchar": | ||
return BasicType.STRING_TYPE; | ||
case "tinyint": | ||
return BasicType.BYTE_TYPE; | ||
case "smallint": | ||
return BasicType.SHORT_TYPE; | ||
case "int": | ||
return BasicType.INT_TYPE; | ||
case "bigint": | ||
return BasicType.LONG_TYPE; | ||
case "decimal": | ||
return new DecimalType(20, 0); | ||
default: | ||
return BasicType.STRING_TYPE; | ||
} | ||
} | ||
|
||
@Override | ||
public Column getSplitColumn( | ||
JdbcConnection jdbc, JdbcDataSourceDialect dialect, TableId tableId) | ||
throws SQLException { | ||
return super.getSplitColumn(jdbc, dialect, tableId); | ||
} | ||
} | ||
|
||
private class TestSourceDialect implements JdbcDataSourceDialect { | ||
|
||
@Override | ||
public String getName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isDataCollectionIdCaseSensitive(JdbcSourceConfig sourceConfig) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ChunkSplitter createChunkSplitter(JdbcSourceConfig sourceConfig) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<TableId> discoverDataCollections(JdbcSourceConfig sourceConfig) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public JdbcConnectionPoolFactory getPooledDataSourceFactory() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public TableChanges.TableChange queryTableSchema(JdbcConnection jdbc, TableId tableId) { | ||
|
||
Table table = | ||
Table.editor() | ||
.tableId(tableId) | ||
.addColumns( | ||
Column.editor() | ||
.name("string_col") | ||
.jdbcType(Types.VARCHAR) | ||
.type("varchar") | ||
.create(), | ||
Column.editor() | ||
.name("smallint") | ||
.jdbcType(Types.SMALLINT) | ||
.type("smallint") | ||
.create(), | ||
Column.editor() | ||
.name("int") | ||
.jdbcType(Types.INTEGER) | ||
.type("int") | ||
.create(), | ||
Column.editor() | ||
.name("decimal") | ||
.jdbcType(Types.DECIMAL) | ||
.type("decimal") | ||
.create(), | ||
Column.editor() | ||
.name("tinyint_col") | ||
.jdbcType(Types.TINYINT) | ||
.type("tinyint") | ||
.create(), | ||
Column.editor() | ||
.name("bigint_col") | ||
.jdbcType(Types.BIGINT) | ||
.type("bigint") | ||
.create()) | ||
.create(); | ||
return new TableChanges.TableChange(TableChanges.TableChangeType.CREATE, table); | ||
} | ||
|
||
@Override | ||
public FetchTask<SourceSplitBase> createFetchTask(SourceSplitBase sourceSplitBase) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public JdbcSourceFetchTaskContext createFetchTaskContext( | ||
SourceSplitBase sourceSplitBase, JdbcSourceConfig taskSourceConfig) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Optional<PrimaryKey> getPrimaryKey(JdbcConnection jdbcConnection, TableId tableId) | ||
throws SQLException { | ||
return Optional.of( | ||
PrimaryKey.of( | ||
"pkName", | ||
Arrays.asList( | ||
"string_col", | ||
"smallint", | ||
"int", | ||
"decimal", | ||
"tinyint_col", | ||
"bigint_col"))); | ||
} | ||
|
||
@Override | ||
public List<ConstraintKey> getUniqueKeys(JdbcConnection jdbcConnection, TableId tableId) | ||
throws SQLException { | ||
return new ArrayList<ConstraintKey>(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use junit 5.9.0 define in root pom.xml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, a large number of tests are used for this version