|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright 2018-2020 The Feast Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package feast.storage.connectors.bigquery.common; |
| 18 | + |
| 19 | +import com.google.cloud.bigquery.StandardSQLTypeName; |
| 20 | +import feast.types.ValueProto; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.Map; |
| 23 | + |
| 24 | +public class TypeUtil { |
| 25 | + |
| 26 | + private static final Map<ValueProto.ValueType.Enum, StandardSQLTypeName> |
| 27 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE = new HashMap<>(); |
| 28 | + |
| 29 | + static { |
| 30 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put(ValueProto.ValueType.Enum.BYTES, StandardSQLTypeName.BYTES); |
| 31 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 32 | + ValueProto.ValueType.Enum.STRING, StandardSQLTypeName.STRING); |
| 33 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put(ValueProto.ValueType.Enum.INT32, StandardSQLTypeName.INT64); |
| 34 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put(ValueProto.ValueType.Enum.INT64, StandardSQLTypeName.INT64); |
| 35 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 36 | + ValueProto.ValueType.Enum.DOUBLE, StandardSQLTypeName.FLOAT64); |
| 37 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 38 | + ValueProto.ValueType.Enum.FLOAT, StandardSQLTypeName.FLOAT64); |
| 39 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put(ValueProto.ValueType.Enum.BOOL, StandardSQLTypeName.BOOL); |
| 40 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 41 | + ValueProto.ValueType.Enum.BYTES_LIST, StandardSQLTypeName.BYTES); |
| 42 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 43 | + ValueProto.ValueType.Enum.STRING_LIST, StandardSQLTypeName.STRING); |
| 44 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 45 | + ValueProto.ValueType.Enum.INT32_LIST, StandardSQLTypeName.INT64); |
| 46 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 47 | + ValueProto.ValueType.Enum.INT64_LIST, StandardSQLTypeName.INT64); |
| 48 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 49 | + ValueProto.ValueType.Enum.DOUBLE_LIST, StandardSQLTypeName.FLOAT64); |
| 50 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 51 | + ValueProto.ValueType.Enum.FLOAT_LIST, StandardSQLTypeName.FLOAT64); |
| 52 | + VALUE_TYPE_TO_STANDARD_SQL_TYPE.put( |
| 53 | + ValueProto.ValueType.Enum.BOOL_LIST, StandardSQLTypeName.BOOL); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Converts {@link feast.types.ValueProto.ValueType} to its corresponding {@link |
| 58 | + * StandardSQLTypeName} |
| 59 | + * |
| 60 | + * @param valueType value type to convert |
| 61 | + * @return {@link StandardSQLTypeName} |
| 62 | + */ |
| 63 | + public static StandardSQLTypeName toStandardSqlType(ValueProto.ValueType.Enum valueType) { |
| 64 | + return VALUE_TYPE_TO_STANDARD_SQL_TYPE.get(valueType); |
| 65 | + } |
| 66 | +} |
0 commit comments