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

Add support of UUID values when encoding avro #971

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -26,10 +26,12 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.UUID;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.EncoderFactory;

public class JdbcAvroRecordConverter {

private final JdbcAvroRecord.SqlFunction<ResultSet, Object>[] mappings;
private final int columnCount;
private final ResultSet resultSet;
Expand Down Expand Up @@ -108,6 +110,8 @@
throws SQLException, IOException {
if (value instanceof String) {
binaryEncoder.writeString((String) value);
} else if (value instanceof UUID) {
binaryEncoder.writeString(value.toString());

Check warning on line 114 in dbeam-core/src/main/java/com/spotify/dbeam/avro/JdbcAvroRecordConverter.java

View check run for this annotation

Codecov / codecov/patch

dbeam-core/src/main/java/com/spotify/dbeam/avro/JdbcAvroRecordConverter.java#L114

Added line #L114 was not covered by tests
} else if (value instanceof Long) {
binaryEncoder.writeLong((Long) value);
} else if (value instanceof Integer) {
Expand All @@ -130,6 +134,8 @@
}

binaryEncoder.writeArrayEnd();
} else {
throw new RuntimeException("Value of type " + value.getClass() + " is not supported");

Check warning on line 138 in dbeam-core/src/main/java/com/spotify/dbeam/avro/JdbcAvroRecordConverter.java

View check run for this annotation

Codecov / codecov/patch

dbeam-core/src/main/java/com/spotify/dbeam/avro/JdbcAvroRecordConverter.java#L138

Added line #L138 was not covered by tests
}
}
}
3 changes: 2 additions & 1 deletion e2e/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ SELECT
random() * (timestamp '2010-01-01 00:00:00' -
timestamp '2020-01-01 00:00:00') AS timestamp2,
E'\\000'::bytea AS bytes_field,
ARRAY['foo', 'bar']::text[] AS arr1
ARRAY['foo', 'bar']::text[] AS arr1,
ARRAY[gen_random_uuid(), gen_random_uuid()]::uuid[] AS arr2
Copy link

@farzad-sedghi farzad-sedghi Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the test(s) failed because of this addition, before the actual fix in the code

FROM
generate_series(1,1000000) a(n)
;
Expand Down