|
11 | 11 | import com.google.auth.oauth2.ServiceAccountCredentials;
|
12 | 12 | import com.google.cloud.bigquery.BigQuery;
|
13 | 13 | import com.google.cloud.bigquery.BigQueryOptions;
|
| 14 | +import com.google.cloud.bigquery.ConnectionProperty; |
14 | 15 | import com.google.cloud.bigquery.Dataset;
|
15 | 16 | import com.google.cloud.bigquery.DatasetInfo;
|
16 | 17 | import com.google.cloud.bigquery.Field;
|
|
23 | 24 | import com.google.cloud.bigquery.QueryJobConfiguration;
|
24 | 25 | import com.google.cloud.bigquery.TableResult;
|
25 | 26 | import com.google.common.collect.ImmutableMap;
|
26 |
| -import com.google.common.collect.Maps; |
| 27 | +import com.google.common.collect.Streams; |
27 | 28 | import io.airbyte.commons.json.Jsons;
|
28 | 29 | import io.airbyte.commons.resources.MoreResources;
|
29 | 30 | import io.airbyte.commons.string.Strings;
|
| 31 | +import io.airbyte.db.bigquery.BigQueryResultSet; |
| 32 | +import io.airbyte.db.bigquery.BigQuerySourceOperations; |
30 | 33 | import io.airbyte.integrations.base.JavaBaseConstants;
|
31 | 34 | import io.airbyte.integrations.destination.NamingConventionTransformer;
|
32 | 35 | import io.airbyte.integrations.destination.StandardNameTransformer;
|
33 | 36 | import io.airbyte.integrations.standardtest.destination.DataArgumentsProvider;
|
34 | 37 | import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
|
| 38 | +import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator; |
35 | 39 | import io.airbyte.protocol.models.AirbyteCatalog;
|
36 | 40 | import io.airbyte.protocol.models.AirbyteMessage;
|
37 | 41 | import io.airbyte.protocol.models.AirbyteRecordMessage;
|
|
42 | 46 | import java.nio.charset.StandardCharsets;
|
43 | 47 | import java.nio.file.Files;
|
44 | 48 | import java.nio.file.Path;
|
45 |
| -import java.util.ArrayList; |
| 49 | +import java.util.Collections; |
46 | 50 | import java.util.List;
|
47 |
| -import java.util.Map; |
48 | 51 | import java.util.Optional;
|
| 52 | +import java.util.TimeZone; |
49 | 53 | import java.util.UUID;
|
50 | 54 | import java.util.stream.Collectors;
|
51 |
| -import java.util.stream.StreamSupport; |
52 | 55 | import org.apache.commons.lang3.tuple.ImmutablePair;
|
53 | 56 | import org.junit.jupiter.params.ParameterizedTest;
|
54 | 57 | import org.junit.jupiter.params.provider.ArgumentsSource;
|
@@ -110,6 +113,27 @@ protected Optional<NamingConventionTransformer> getNameTransformer() {
|
110 | 113 | return Optional.of(NAME_TRANSFORMER);
|
111 | 114 | }
|
112 | 115 |
|
| 116 | + @Override |
| 117 | + protected TestDataComparator getTestDataComparator() { |
| 118 | + return new BigQueryDenormalizedTestDataComparator(); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + protected boolean supportBasicDataTypeTest() { |
| 123 | + return true; |
| 124 | + } |
| 125 | + |
| 126 | + // #13154 Normalization issue |
| 127 | + @Override |
| 128 | + protected boolean supportArrayDataTypeTest() { |
| 129 | + return false; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + protected boolean supportObjectDataTypeTest() { |
| 134 | + return true; |
| 135 | + } |
| 136 | + |
113 | 137 | @Override
|
114 | 138 | protected void assertNamespaceNormalization(final String testCaseId,
|
115 | 139 | final String expectedNormalizedNamespace,
|
@@ -143,42 +167,29 @@ protected List<JsonNode> retrieveRecords(final TestDestinationEnv env,
|
143 | 167 | final String namespace,
|
144 | 168 | final JsonNode streamSchema)
|
145 | 169 | 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; |
| 170 | + final String tableName = namingResolver.getIdentifier(streamName); |
| 171 | + final String schema = namingResolver.getIdentifier(namespace); |
| 172 | + return retrieveRecordsFromTable(tableName, schema); |
155 | 173 | }
|
156 | 174 |
|
157 | 175 | private List<JsonNode> retrieveRecordsFromTable(final String tableName, final String schema) throws InterruptedException {
|
| 176 | + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); |
| 177 | + |
158 | 178 | final QueryJobConfiguration queryConfig =
|
159 | 179 | QueryJobConfiguration
|
160 | 180 | .newBuilder(
|
161 | 181 | String.format("SELECT * FROM `%s`.`%s` order by %s asc;", schema, tableName,
|
162 | 182 | JavaBaseConstants.COLUMN_NAME_EMITTED_AT))
|
163 |
| - .setUseLegacySql(false).build(); |
| 183 | + // .setUseLegacySql(false) |
| 184 | + .setConnectionProperties(Collections.singletonList(ConnectionProperty.of("time_zone", "UTC"))) |
| 185 | + .build(); |
164 | 186 |
|
165 | 187 | final TableResult queryResults = executeQuery(bigquery, queryConfig).getLeft().getQueryResults();
|
166 | 188 | final FieldList fields = queryResults.getSchema().getFields();
|
| 189 | + BigQuerySourceOperations sourceOperations = new BigQuerySourceOperations(); |
167 | 190 |
|
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()); |
| 191 | + return Streams.stream(queryResults.iterateAll()) |
| 192 | + .map(fieldValues -> sourceOperations.rowToJson(new BigQueryResultSet(fieldValues, fields))).collect(Collectors.toList()); |
182 | 193 | }
|
183 | 194 |
|
184 | 195 | private boolean isAirbyteColumn(final String name) {
|
|
0 commit comments