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

[Bug]: After JDBCIO read withRowOutput(), the VARCHAR/TEXT -> LOGICAL_TYPE and not compatible with SqlTypeName #23747

Closed
haoyuche opened this issue Oct 20, 2022 · 8 comments · Fixed by #23891

Comments

@haoyuche
Copy link

haoyuche commented Oct 20, 2022

What happened?

    PCollection<Row> rows = pipeline.apply(JdbcIO.<Row>readWithPartitions()
            .withDataSourceConfiguration(JdbcIO.DataSourceConfiguration.create(
                    input.driverClassName, input.url)
                    .withUsername(input.username)
                    .withPassword(input.password))
            .withTable(input.tableName)
            .withPartitionColumn(input.primeKeyForPartitionRead)
            .withRowOutput());

Now there is a column named "name" which is VARCHAR, which has been read as beam type LOGICAL_TYPE NOT NULL.

Then I do

        Schema schemaAfterSql = Schema.builder().addNullableField("id", Schema.FieldType.INT64).addNullableField("name", Schema.FieldType.String).build();
        String selectQuery = "SELECT id, name FROM PCOLLECTION" ;
        PCollection<Row> processedRows = rows.apply("EnforcePolicy", SqlTransform.query(selectQuery)).setRowSchema(schemaAfterSql);

It gets "An exception occured while executing the Java class. Unable to parse query SELECT id, policy_name FROM PCOLLECTION: java.lang.IllegalArgumentException: Cannot find a matching Calcite SqlTypeName for Beam type: LOGICAL_TYPE NOT NULL"

Issue Priority

Priority: 0

Issue Component

Component: io-java-jdbc

@Abacn
Copy link
Contributor

Abacn commented Oct 24, 2022

Thanks for reporting this. It looks like the cause is CalciteUtil here:


does not consider the logical type FieldType.

@Abacn
Copy link
Contributor

Abacn commented Oct 24, 2022

.remove-label P0, "awaiting triage"

.add_label P2

@Abacn
Copy link
Contributor

Abacn commented Oct 24, 2022

.remove-labels P0, "awaiting triage"

.set_labels P2

@Abacn
Copy link
Contributor

Abacn commented Oct 24, 2022

.remove-labels 'awaiting triage'

@github-actions
Copy link
Contributor

Label cannot be managed because it does not exist in the repo. Please check your spelling.

@haoyuche
Copy link
Author

haoyuche commented Oct 24, 2022

Yes, I think somehow we should not feed LOGICAL_TYPE to CalciteUtils but instead we should feed the BaseT so that it can handle the normal sql types. So the fix should be within apache/beam/tree/master/sdks/java/extensions/sql/jdbc when parsing the sql query.

@Abacn
Copy link
Contributor

Abacn commented Oct 29, 2022

.take-issue

apilloud added a commit that referenced this issue Oct 31, 2022
@github-actions github-actions bot added this to the 2.44.0 Release milestone Oct 31, 2022
@haoyuche
Copy link
Author

Thanks Andrew for fixing this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants