01 /*
02 * SPDX-License-Identifier: Apache-2.0
03 *
04 * Copyright 2020-2022 Agorapulse.
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package com.agorapulse.micronaut.bigquery.impl;
19
20 import com.agorapulse.micronaut.bigquery.RowResult;
21 import com.google.cloud.bigquery.FieldValueList;
22
23 import java.time.Instant;
24
25 class FieldValueListRowResult implements RowResult {
26
27 private final FieldValueList values;
28
29 FieldValueListRowResult(FieldValueList values) {
30 this.values = values;
31 }
32
33 @Override
34 public boolean isNull(String key) {
35 return values.get(key).isNull();
36 }
37
38 @Override
39 public Boolean getBooleanValue(String key) {
40 return values.get(key).isNull() ? null : values.get(key).getBooleanValue();
41 }
42
43 @Override
44 public Double getDoubleValue(String key) {
45 return values.get(key).isNull() ? null : values.get(key).getDoubleValue();
46 }
47
48 @Override
49 public String getStringValue(String key) {
50 return values.get(key).isNull() ? null : values.get(key).getStringValue();
51 }
52
53 @Override
54 public Long getLongValue(String key) {
55 return values.get(key).isNull() ? null : values.get(key).getLongValue();
56 }
57
58 @Override
59 public Instant getTimestampValue(String key) {
60 if (values.get(key).isNull()) {
61 return null;
62 }
63
64 long timestampValue = values.get(key).getTimestampValue();
65
66 return Instant.ofEpochSecond(timestampValue / 1_000_000, timestampValue % 1_000_000 * 1000);
67 }
68
69 }
|