|
9 | 9 | import com.fasterxml.jackson.databind.JsonNode;
|
10 | 10 | import com.fasterxml.jackson.databind.node.ObjectNode;
|
11 | 11 | import com.google.auth.oauth2.ServiceAccountCredentials;
|
12 |
| -import com.google.cloud.bigquery.BigQuery; |
13 |
| -import com.google.cloud.bigquery.BigQueryOptions; |
14 |
| -import com.google.cloud.bigquery.Dataset; |
15 |
| -import com.google.cloud.bigquery.DatasetInfo; |
16 |
| -import com.google.cloud.bigquery.Field; |
17 |
| -import com.google.cloud.bigquery.FieldList; |
18 |
| -import com.google.cloud.bigquery.FieldValue; |
19 |
| -import com.google.cloud.bigquery.FieldValueList; |
20 |
| -import com.google.cloud.bigquery.Job; |
21 |
| -import com.google.cloud.bigquery.JobId; |
22 |
| -import com.google.cloud.bigquery.JobInfo; |
23 |
| -import com.google.cloud.bigquery.QueryJobConfiguration; |
24 |
| -import com.google.cloud.bigquery.TableResult; |
| 12 | +import com.google.cloud.bigquery.*; |
25 | 13 | import com.google.common.collect.ImmutableMap;
|
26 |
| -import com.google.common.collect.Maps; |
| 14 | +import io.airbyte.db.bigquery.BigQueryResultSet; |
| 15 | +import io.airbyte.db.bigquery.BigQuerySourceOperations; |
| 16 | +import com.google.common.collect.Streams; |
27 | 17 | import io.airbyte.commons.json.Jsons;
|
28 | 18 | import io.airbyte.commons.resources.MoreResources;
|
29 | 19 | import io.airbyte.commons.string.Strings;
|
|
32 | 22 | import io.airbyte.integrations.destination.StandardNameTransformer;
|
33 | 23 | import io.airbyte.integrations.standardtest.destination.DataArgumentsProvider;
|
34 | 24 | import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
|
| 25 | +import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator; |
35 | 26 | import io.airbyte.protocol.models.AirbyteCatalog;
|
36 | 27 | import io.airbyte.protocol.models.AirbyteMessage;
|
37 | 28 | import io.airbyte.protocol.models.AirbyteRecordMessage;
|
|
42 | 33 | import java.nio.charset.StandardCharsets;
|
43 | 34 | import java.nio.file.Files;
|
44 | 35 | import java.nio.file.Path;
|
45 |
| -import java.util.ArrayList; |
46 |
| -import java.util.List; |
47 |
| -import java.util.Map; |
48 |
| -import java.util.Optional; |
49 |
| -import java.util.UUID; |
| 36 | +import java.util.*; |
50 | 37 | import java.util.stream.Collectors;
|
51 |
| -import java.util.stream.StreamSupport; |
52 | 38 | import org.apache.commons.lang3.tuple.ImmutablePair;
|
53 | 39 | import org.junit.jupiter.params.ParameterizedTest;
|
54 | 40 | import org.junit.jupiter.params.provider.ArgumentsSource;
|
@@ -110,6 +96,26 @@ protected Optional<NamingConventionTransformer> getNameTransformer() {
|
110 | 96 | return Optional.of(NAME_TRANSFORMER);
|
111 | 97 | }
|
112 | 98 |
|
| 99 | + @Override |
| 100 | + protected TestDataComparator getTestDataComparator() { |
| 101 | + return new BigQueryDenormalizedTestDataComparator(); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + protected boolean supportBasicDataTypeTest() { |
| 106 | + return true; |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + protected boolean supportArrayDataTypeTest() { |
| 111 | + return true; |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + protected boolean supportObjectDataTypeTest() { |
| 116 | + return true; |
| 117 | + } |
| 118 | + |
113 | 119 | @Override
|
114 | 120 | protected void assertNamespaceNormalization(final String testCaseId,
|
115 | 121 | final String expectedNormalizedNamespace,
|
@@ -142,43 +148,30 @@ protected List<JsonNode> retrieveRecords(final TestDestinationEnv env,
|
142 | 148 | final String streamName,
|
143 | 149 | final String namespace,
|
144 | 150 | final JsonNode streamSchema)
|
145 |
| - throws Exception { |
146 |
| - return new ArrayList<>(retrieveRecordsFromTable(namingResolver.getIdentifier(streamName), namingResolver.getIdentifier(namespace))); |
147 |
| - } |
148 |
| - |
149 |
| - @Override |
150 |
| - protected List<String> resolveIdentifier(final String identifier) { |
151 |
| - final List<String> result = new ArrayList<>(); |
152 |
| - result.add(identifier); |
153 |
| - result.add(namingResolver.getIdentifier(identifier)); |
154 |
| - return result; |
| 151 | + throws Exception { |
| 152 | + final String tableName = namingResolver.getIdentifier(streamName); |
| 153 | + final String schema = namingResolver.getIdentifier(namespace); |
| 154 | + return retrieveRecordsFromTable(tableName, schema); |
155 | 155 | }
|
156 | 156 |
|
157 | 157 | private List<JsonNode> retrieveRecordsFromTable(final String tableName, final String schema) throws InterruptedException {
|
| 158 | + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); |
| 159 | + |
158 | 160 | final QueryJobConfiguration queryConfig =
|
159 |
| - QueryJobConfiguration |
160 |
| - .newBuilder( |
161 |
| - String.format("SELECT * FROM `%s`.`%s` order by %s asc;", schema, tableName, |
162 |
| - JavaBaseConstants.COLUMN_NAME_EMITTED_AT)) |
163 |
| - .setUseLegacySql(false).build(); |
| 161 | + QueryJobConfiguration |
| 162 | + .newBuilder( |
| 163 | + String.format("SELECT * FROM `%s`.`%s` order by %s asc;", schema, tableName, |
| 164 | + JavaBaseConstants.COLUMN_NAME_EMITTED_AT)) |
| 165 | +// .setUseLegacySql(false) |
| 166 | + .setConnectionProperties(Collections.singletonList(ConnectionProperty.of("time_zone", "UTC"))) |
| 167 | + .build(); |
164 | 168 |
|
165 | 169 | final TableResult queryResults = executeQuery(bigquery, queryConfig).getLeft().getQueryResults();
|
166 | 170 | final FieldList fields = queryResults.getSchema().getFields();
|
| 171 | + BigQuerySourceOperations sourceOperations = new BigQuerySourceOperations(); |
167 | 172 |
|
168 |
| - return StreamSupport |
169 |
| - .stream(queryResults.iterateAll().spliterator(), false) |
170 |
| - .map(row -> { |
171 |
| - final Map<String, Object> jsonMap = Maps.newHashMap(); |
172 |
| - for (final Field field : fields) { |
173 |
| - final Object value = getTypedFieldValue(row, field); |
174 |
| - if (!isAirbyteColumn(field.getName()) && value != null) { |
175 |
| - jsonMap.put(field.getName(), value); |
176 |
| - } |
177 |
| - } |
178 |
| - return jsonMap; |
179 |
| - }) |
180 |
| - .map(Jsons::jsonNode) |
181 |
| - .collect(Collectors.toList()); |
| 173 | + return Streams.stream(queryResults.iterateAll()) |
| 174 | + .map(fieldValues -> sourceOperations.rowToJson(new BigQueryResultSet(fieldValues, fields))).collect(Collectors.toList()); |
182 | 175 | }
|
183 | 176 |
|
184 | 177 | private boolean isAirbyteColumn(final String name) {
|
|
0 commit comments