forked from apache/flink
-
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.
[FLINK-18202][protobuf] Introduce protobuf format
This closes apache#14376
- Loading branch information
1 parent
9d0573b
commit dc6dcee
Showing
75 changed files
with
5,655 additions
and
0 deletions.
There are no files selected for viewing
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,146 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-formats</artifactId> | ||
<version>1.16-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>flink-protobuf</artifactId> | ||
<name>Flink : Formats : Protobuf</name> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<!-- the same with flink-table/pom.xml --> | ||
<janino.version>3.0.11</janino.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- core dependencies --> | ||
|
||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-core</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-table-common</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>${protoc.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.codehaus.janino</groupId> | ||
<artifactId>janino</artifactId> | ||
<!-- this should be the same version of flink-table module --> | ||
<version>${janino.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-table-planner_${scala.binary.version}</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-table-planner_${scala.binary.version}</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
|
||
<!-- test utils dependency --> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-test-utils</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.os72</groupId> | ||
<artifactId>protoc-jar-maven-plugin</artifactId> | ||
<version>3.11.4</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<protocVersion>${protoc.version}</protocVersion> | ||
<inputDirectories> | ||
<include>src/test/proto</include> | ||
</inputDirectories> | ||
<outputTargets> | ||
<outputTarget> | ||
<type>java</type> | ||
<addSources>none</addSources> | ||
<outputDirectory>target/test-proto-sources</outputDirectory> | ||
</outputTarget> | ||
</outputTargets> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-test-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>target/test-proto-sources</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
27 changes: 27 additions & 0 deletions
27
flink-formats/flink-protobuf/src/main/java/com/google/protobuf/ProtobufInternalUtils.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,27 @@ | ||
/* | ||
* 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 com.google.protobuf; | ||
|
||
/** This class is to access internal method in protobuf package. */ | ||
public class ProtobufInternalUtils { | ||
/** convert underscore name to camel name. */ | ||
public static String underScoreToCamelCase(String name, boolean capNext) { | ||
return SchemaUtil.toCamelCase(name, capNext); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ts/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/PbCodegenException.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,36 @@ | ||
/* | ||
* 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.flink.formats.protobuf; | ||
|
||
/** Exception represents codegen error in row and proto conversion which is probably a bug. */ | ||
public class PbCodegenException extends Exception { | ||
public PbCodegenException() {} | ||
|
||
public PbCodegenException(String message) { | ||
super(message); | ||
} | ||
|
||
public PbCodegenException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public PbCodegenException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/PbConstant.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,29 @@ | ||
/* | ||
* 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.flink.formats.protobuf; | ||
|
||
/** Keeps protobuf constants separately. */ | ||
public class PbConstant { | ||
public static final String PB_METHOD_GET_DESCRIPTOR = "getDescriptor"; | ||
public static final String PB_METHOD_PARSE_FROM = "parseFrom"; | ||
public static final String GENERATED_DECODE_METHOD = "decode"; | ||
public static final String GENERATED_ENCODE_METHOD = "encode"; | ||
public static final String PB_MAP_KEY_NAME = "key"; | ||
public static final String PB_MAP_VALUE_NAME = "value"; | ||
} |
52 changes: 52 additions & 0 deletions
52
...mats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/PbDecodingFormat.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,52 @@ | ||
/* | ||
* 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.flink.formats.protobuf; | ||
|
||
import org.apache.flink.api.common.serialization.DeserializationSchema; | ||
import org.apache.flink.api.common.typeinfo.TypeInformation; | ||
import org.apache.flink.formats.protobuf.deserialize.PbRowDataDeserializationSchema; | ||
import org.apache.flink.table.connector.ChangelogMode; | ||
import org.apache.flink.table.connector.format.DecodingFormat; | ||
import org.apache.flink.table.connector.source.DynamicTableSource; | ||
import org.apache.flink.table.data.RowData; | ||
import org.apache.flink.table.types.DataType; | ||
import org.apache.flink.table.types.logical.RowType; | ||
|
||
/** {@link DecodingFormat} for protobuf decoding. */ | ||
public class PbDecodingFormat implements DecodingFormat<DeserializationSchema<RowData>> { | ||
private final PbFormatConfig formatConfig; | ||
|
||
public PbDecodingFormat(PbFormatConfig formatConfig) { | ||
this.formatConfig = formatConfig; | ||
} | ||
|
||
@Override | ||
public DeserializationSchema<RowData> createRuntimeDecoder( | ||
DynamicTableSource.Context context, DataType producedDataType) { | ||
final RowType rowType = (RowType) producedDataType.getLogicalType(); | ||
final TypeInformation<RowData> rowDataTypeInfo = | ||
context.createTypeInformation(producedDataType); | ||
return new PbRowDataDeserializationSchema(rowType, rowDataTypeInfo, formatConfig); | ||
} | ||
|
||
@Override | ||
public ChangelogMode getChangelogMode() { | ||
return ChangelogMode.insertOnly(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...mats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/PbEncodingFormat.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,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.flink.formats.protobuf; | ||
|
||
import org.apache.flink.api.common.serialization.SerializationSchema; | ||
import org.apache.flink.formats.protobuf.serialize.PbRowDataSerializationSchema; | ||
import org.apache.flink.table.connector.ChangelogMode; | ||
import org.apache.flink.table.connector.format.EncodingFormat; | ||
import org.apache.flink.table.connector.sink.DynamicTableSink; | ||
import org.apache.flink.table.data.RowData; | ||
import org.apache.flink.table.types.DataType; | ||
import org.apache.flink.table.types.logical.RowType; | ||
|
||
/** {@link EncodingFormat} for protobuf encoding. */ | ||
public class PbEncodingFormat implements EncodingFormat<SerializationSchema<RowData>> { | ||
private final PbFormatConfig pbFormatConfig; | ||
|
||
public PbEncodingFormat(PbFormatConfig pbFormatConfig) { | ||
this.pbFormatConfig = pbFormatConfig; | ||
} | ||
|
||
@Override | ||
public ChangelogMode getChangelogMode() { | ||
return ChangelogMode.insertOnly(); | ||
} | ||
|
||
@Override | ||
public SerializationSchema<RowData> createRuntimeEncoder( | ||
DynamicTableSink.Context context, DataType consumedDataType) { | ||
RowType rowType = (RowType) consumedDataType.getLogicalType(); | ||
return new PbRowDataSerializationSchema(rowType, pbFormatConfig); | ||
} | ||
} |
Oops, something went wrong.