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
feat: better default stream support in client library #750
Merged
stephaniewang526
merged 20 commits into
googleapis:master
from
yirutang:default-stream-1
Dec 30, 2020
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
01e46df
.
yirutang d205dd1
.
yirutang 70d9a1e
.
yirutang 55b878f
feat: Support default stream on streamWriter and jsonStreamWriter
yirutang 14a4444
add integration test
yirutang 017a543
.
yirutang 5e9888b
.
yirutang 8e47caa
ci(java): ignore bot users for generate-files-bot (#749)
yoshi-automation 489bdbd
.
yirutang 72f0191
.
yirutang f097e24
chore: synthtool changes (#746)
yoshi-automation 2297a30
.
yirutang 940a43e
.
yirutang b9d53e6
.
yirutang 97edec4
.
yirutang a24ae87
.
yirutang cf92c02
.
yirutang e68f2d1
.
yirutang 287c393
fix flushall test
yirutang 0466702
Merge branch 'master' into default-stream-1
stephaniewang526 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
86 changes: 86 additions & 0 deletions
86
...age/src/main/java/com/google/cloud/bigquery/storage/v1beta2/BQV2ToBQStorageConverter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.bigquery.storage.v1beta2; | ||
|
||
import com.google.cloud.bigquery.Field; | ||
import com.google.cloud.bigquery.Schema; | ||
import com.google.cloud.bigquery.StandardSQLTypeName; | ||
import com.google.cloud.bigquery.storage.v1alpha2.Table; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
/** Converts structure from BigQuery v2 API to BigQueryStorage API */ | ||
public class BQV2ToBQStorageConverter { | ||
private static ImmutableMap<Field.Mode, TableFieldSchema.Mode> BQTableSchemaModeMap = | ||
ImmutableMap.of( | ||
Field.Mode.NULLABLE, TableFieldSchema.Mode.NULLABLE, | ||
Field.Mode.REPEATED, TableFieldSchema.Mode.REPEATED, | ||
Field.Mode.REQUIRED, TableFieldSchema.Mode.REQUIRED); | ||
|
||
private static ImmutableMap<StandardSQLTypeName, TableFieldSchema.Type> BQTableSchemaTypeMap = | ||
new ImmutableMap.Builder<StandardSQLTypeName, TableFieldSchema.Type>() | ||
.put(StandardSQLTypeName.BOOL, TableFieldSchema.Type.BOOL) | ||
.put(StandardSQLTypeName.BYTES, TableFieldSchema.Type.BYTES) | ||
.put(StandardSQLTypeName.DATE, TableFieldSchema.Type.DATE) | ||
.put(StandardSQLTypeName.DATETIME, TableFieldSchema.Type.DATETIME) | ||
.put(StandardSQLTypeName.FLOAT64, TableFieldSchema.Type.DOUBLE) | ||
.put(StandardSQLTypeName.GEOGRAPHY, TableFieldSchema.Type.GEOGRAPHY) | ||
.put(StandardSQLTypeName.INT64, TableFieldSchema.Type.INT64) | ||
.put(StandardSQLTypeName.NUMERIC, TableFieldSchema.Type.NUMERIC) | ||
.put(StandardSQLTypeName.STRING, TableFieldSchema.Type.STRING) | ||
.put(StandardSQLTypeName.STRUCT, TableFieldSchema.Type.STRUCT) | ||
.put(StandardSQLTypeName.TIME, TableFieldSchema.Type.TIME) | ||
.put(StandardSQLTypeName.TIMESTAMP, TableFieldSchema.Type.TIMESTAMP) | ||
.build(); | ||
|
||
/** | ||
* Converts from bigquery v2 Table Schema to bigquery storage API Table Schema. | ||
* | ||
* @param schame the bigquery v2 Table Schema | ||
* @return the bigquery storage API Table Schema | ||
*/ | ||
public static TableSchema ConvertTableSchema(Schema schema) { | ||
TableSchema.Builder result = TableSchema.newBuilder(); | ||
for (int i = 0; i < schema.getFields().size(); i++) { | ||
result.addFields(i, ConvertFieldSchema(schema.getFields().get(i))); | ||
} | ||
return result.build(); | ||
} | ||
|
||
/** | ||
* Converts from bigquery v2 Field Schema to bigquery storage API Field Schema. | ||
* | ||
* @param schame the bigquery v2 Field Schema | ||
* @return the bigquery storage API Field Schema | ||
*/ | ||
public static TableFieldSchema ConvertFieldSchema(Field field) { | ||
TableFieldSchema.Builder result = TableFieldSchema.newBuilder(); | ||
if (field.getMode() == null) { | ||
field = field.toBuilder().setMode(Field.Mode.NULLABLE).build(); | ||
} | ||
result.setMode(BQTableSchemaModeMap.get(field.getMode())); | ||
result.setName(field.getName()); | ||
result.setType(BQTableSchemaTypeMap.get(field.getType().getStandardType())); | ||
if (field.getDescription() != null) { | ||
result.setDescription(field.getDescription()); | ||
} | ||
if (field.getSubFields() != null) { | ||
for (int i = 0; i < field.getSubFields().size(); i++) { | ||
result.addFields(i, ConvertFieldSchema(field.getSubFields().get(i))); | ||
} | ||
} | ||
return result.build(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
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.