-
Notifications
You must be signed in to change notification settings - Fork 1
SinkWriter implementation of String data type #22
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
608b071
SinkWriter implementation of String data type
mzitnik 5d3c8ce
Added db to sql when creating or dropping table.
mzitnik ab73284
Clean up code & add handleFailedRequest method
mzitnik 9d641d9
Adding scala tests
mzitnik c160c68
Split tests to workflow for Java & Scala
mzitnik 97a0fe4
Adding POJO support
mzitnik f5d286e
Update Jave client version.
mzitnik 94a85db
Fix SimplePOJO content to avoid dedup
mzitnik ed92b0a
Remove System.out
mzitnik 1adbe84
Update flink-connector-clickhouse-base/src/test/java/org/apache/flink…
mzitnik 6bdbf0b
Fix copilot suggestions
mzitnik e0f61b3
Merge branch 'implement-sink-writer-api' of github.com:ClickHouse/fli…
mzitnik 11faf34
Added a few metrics & started to implement retry logic
mzitnik 7875a71
Remove remarked import
mzitnik 2bb4e81
remove uneeded code from writePrimitiveValuePreamble
mzitnik 4fc155b
Added logging to writeValuePreamble
mzitnik 4dda9ca
Add logging & ignore if payload is null before sending
mzitnik b7058cd
Added logging to convertToInteger
mzitnik 02e4aa7
Remove System.out...
mzitnik c17bb06
Remove join from logic
mzitnik a77846e
Added some enhancements to ClickHouseAsyncSinkSerializer
mzitnik bea0ec6
Address comments
mzitnik 35202ac
Added serialVersionUID to ClickHousePayload
mzitnik 1716d05
Fixing version nammeing in github action
mzitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,40 @@ | ||
| name: Apache Flink ClickHouse Connector Tests CI (Scala) | ||
|
|
||
| on: [push] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| clickhouse: [ "23.7", "24.3", "latest", "cloud" ] | ||
| name: Apache Flink ClickHouse Connector tests with ClickHouse ${{ matrix.clickhouse }} | ||
| steps: | ||
| - name: Check for Cloud Credentials | ||
| id: check-cloud-credentials | ||
| run: | | ||
| if [[ "${{ matrix.clickhouse }}" == "cloud" && (-z "${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT }}" || -z "${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT }}") ]]; then | ||
| echo "SKIP_STEP=true" >> $GITHUB_ENV | ||
| else | ||
| echo "SKIP_STEP=false" >> $GITHUB_ENV | ||
| fi | ||
| shell: bash | ||
| - uses: actions/checkout@v3 | ||
| if: env.SKIP_STEP != 'true' | ||
| - name: Set up JDK 21 | ||
| if: env.SKIP_STEP != 'true' | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'adopt' | ||
| architecture: x64 | ||
| - name: Setup and execute Gradle 'runScalaTests' task | ||
| if: env.SKIP_STEP != 'true' | ||
| uses: gradle/gradle-build-action@v2 | ||
| env: | ||
| CLICKHOUSE_VERSION: ${{ matrix.clickhouse }} | ||
| CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT }} | ||
| CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT }} | ||
| with: | ||
| arguments: runScalaTests | ||
This file contains hidden or 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 hidden or 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
183 changes: 183 additions & 0 deletions
183
flink-connector-clickhouse-base/src/main/java/com/clickhouse/utils/Serialize.java
This file contains hidden or 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,183 @@ | ||
| package com.clickhouse.utils; | ||
|
|
||
| import com.clickhouse.client.api.data_formats.internal.SerializerUtils; | ||
| import com.clickhouse.data.ClickHouseDataType; | ||
| import com.clickhouse.data.format.BinaryStreamUtils; | ||
| import org.jline.utils.Log; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.lang.reflect.Method; | ||
| import java.time.LocalDate; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class Serialize { | ||
|
|
||
| public static boolean writePrimitiveValuePreamble(OutputStream out, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| // since it is primitive we always have a value that is not null | ||
| if (defaultsSupport) { | ||
| // Add indicator since the table has default values | ||
| SerializerUtils.writeNonNull(out); | ||
| } | ||
| // if the column is Nullable need to add an indicator for nullable | ||
| if (isNullable) { | ||
| SerializerUtils.writeNonNull(out); | ||
| } | ||
| return true; | ||
| } | ||
| public static boolean writeValuePreamble(OutputStream out, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column, Object value) throws IOException { | ||
| Log.debug("writeValuePreamble[defaultsSupport='%s', isNullable='%s', dataType='%s', column='%s', value='%s']"); | ||
| if (defaultsSupport) { | ||
| if (value != null) { | ||
| SerializerUtils.writeNonNull(out); | ||
| if (isNullable) { | ||
| SerializerUtils.writeNonNull(out); | ||
| } | ||
| } else { | ||
| if (hasDefault) { | ||
| SerializerUtils.writeNull(out); | ||
| return false; | ||
| } | ||
|
|
||
| if (isNullable) { | ||
| SerializerUtils.writeNonNull(out); | ||
| SerializerUtils.writeNull(out); | ||
| return false; | ||
| } | ||
|
|
||
| if (dataType == ClickHouseDataType.Array) { | ||
| SerializerUtils.writeNonNull(out); | ||
| } else if (dataType != ClickHouseDataType.Dynamic) { | ||
| throw new IllegalArgumentException(String.format("An attempt to write null into not nullable column '%s' of type '%s'", column, dataType)); | ||
| } | ||
| } | ||
| } else if (isNullable) { | ||
| if (value == null) { | ||
| SerializerUtils.writeNull(out); | ||
| return false; | ||
| } | ||
|
|
||
| SerializerUtils.writeNonNull(out); | ||
| } else if (value == null) { | ||
| if (dataType == ClickHouseDataType.Array) { | ||
| SerializerUtils.writeNonNull(out); | ||
| } else if (dataType != ClickHouseDataType.Dynamic) { | ||
| throw new IllegalArgumentException(String.format("An attempt to write null into not nullable column '%s' of type '%s'", column, dataType)); | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public static String convertToString(Object value) { | ||
| return java.lang.String.valueOf(value); | ||
| } | ||
|
|
||
| public static Integer convertToInteger(Object value) { | ||
| if (value instanceof Integer) { | ||
| return (Integer) value; | ||
| } else if (value instanceof Number) { | ||
| return ((Number) value).intValue(); | ||
| } else if (value instanceof String) { | ||
| return Integer.parseInt((String) value); | ||
| } else if (value instanceof Boolean) { | ||
| return ((Boolean) value) ? 1 : 0; | ||
| } else { | ||
| throw new IllegalArgumentException("Cannot convert object of type " + | ||
| value.getClass().getName() + " to Integer: " + value); | ||
| } | ||
| } | ||
|
|
||
| public static Map<ClickHouseDataType, Method> mapClickHouseTypeToMethod() { | ||
| Map<ClickHouseDataType, Method> map = new HashMap<>(); | ||
| for (Method method : Serialize.class.getMethods()) { | ||
| String name = method.getName(); | ||
| if (name.startsWith("write")) { | ||
| String chType = name.substring("write".length()); | ||
| try { | ||
| ClickHouseDataType type = ClickHouseDataType.valueOf(chType); | ||
| map.put(type, method); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
|
|
||
| // Method structure write[ClickHouse Type](OutputStream, Java type, ... ) | ||
| // Date support | ||
| public static void writeDate(OutputStream out, LocalDate value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| SerializerUtils.writeDate(out, value, ZoneId.of("UTC")); // TODO: check | ||
| } | ||
| } | ||
|
|
||
| public static void writeDate(OutputStream out, ZonedDateTime value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| SerializerUtils.writeDate(out, value, ZoneId.of("UTC")); // TODO: check | ||
| } | ||
| } | ||
|
|
||
| // clickhouse type String support | ||
| public static void writeString(OutputStream out, String value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeString(out, convertToString(value)); | ||
| } | ||
| } | ||
|
|
||
| public static void writeFixedString(OutputStream out, String value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, int size, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeFixedString(out, convertToString(value), size); | ||
| } | ||
| } | ||
|
|
||
| // Int8 | ||
| public static void writeInt8(OutputStream out, Byte value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
mzitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeInt8(out, convertToInteger(value)); | ||
| } | ||
| } | ||
|
|
||
| // Int16 | ||
| public static void writeInt16(OutputStream out, Short value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeInt16(out, convertToInteger(value)); | ||
| } | ||
| } | ||
|
|
||
| // Int32 | ||
| public static void writeInt32(OutputStream out, Integer value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeInt32(out, convertToInteger(value)); | ||
| } | ||
| } | ||
|
|
||
| // Int64 | ||
| public static void writeInt64(OutputStream out, Long value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeInt64(out, convertToInteger(value)); | ||
| } | ||
| } | ||
|
|
||
| // Float32 | ||
| public static void writeFloat32(OutputStream out, Float value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeFloat32(out, value); | ||
| } | ||
| } | ||
|
|
||
| // Float64 | ||
| public static void writeFloat64(OutputStream out, Double value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException { | ||
| if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) { | ||
| BinaryStreamUtils.writeFloat64(out, value); | ||
| } | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.