forked from apache/inlong
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-10729][Sort] Sorstandalone EsSink support transform
- Loading branch information
Showing
14 changed files
with
317 additions
and
22 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
.../transform-sdk/src/main/java/org/apache/inlong/sdk/transform/encode/EsMapSinkEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.inlong.sdk.transform.encode; | ||
|
||
import org.apache.inlong.sdk.transform.pojo.EsMapSinkInfo; | ||
import org.apache.inlong.sdk.transform.pojo.FieldInfo; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.converter.TypeConverter; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
public class EsMapSinkEncoder implements SinkEncoder<Map<String, Object>> { | ||
|
||
private final EsMapSinkInfo sinkInfo; | ||
private final Map<String, TypeConverter> converters; | ||
|
||
public EsMapSinkEncoder(EsMapSinkInfo sinkInfo) { | ||
this.sinkInfo = sinkInfo; | ||
this.converters = sinkInfo.getFields() | ||
.stream() | ||
.collect(Collectors.toMap(FieldInfo::getName, FieldInfo::getConverter)); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> encode(SinkData sinkData, Context context) { | ||
Map<String, Object> esMap = new HashMap<>(); | ||
for (FieldInfo fieldInfo : sinkInfo.getFields()) { | ||
String fieldName = fieldInfo.getName(); | ||
String strValue = sinkData.getField(fieldName); | ||
TypeConverter converter = converters.get(fieldName); | ||
try { | ||
esMap.put(fieldName, converter.convert(strValue)); | ||
} catch (Throwable t) { | ||
log.warn("failed to serialize field ={}, value={}", fieldName, strValue, t); | ||
esMap.put(fieldName, null); | ||
} | ||
} | ||
|
||
return esMap; | ||
} | ||
|
||
@Override | ||
public List<FieldInfo> getFields() { | ||
return sinkInfo.getFields(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...g-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/pojo/EsMapSinkInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.inlong.sdk.transform.pojo; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.commons.collections.CollectionUtils; | ||
|
||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@SuperBuilder | ||
@Data | ||
public class EsMapSinkInfo extends SinkInfo { | ||
|
||
private List<FieldInfo> fields; | ||
|
||
public EsMapSinkInfo( | ||
@JsonProperty("charset") String charset, | ||
@JsonProperty("fields") List<FieldInfo> fields) { | ||
super(SinkInfo.ES_MAP, charset); | ||
if (CollectionUtils.isEmpty(fields)) { | ||
throw new IllegalArgumentException("failed to init es map sink info, fieldInfos is empty"); | ||
} | ||
this.fields = fields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...rm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/converter/TypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.inlong.sdk.transform.process.converter; | ||
|
||
public interface TypeConverter { | ||
|
||
Object convert(String value) throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.