Repository navigation
perf(bigquery): [T2-3] support typed FieldValue backing to avoid binary-to-String-to-binary round-trips in ArrowDeserializer - #28
Open
lqiu96 wants to merge 1 commit into
Conversation
…ry-to-String-to-binary round-trips in ArrowDeserializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary & Bottleneck
In
java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowDeserializer.java(arrowVectorToFieldValue), every binary primitive extracted from an Apache Arrow vector is eagerly converted into aStringand wrapped inFieldValue.of(Attribute.PRIMITIVE, stringVal):String-to-binary round-trips onIntVectorandBigIntVectorvalues are formatted viaInteger.toStringorLong.toString, only forFieldValue.getLongValue()to immediately re-parse the string viaLong.parseLong.Float8Vectorvalues are formatted viaDouble.toString, only forFieldValue.getDoubleValue()to re-parse the string viaDouble.parseDouble.TimeStampVectorepoch microsecond values are formatted viaformatTimestampMicros(long)into"<seconds>.<microseconds>", only forFieldValue.getTimestampValue()to construct and scale aBigDecimalto recover the originallongmicroseconds.DecimalVector(BigDecimal) values are formatted viatoPlainString(), only forFieldValue.getNumericValue()to constructnew BigDecimal(String).VarBinaryVector(byte[]) values are Base64-encoded viaBaseEncoding.base64().encode(byte[]), only forFieldValue.getBytesValue()to Base64-decode them back intobyte[].Changes
java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java:ofLong,ofDouble,ofTimestampMicros,ofNumeric,ofBytes) that retain the typed value inrawValue.getLongValue(),getDoubleValue(),getTimestampValue(),getTimestampInstant(),getNumericValue(), andgetBytesValue()without allocating or parsing aString.Stringrepresentation ingetValue()andgetStringValue()(and usegetValue()inequals(),hashCode(), andtoString()) so string access and equality checks remain 100% compatible with string-backedFieldValueinstances.java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowDeserializer.java:FieldValueinstances usingofTimestampMicros,ofLong,ofDouble,ofBytes, andofNumericinarrowVectorToFieldValue.Expected Impact
Stringformatting, Base64 encoding/decoding, andLong/Double/BigDecimalre-parsing when reading typed columns from Arrow streams viagetLongValue(),getDoubleValue(),getTimestampValue(),getNumericValue(), andgetBytesValue().getStringValue(),getValue(),equals(), orhashCode().Verification
java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldValueTest.javaandjava-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ArrowDeserializerTest.java.mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=FieldValueTest,FieldValueListTest,ArrowDeserializerTest,ArrowQueryPageFetcherTest,ConnectionImplTest(59 tests run, 0 failures).