Skip to content

Commit 4611e95

Browse files
committed
modify: create a new object avoid to share SrcFieldSpec
1 parent f594dae commit 4611e95

3 files changed

Lines changed: 34 additions & 29 deletions

File tree

seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/embedding/SrcField.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717

1818
package org.apache.seatunnel.transform.nlpmodel.embedding;
1919

20+
import org.apache.seatunnel.transform.nlpmodel.embedding.multimodal.ModalityType;
21+
2022
import lombok.Data;
23+
import lombok.extern.slf4j.Slf4j;
2124

2225
import java.io.Serializable;
2326
import java.util.Base64;
2427

2528
@Data
29+
@Slf4j
2630
public class SrcField implements Serializable {
2731

2832
private static final long serialVersionUID = 1L;
@@ -32,8 +36,31 @@ public class SrcField implements Serializable {
3236
private Object fieldValue;
3337

3438
public SrcField(SrcFieldSpec spec, Object value) {
35-
this.fieldSpec = spec;
39+
// create a new object avoid to mutate original src field spec
40+
this.fieldSpec =
41+
new SrcFieldSpec(
42+
spec.getFieldName(), spec.getModalityType(), spec.getPayloadFormat());
3643
this.fieldValue = value;
44+
determineModalityType();
45+
}
46+
47+
/**
48+
* Determine the actual modality type based on field spec and value If not binary format,
49+
* analyze the value suffix to determine modality type
50+
*/
51+
private void determineModalityType() {
52+
if (fieldSpec.isBinary()) {
53+
return;
54+
}
55+
if (fieldValue != null) {
56+
String valueStr = fieldValue.toString();
57+
ModalityType detectedType = ModalityType.fromFileSuffix(valueStr);
58+
if (detectedType != null) {
59+
log.debug(
60+
"Auto-detected modality type '{}' from value: {}", detectedType, valueStr);
61+
fieldSpec.setModalityType(detectedType);
62+
}
63+
}
3764
}
3865

3966
public String toBase64() {

seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/embedding/SrcFieldSpec.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public SrcFieldSpec(Map<String, Object> fieldConfig) {
8181
}
8282
}
8383

84+
public SrcFieldSpec(String fieldName, ModalityType modalityType, PayloadFormat payloadFormat) {
85+
this.fieldName = fieldName;
86+
this.modalityType = modalityType;
87+
this.payloadFormat = payloadFormat;
88+
}
89+
8490
public boolean isBinary() {
8591
return PayloadFormat.BINARY.equals(payloadFormat);
8692
}

seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/embedding/multimodal/MultimodalFieldValue.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
package org.apache.seatunnel.transform.nlpmodel.embedding.multimodal;
1919

2020
import org.apache.seatunnel.transform.nlpmodel.embedding.SrcField;
21-
import org.apache.seatunnel.transform.nlpmodel.embedding.SrcFieldSpec;
2221

2322
import lombok.Getter;
24-
import lombok.extern.slf4j.Slf4j;
2523

2624
import java.io.Serializable;
2725
import java.util.List;
2826

29-
@Slf4j
3027
@Getter
3128
public class MultimodalFieldValue implements Serializable {
3229

@@ -36,30 +33,5 @@ public class MultimodalFieldValue implements Serializable {
3633

3734
public MultimodalFieldValue(List<SrcField> srcFields) {
3835
this.srcFields = srcFields;
39-
for (SrcField srcField : srcFields) {
40-
SrcFieldSpec fieldSpec = srcField.getFieldSpec();
41-
ModalityType modalityType = determineModalityType(fieldSpec, srcField.getFieldValue());
42-
fieldSpec.setModalityType(modalityType);
43-
}
44-
}
45-
46-
/**
47-
* Determine the actual modality type based on field spec and value If not binary format,
48-
* analyze the value suffix to determine modality type
49-
*/
50-
private ModalityType determineModalityType(SrcFieldSpec fieldSpec, Object fieldValue) {
51-
if (fieldSpec.isBinary()) {
52-
return fieldSpec.getModalityType();
53-
}
54-
if (fieldValue != null) {
55-
String valueStr = fieldValue.toString();
56-
ModalityType detectedType = ModalityType.fromFileSuffix(valueStr);
57-
if (detectedType != null) {
58-
log.debug(
59-
"Auto-detected modality type '{}' from value: {}", detectedType, valueStr);
60-
return detectedType;
61-
}
62-
}
63-
return fieldSpec.getModalityType();
6436
}
6537
}

0 commit comments

Comments
 (0)