-
Notifications
You must be signed in to change notification settings - Fork 56
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
Propagate array item types from SQL to Avro schema #931
Conversation
@@ -74,6 +74,8 @@ public static Schema createSchemaByReadingOneRow( | |||
try (Statement statement = connection.createStatement()) { | |||
final ResultSet resultSet = statement.executeQuery(queryBuilderArgs.sqlQueryWithLimitOne()); | |||
|
|||
resultSet.next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is needed to call resultSet.getArray(i)
. Also it corresponds to the method name
@@ -225,10 +236,12 @@ private static SchemaBuilder.FieldAssembler<Schema> createAvroFields( | |||
} else { | |||
return field.bytesType(); | |||
} | |||
case ARRAY: | |||
return setAvroColumnType(arrayItemType, null, precision, columnClassName, | |||
useLogicalTypes, field.array().items()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you run e2e tests this change will result in:
}, {
"name" : "arr1",
"type" : [ "null", {
"type" : "array",
"items" : "string"
} ],
"doc" : "From sqlType 2003 ARRAY (java.sql.Array)",
"default" : null,
"typeName" : "ARRAY",
"columnClassName" : "java.sql.Array",
"sqlCode" : "2003",
"columnName" : "arr1"
} ],
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #931 +/- ##
============================================
+ Coverage 91.47% 91.65% +0.17%
- Complexity 243 252 +9
============================================
Files 26 26
Lines 927 947 +20
Branches 67 71 +4
============================================
+ Hits 848 868 +20
Misses 52 52
Partials 27 27 |
e2e/e2e.sh
Outdated
time docker run --interactive --rm \ | ||
--net="$DOCKER_NETWORK" \ | ||
--mount="type=bind,source=$PROJECT_PATH/dbeam-core/target,target=/dbeam" \ | ||
$OUTPUT_MOUNT_EXP \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to get test output from container to the local folder. This is how I verified the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
- Note this might be a schema breaking change for exports from ARRAY. I guess that is not too frequent, so it might be fine.
- Consider adding/improving tests to JdbcAvroSchemaTest, JdbcAvroRecordTest. And perhaps adding array type to dbeam-core/src/test/java/com/spotify/dbeam/Coffee.java fixture.
I am not in favor of Beam's approach, because getColumnTypeName does:
but the solution I made doesn't need this at all, because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update the doc here ?
Co-authored-by: Luís Bianchin <[email protected]>
Co-authored-by: Luís Bianchin <[email protected]>
Before the change it generated this:
after the change it generetes:
Checklist for PR author(s)
mvn com.coveo:fmt-maven-plugin:format org.codehaus.mojo:license-maven-plugin:update-file-header
)