Skip to content

Commit

Permalink
fix(TCOMP-2565): support origin type pass for studio dynamic type (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwang-talend committed Dec 14, 2023
1 parent a266279 commit 367d4af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static java.util.stream.Collectors.toMap;
import static org.talend.sdk.component.api.record.SchemaProperty.ALLOW_SPECIAL_NAME;
import static org.talend.sdk.component.api.record.SchemaProperty.IS_KEY;
import static org.talend.sdk.component.api.record.SchemaProperty.ORIGIN_TYPE;
import static org.talend.sdk.component.api.record.SchemaProperty.PATTERN;
import static org.talend.sdk.component.api.record.SchemaProperty.SCALE;
import static org.talend.sdk.component.api.record.SchemaProperty.SIZE;
Expand Down Expand Up @@ -268,6 +269,11 @@ private DynamicMetadataWrapper generateMetadata(final Entry entry) {
metadata.getDynamicMetadata().setKey(isKey);
metadata.getDynamicMetadata().setType(studioType);

final String originType = entry.getProp(ORIGIN_TYPE);
if (originType != null && !originType.isEmpty()) {
metadata.getDynamicMetadata().setDbType(originType);
}

if (length != null) {
metadata.getDynamicMetadata().setLength(length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.talend.sdk.component.api.record.SchemaProperty.ORIGIN_TYPE;
import static org.talend.sdk.component.api.record.SchemaProperty.STUDIO_TYPE;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -99,6 +98,7 @@ void visit() {
.withName("dynBigDecimal")
.withType(Type.STRING)
.withProp(STUDIO_TYPE, StudioTypes.BIGDECIMAL)
.withProp(ORIGIN_TYPE, "DECIMAL")
.build(), BIGDEC.toString())
.withDecimal(factory.newEntryBuilder()
.withName("dynBigDecimal2")
Expand Down Expand Up @@ -247,6 +247,8 @@ void visit() {
assertTrue(byte[].class.isInstance(dynObject));
assertArrayEquals(String.valueOf(BYTES0).getBytes(), (byte[]) dynObject);

String originType = rowStruct.dynamic.getColumnMetadata(7).getDbType();
assertEquals("DECIMAL", originType);
dynObject = rowStruct.dynamic.getColumnValue("dynBigDecimal");
assertTrue(BigDecimal.class.isInstance(dynObject));
assertEquals(BIGDEC, dynObject);
Expand Down

0 comments on commit 367d4af

Please sign in to comment.