From 5ff60fe48e2c893bd5daf14eb8e6e14c003571d7 Mon Sep 17 00:00:00 2001 From: Yiru Tang Date: Wed, 8 Feb 2023 01:23:55 +0000 Subject: [PATCH] . --- .../BqToBqStorageSchemaConverter.java | 88 ------------------- 1 file changed, 88 deletions(-) delete mode 100644 samples/snippets/src/main/java/com/example/bigquerystorage/BqToBqStorageSchemaConverter.java diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/BqToBqStorageSchemaConverter.java b/samples/snippets/src/main/java/com/example/bigquerystorage/BqToBqStorageSchemaConverter.java deleted file mode 100644 index 27c5d1dbcb..0000000000 --- a/samples/snippets/src/main/java/com/example/bigquerystorage/BqToBqStorageSchemaConverter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2021 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 - * - * http://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.example.bigquerystorage; - -import com.google.cloud.bigquery.Field; -import com.google.cloud.bigquery.Schema; -import com.google.cloud.bigquery.StandardSQLTypeName; -import com.google.cloud.bigquery.storage.v1.TableFieldSchema; -import com.google.cloud.bigquery.storage.v1.TableSchema; -import com.google.common.collect.ImmutableMap; - -/** Converts structure from BigQuery client to BigQueryStorage client */ -public class BqToBqStorageSchemaConverter { - private static ImmutableMap BQTableSchemaModeMap = - ImmutableMap.of( - Field.Mode.NULLABLE, TableFieldSchema.Mode.NULLABLE, - Field.Mode.REPEATED, TableFieldSchema.Mode.REPEATED, - Field.Mode.REQUIRED, TableFieldSchema.Mode.REQUIRED); - - private static ImmutableMap BQTableSchemaTypeMap = - new ImmutableMap.Builder() - .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 client Table Schema to bigquery storage API Table Schema. - * - * @param schema the BigQuery client 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 field the BigQuery client 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(); - } -}