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

Translate vector-type fields properly in DDlogJooqProvider #1089

Merged
merged 2 commits into from
Sep 28, 2021

Conversation

amytai
Copy link
Contributor

@amytai amytai commented Sep 26, 2021

Signed-off-by: Amy Tai amy.tai.2009@gmail.com

Previously, vector-type columns (i.e. ARRAY_AGG) would not get properly handled by the DDlogJooqProvider during writeback (DDlogJooqProvider::onChange), because the Jooq H2 backend stores the type of array columns as Object.class. Instead, in the writeback function, we infer the type of the column from the DDlog record, which should have all typing informaiton.

Signed-off-by: Amy Tai <amy.tai.2009@gmail.com>
throw new DDlogJooqProviderException("Unknown datatype " + field);
// Return a value based on the DDlog type of the record
private static Object ddlogRecordToObject(final Field<?> field, final DDlogRecord in) {
if (in.isBool()) {

Choose a reason for hiding this comment

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

How about adding a 'debug' flag which will cause the code to assert that the SQL type matches as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, for the simple types. For compound types (such as vector/array), the SQL type simply shows up as Object, which is the entire reason for this PR.

return in.getFloat();
} else if (in.isString()) {
return in.getString();
} else if (in.isStruct()) {

Choose a reason for hiding this comment

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

how come that the original code didn't have this path?
were there no nulls so far in the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Previously, nulls were checked for outside this function (see DDlogJooqProvider::structToValue, which calls this function after inspecting for struct).

This path is more robust in the case of nested types, so I've removed structToValue and replaced it with setValue.

sql/src/test/java/ddlog/JooqProviderTestBase.java Outdated Show resolved Hide resolved
public void testArrayAggTypes() {
assert(create != null);
create.execute("insert into \nhosts values ('n1', 10, true)");
create.batch("insert into hosts values ('n54', 18, false)",

Choose a reason for hiding this comment

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

none of your tests has an array with more than 1 element, or with a null element.
is it possible to add these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added both types of array results.

Signed-off-by: Amy Tai <amy.tai.2009@gmail.com>
@mihaibudiu mihaibudiu merged commit decfd1d into vmware:master Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants