Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Transform-V2] Jsonpath support dest column and delete src field #7982

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,54 +109,46 @@ private static class ColumnParser implements TableSchemaParser.ColumnParser<Read
public List<Column> parse(ReadonlyConfig schemaConfig) {
return schemaConfig.get(TableSchemaOptions.ColumnOptions.COLUMNS).stream()
.map(ReadonlyConfig::fromMap)
.map(
columnConfig -> {
String name =
columnConfig
.getOptional(TableSchemaOptions.ColumnOptions.NAME)
.orElseThrow(
() ->
new IllegalArgumentException(
"schema.columns.* config need option [name], please correct your config first"));
SeaTunnelDataType<?> seaTunnelDataType =
columnConfig
.getOptional(TableSchemaOptions.ColumnOptions.TYPE)
.map(
column ->
SeaTunnelDataTypeConvertorUtil
.deserializeSeaTunnelDataType(
name, column))
.orElseThrow(
() ->
new IllegalArgumentException(
"schema.columns.* config need option [type], please correct your config first"));
.map(ReadonlyConfigParser::parsePhysicalColumn)
.collect(Collectors.toList());
}
}

public static PhysicalColumn parsePhysicalColumn(ReadonlyConfig columnConfig) {
String name =
columnConfig
.getOptional(TableSchemaOptions.ColumnOptions.NAME)
.orElseThrow(
() ->
new IllegalArgumentException(
"schema.columns.* config need option [name], please correct your config first"));
SeaTunnelDataType<?> seaTunnelDataType =
columnConfig
.getOptional(TableSchemaOptions.ColumnOptions.TYPE)
.map(
column ->
SeaTunnelDataTypeConvertorUtil.deserializeSeaTunnelDataType(
name, column))
.orElseThrow(
() ->
new IllegalArgumentException(
"schema.columns.* config need option [type], please correct your config first"));

Integer columnLength =
columnConfig.get(
TableSchemaOptions.ColumnOptions.COLUMN_LENGTH);
Integer columnLength = columnConfig.get(TableSchemaOptions.ColumnOptions.COLUMN_LENGTH);

Integer columnScale =
columnConfig.get(
TableSchemaOptions.ColumnOptions.COLUMN_SCALE);
Integer columnScale = columnConfig.get(TableSchemaOptions.ColumnOptions.COLUMN_SCALE);

Boolean nullable =
columnConfig.get(TableSchemaOptions.ColumnOptions.NULLABLE);
Object defaultValue =
columnConfig.get(
TableSchemaOptions.ColumnOptions.DEFAULT_VALUE);
String comment =
columnConfig.get(TableSchemaOptions.ColumnOptions.COMMENT);
return PhysicalColumn.of(
name,
seaTunnelDataType,
Long.valueOf(columnLength),
columnScale,
nullable,
defaultValue,
comment);
})
.collect(Collectors.toList());
}
Boolean nullable = columnConfig.get(TableSchemaOptions.ColumnOptions.NULLABLE);
Object defaultValue = columnConfig.get(TableSchemaOptions.ColumnOptions.DEFAULT_VALUE);
String comment = columnConfig.get(TableSchemaOptions.ColumnOptions.COMMENT);
return PhysicalColumn.of(
name,
seaTunnelDataType,
Long.valueOf(columnLength),
columnScale,
nullable,
defaultValue,
comment);
}

private static class ConstraintKeyParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -86,8 +87,10 @@ protected TableSchema transformTableSchema() {
builder.primaryKey(inputCatalogTable.getTableSchema().getPrimaryKey().copy());
}
builder.constraintKey(copiedConstraintKeys);
List<String> deletedColumns = getDeletedColumns();
List<Column> columns =
inputCatalogTable.getTableSchema().getColumns().stream()
.filter(c -> !deletedColumns.contains(c.getName()))
.map(Column::copy)
.collect(Collectors.toList());

Expand Down Expand Up @@ -157,4 +160,8 @@ protected TableIdentifier transformTableIdentifier() {
}

protected abstract Column[] getOutputColumns();

protected List<String> getDeletedColumns() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ public class ColumnConfig implements Serializable {
private final String srcField;

private final String destField;
private final boolean deleteSrcField;

private final SeaTunnelDataType<?> destType;
private final ErrorHandleWay errorHandleWay;

public ColumnConfig(
String path,
String srcField,
boolean deleteSrcField,
String destField,
SeaTunnelDataType<?> destType,
ErrorHandleWay errorHandleWay) {
this.path = path;
this.srcField = srcField;
this.deleteSrcField = deleteSrcField;
this.destField = destField;
this.destType = destType;
this.errorHandleWay = errorHandleWay;
}

public boolean isDeleteSrcField() {
return deleteSrcField;
}

public String getPath() {
return path;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.transform.jsonpath;

import org.apache.seatunnel.api.configuration.ReadonlyConfig;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.transform.SeaTunnelTransform;
import org.apache.seatunnel.transform.common.AbstractMultiCatalogSupportTransform;

import java.util.List;
import java.util.Optional;

public class JsonPathMultiCatalogTransform extends AbstractMultiCatalogSupportTransform {

public JsonPathMultiCatalogTransform(
List<CatalogTable> inputCatalogTables, ReadonlyConfig config) {
super(inputCatalogTables, config);
}

@Override
public String getPluginName() {
return JsonPathTransform.PLUGIN_NAME;
}

@Override
protected Optional<SeaTunnelTransform<SeaTunnelRow>> buildTransform(
CatalogTable inputCatalogTable, ReadonlyConfig config) {
return JsonPathTransformConfig.ofOptional(config, inputCatalogTable)
.map(
jsonPathTransformConfig ->
new JsonPathTransform(jsonPathTransformConfig, inputCatalogTable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static org.apache.seatunnel.transform.exception.JsonPathTransformErrorCode.JSON_PATH_COMPILE_ERROR;

Expand Down Expand Up @@ -198,4 +199,12 @@ protected Column[] getOutputColumns() {
}
return columns;
}

@Override
protected List<String> getDeletedColumns() {
return this.config.getColumnConfigs().stream()
.filter(ColumnConfig::isDeleteSrcField)
.map(ColumnConfig::getSrcField)
.collect(Collectors.toList());
}
}
Loading
Loading