forked from harbby/sylph
-
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.
- Loading branch information
Showing
8 changed files
with
221 additions
and
84 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
sylph-connectors/sylph-kafka/src/main/java/ideal/sylph/plugins/kafka/KafkaSourceConfig.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,73 @@ | ||
/* | ||
* Copyright (C) 2018 The Sylph Authors | ||
* | ||
* Licensed 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 ideal.sylph.plugins.kafka; | ||
|
||
import ideal.sylph.annotation.Description; | ||
import ideal.sylph.annotation.Name; | ||
import ideal.sylph.etl.PluginConfig; | ||
|
||
public class KafkaSourceConfig | ||
extends PluginConfig | ||
{ | ||
private static final long serialVersionUID = 2L; | ||
|
||
@Name("kafka_topic") | ||
@Description("this is kafka topic list") | ||
private String topics = "test1"; | ||
|
||
@Name("kafka_broker") | ||
@Description("this is kafka broker list") | ||
private String brokers = "localhost:9092"; | ||
|
||
@Name("kafka_group_id") | ||
@Description("this is kafka_group_id") | ||
private String groupid = "sylph_streamSql_test1"; | ||
|
||
@Name("auto.offset.reset") | ||
@Description("this is auto.offset.reset mode") | ||
private String offsetMode = "latest"; | ||
|
||
@Name("value_type") | ||
@Description("this is kafka String value Type, use json") | ||
private String valueType; | ||
|
||
public String getTopics() | ||
{ | ||
return topics; | ||
} | ||
|
||
public String getBrokers() | ||
{ | ||
return brokers; | ||
} | ||
|
||
public String getGroupid() | ||
{ | ||
return groupid; | ||
} | ||
|
||
public String getOffsetMode() | ||
{ | ||
return offsetMode; | ||
} | ||
|
||
public String getValueType() | ||
{ | ||
return valueType; | ||
} | ||
|
||
private KafkaSourceConfig() {} | ||
} |
69 changes: 69 additions & 0 deletions
69
sylph-connectors/sylph-kafka/src/main/java/ideal/sylph/plugins/kafka/flink/JsonSchema.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,69 @@ | ||
/* | ||
* Copyright (C) 2018 The Sylph Authors | ||
* | ||
* Licensed 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 ideal.sylph.plugins.kafka.flink; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import ideal.sylph.etl.SourceContext; | ||
import org.apache.flink.api.common.typeinfo.TypeInformation; | ||
import org.apache.flink.api.java.typeutils.RowTypeInfo; | ||
import org.apache.flink.api.java.typeutils.TypeExtractor; | ||
import org.apache.flink.streaming.util.serialization.KeyedDeserializationSchema; | ||
import org.apache.flink.types.Row; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class JsonSchema | ||
implements KeyedDeserializationSchema<Row> | ||
{ | ||
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
private final RowTypeInfo rowTypeInfo; | ||
|
||
public JsonSchema(SourceContext context) | ||
{ | ||
ideal.sylph.etl.Row.Schema schema = context.getSchema(); | ||
|
||
TypeInformation<?>[] types = schema.getFieldTypes().stream().map(TypeExtractor::createTypeInfo).toArray(TypeInformation<?>[]::new); | ||
String[] names = schema.getFieldNames().toArray(new String[0]); | ||
this.rowTypeInfo = new RowTypeInfo(types, names); | ||
} | ||
|
||
@Override | ||
public Row deserialize(byte[] messageKey, byte[] message, String topic, int partition, long offset) | ||
throws IOException | ||
{ | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> map = MAPPER.readValue(message, Map.class); | ||
String[] names = rowTypeInfo.getFieldNames(); | ||
Row row = new Row(names.length); | ||
for (int i = 0; i < names.length; i++) { | ||
row.setField(i, map.get(names[i])); | ||
} | ||
return row; | ||
} | ||
|
||
@Override | ||
public boolean isEndOfStream(Row nextElement) | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public TypeInformation<Row> getProducedType() | ||
{ | ||
return rowTypeInfo; | ||
} | ||
} |
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
File renamed without changes.
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
26 changes: 26 additions & 0 deletions
26
sylph-etl-api/src/main/java/ideal/sylph/etl/SourceContext.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,26 @@ | ||
/* | ||
* Copyright (C) 2018 The Sylph Authors | ||
* | ||
* Licensed 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 ideal.sylph.etl; | ||
|
||
import java.io.Serializable; | ||
|
||
public interface SourceContext | ||
extends Serializable | ||
{ | ||
public Row.Schema getSchema(); | ||
|
||
public String getSinkTable(); | ||
} |
Oops, something went wrong.