Skip to content

Commit

Permalink
[cdc] Add more checker for the timestamp type. (#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
MOBIN-F authored May 13, 2024
1 parent fa43a67 commit 3a7d030
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public abstract class UpdatedDataFieldsProcessFunctionBase<I, O> extends Process

private static final List<DataTypeRoot> DECIMAL_TYPES = Arrays.asList(DataTypeRoot.DECIMAL);

private static final List<DataTypeRoot> TIMESTAMP_TYPES =
Arrays.asList(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE);

protected UpdatedDataFieldsProcessFunctionBase(Catalog.Loader catalogLoader) {
this.catalogLoader = catalogLoader;
}
Expand Down Expand Up @@ -174,6 +177,14 @@ public static ConvertAction canConvert(DataType oldType, DataType newType) {
: ConvertAction.CONVERT;
}

oldIdx = TIMESTAMP_TYPES.indexOf(oldType.getTypeRoot());
newIdx = TIMESTAMP_TYPES.indexOf(newType.getTypeRoot());
if (oldIdx >= 0 && newIdx >= 0) {
return DataTypeChecks.getPrecision(oldType) <= DataTypeChecks.getPrecision(newType)
? ConvertAction.CONVERT
: ConvertAction.IGNORE;
}

return ConvertAction.EXCEPTION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.paimon.types.DecimalType;
import org.apache.paimon.types.IntType;
import org.apache.paimon.types.SmallIntType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.types.VarCharType;

import org.junit.Assert;
Expand Down Expand Up @@ -79,4 +80,22 @@ public void testCanConvertDecimal() {
Assert.assertEquals(
UpdatedDataFieldsProcessFunctionBase.ConvertAction.IGNORE, convertAction);
}

@Test
public void testCanConvertTimestamp() {
TimestampType oldType = new TimestampType(true, 3);
TimestampType biggerLengthTimestamp = new TimestampType(true, 5);
TimestampType smallerLengthTimestamp = new TimestampType(true, 2);

UpdatedDataFieldsProcessFunctionBase.ConvertAction convertAction = null;
convertAction =
UpdatedDataFieldsProcessFunctionBase.canConvert(oldType, biggerLengthTimestamp);
Assert.assertEquals(
UpdatedDataFieldsProcessFunctionBase.ConvertAction.CONVERT, convertAction);
convertAction =
UpdatedDataFieldsProcessFunctionBase.canConvert(oldType, smallerLengthTimestamp);

Assert.assertEquals(
UpdatedDataFieldsProcessFunctionBase.ConvertAction.IGNORE, convertAction);
}
}

0 comments on commit 3a7d030

Please sign in to comment.