Prerequisites

  • JDK 1.8 or above
  • Maven 2.5 or above

Installing SDK Dependencies

You need to include the SDK library in your project to use the SDK. The library can be obtained in the following two ways:

  • Obtain the source code, compile it yourself, and deploy the SDK package to the local repository. See How to Compile for details.
  • Directly reference the existing library in the Apache repository. xml
  1. <dependency>
  2. <groupId>org.apache.inlong</groupId>
  3. <artifactId>transform-sdk</artifactId>
  4. <version>1.13.0</version>
  5. </dependency>

Specific Examples

Transform Requirements

  • Filter out the video playback start data in the Shenzhen region, the original fields include:
    • event_time
    • zone, optional values: [ shenzhen, shanghai, beijing ]
    • video_id
    • username
    • operation_type, optional values [ start, end ]
  • Original test data, CSV format, vertical bar delimited.
  1. 2024-05-09 20:00:01|shenzhen|1111|zhangsan|start
  2. 2024-05-09 20:00:02|shanghai|1111|lisi|start
  3. 2024-05-09 20:00:03|shanghai|1111|lisi|end
  4. 2024-05-09 20:00:04|shenzhen|1111|zhangsan|end
  5. 2024-05-09 20:00:05|beijing|1111|zhangsan|start
  6. 2024-05-09 20:00:06|beijing|1111|zhangsan|end
  • Expected result data, KV format
  1. event_time=2024-05-09 20:00:02&zone=shanghai&video_id=1111&username=lisi&operation_type=start

Transform SDK Implementation

Configure Source Data Configuration

  1. // source
  2. SourceInfo csvSource = new CsvSourceInfo("UTF-8", "|", "\\", null);

Configure Result Data Configuration

  1. // sink
  2. SinkInfo kvSink = new KvSinkInfo("UTF-8", null);

Execute Transformation Logic

  1. String transformSql = "select $1 event_time,$2 zone,$3 video_id,$4 username,$5 operation_type from source where $2='shenzhen' and $5='start' ";
  2. TransformConfig config = new TransformConfig(csvSource, kvSink, transformSql);

Build SDK Object and Execute Transformation

  1. TransformProcessor processor = new TransformProcessor(config);
  2. String srcString = "2024-05-09 20:00:01|shenzhen|1111|zhangsan|start\n"
  3. + "2024-05-09 20:00:02|shanghai|1111|lisi|start\n"
  4. + "2024-05-09 20:00:03|shanghai|1111|lisi|end\n"
  5. + "2024-05-09 20:00:04|shenzhen|1111|zhangsan|end\n"
  6. + "2024-05-09 20:00:05|beijing|1111|zhangsan|start\n"
  7. + "2024-05-09 20:00:06|beijing|1111|zhangsan|end";
  8. List<String> outputs = processor.transform("2024-04-28 00:00:00|ok", new HashMap<>());
  9. // Expected outcome:[event_time=2024-05-09 20:00:02&zone=shanghai&video_id=1111&username=lisi&operation_type=start]
  10. System.out.println(outputs);

More Transform Examples