YYChildren opened a new issue, #9578:
URL: https://github.com/apache/seatunnel/issues/9578

   ### Search before asking
   
   - [x] I had searched in the 
[feature](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22Feature%22)
 and found no similar feature requirement.
   
   
   ### Description
   
   I want to Fill Default Value by datatype In Transform.  I write 
DynamicCompile , but the ThreadLocal var can not used! This is my config
   ```hocon
   transform {
       DynamicCompile {
           plugin__input = "source_output"
           plugin_output = "transform_output"
           compile_language="JAVA"
           compile_pattern="SOURCE_CODE"
           source_code="""
               import org.apache.seatunnel.api.table.catalog.*;
               import org.apache.seatunnel.api.table.type.*;
               import java.util.List;
                   public static final ThreadLocal  currentCatalogTable = new 
ThreadLocal();
                   public Column[] getInlineOutputColumns(CatalogTable 
inputCatalogTable) {
                       List columns = 
inputCatalogTable.getTableSchema().getColumns();
                       Column[] result = new Column[columns.size()];
                       for (int i  = 0; i < columns.size(); i++) {
                           result[i] = (Column)columns.get(i);
                       }
                   }
                   public Object[] 
getInlineOutputFieldValues(SeaTunnelRowAccessor inputRow) {
                       int fieldCount = inputRow.getArity();
                       Object[] result = new Object[fieldCount];
                       for (int i = 0; i < fieldCount; i++) {
                           Object value = inputRow..getField(i);
                           if (value == null) {
                               CatalogTable catalogTable = 
(CatalogTable)currentCatalogTable.get();
                               if (catalogTable == null) {
                                   throw new RuntimeException("CatalogTable not 
initialized in current thread");
                               }
                               SeaTunnelDataType dataType = 
catalogTable.getSeaTunnelRowType().getFieldType(i);
                               switch (dataType.getSqlType()) {
                                   case STRING:
                                       result[i] = "";
                                       break;
                                   case BOOLEAN:
                                       result[i] = false;
                                       break;
                                   case TINYINT:
                                       result[i] = (byte) 0;
                                       break;
                                   case SMALLINT:
                                       result[i] =(short) 0;
                                       break;
                                   case INT:
                                       result[i] =   0;
                                       break;
                                   case BIGINT:
                                       result[i] = 0L;
                                       break;
                                   case FLOAT:
                                       result[i] = 0.0f;
                                       break;
                                   case DOUBLE:
                                   case DECIMAL:
                                       result[i] = 0.0d;
                                       break;
                                   case BYTES:
                                       result[i] = new byte[0];
                                       break;
                                   default:
                                       result[i] = null;
                                       break;
                               }
                           } else {
                               result[i] = value;
                           }
                       }
                       return result;
                   }
               """
       }
   }
   ```
   
   
   ### Usage Scenario
   
   _No response_
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to