hailin0 commented on code in PR #7524:
URL: https://github.com/apache/seatunnel/pull/7524#discussion_r1746849125
##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/JsonPathTransformFactoryTest.java:
##########
@@ -16,15 +16,217 @@
*/
package org.apache.seatunnel.transform;
-import org.apache.seatunnel.transform.jsonpath.JsonPathTransformFactory;
+import org.apache.seatunnel.shade.com.google.common.collect.ImmutableMap;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.CatalogTableUtil;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.transform.common.CommonOptions;
+import org.apache.seatunnel.transform.common.ErrorHandleWay;
+import org.apache.seatunnel.transform.jsonpath.JsonPathTransform;
+import org.apache.seatunnel.transform.jsonpath.JsonPathTransformConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
public class JsonPathTransformFactoryTest {
+
+ @Test
+ public void testJsonPath() {
+ Map<String, Object> configMap = new HashMap<>();
+ configMap.put(
+ JsonPathTransformConfig.COLUMNS.key(),
+ Arrays.asList(
+ ImmutableMap.of(
+ JsonPathTransformConfig.SRC_FIELD.key(),
"data",
+ JsonPathTransformConfig.PATH.key(), "$.f1",
+ JsonPathTransformConfig.DEST_FIELD.key(),
"f1")));
+ ReadonlyConfig config = ReadonlyConfig.fromMap(configMap);
+ CatalogTable table =
+ CatalogTableUtil.getCatalogTable(
+ "test",
+ new SeaTunnelRowType(
+ new String[] {"data"},
+ new SeaTunnelDataType[]
{BasicType.STRING_TYPE}));
+ JsonPathTransform transform =
+ new JsonPathTransform(JsonPathTransformConfig.of(config),
table);
+
+ CatalogTable outputTable = transform.getProducedCatalogTable();
+ SeaTunnelRow outputRow = transform.map(new SeaTunnelRow(new Object[]
{"{\"f1\": 1}"}));
+ Assertions.assertEquals(
+ "1",
outputRow.getField(outputTable.getSeaTunnelRowType().indexOf("f1")));
+ }
+
@Test
- public void testOptionRule() {
- JsonPathTransformFactory jsonPathTransformFactory = new
JsonPathTransformFactory();
- Assertions.assertNotNull(jsonPathTransformFactory.optionRule());
+ public void testErrorHandleWay() {
+ Map<String, Object> configMap = new HashMap<>();
+ configMap.put(
+ JsonPathTransformConfig.COLUMNS.key(),
+ Arrays.asList(
+ ImmutableMap.of(
+ JsonPathTransformConfig.SRC_FIELD.key(),
"data",
+ JsonPathTransformConfig.PATH.key(), "$.f1",
+ JsonPathTransformConfig.DEST_FIELD.key(),
"f1")));
+ ReadonlyConfig config = ReadonlyConfig.fromMap(configMap);
+ CatalogTable table =
+ CatalogTableUtil.getCatalogTable(
+ "test",
+ new SeaTunnelRowType(
+ new String[] {"data"},
+ new SeaTunnelDataType[]
{BasicType.STRING_TYPE}));
+ JsonPathTransform transform =
+ new JsonPathTransform(JsonPathTransformConfig.of(config),
table);
+
+ CatalogTable outputTable = transform.getProducedCatalogTable();
+ SeaTunnelRow outputRow;
+ try {
+ outputRow = transform.map(new SeaTunnelRow(new Object[] {"{\"f2\":
1}"}));
+ Assertions.fail("should throw exception");
+ } catch (Exception e) {
+ // ignore
+ }
Review Comment:
fixed
--
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]