Skip to content

[BigQueryIO] support MicrosInstant type (for xlang) #34707

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 1 commit into from
Apr 22, 2025

Conversation

ahmedabu98
Copy link
Contributor

tl;dr just adding some missing logic to support converting BQ timestamp type --> Java logical timestamp type --> Python timestamp type

We have some existing Schema translation between Python and Java SDKs for Timestamps. A Python Timestamp maps to a Java MicrosInstant (aka SqlTypes.TIMESTAMP)

Writing timestamps to BQ Storage Write API with the Python SDK works fine, but when a row fails and we try converting the BQ type back to a MicrosInstant, we get the following error:

java.lang.UnsupportedOperationException: Converting BigQuery type 'class java.lang.String' to 'LOGICAL_TYPE<beam:logical_type:micros_instant:v1> NOT NULL' is not supported
	at org.apache.beam.sdk.io.gcp.bigquery.BigQueryUtils.toBeamValue(BigQueryUtils.java:802)
	at org.apache.beam.sdk.io.gcp.bigquery.BigQueryUtils.lambda$toBeamRow$6(BigQueryUtils.java:693)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Collections$2.tryAdvance(Collections.java:5073)
	at java.base/java.util.Collections$2.forEachRemaining(Collections.java:5081)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.apache.beam.sdk.io.gcp.bigquery.BigQueryUtils.toBeamRow(BigQueryUtils.java:694)

We're just missing some logic that accounts for when we want to convert a BQ timestamp to a MicrosInstant. I believe this was neglected because MicrosInstant isn't meant to be used as a Java native type.

@liferoad liferoad added this to the 2.65.0 Release milestone Apr 22, 2025
@ahmedabu98 ahmedabu98 merged commit bf417db into apache:master Apr 22, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants