Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct _default stream path #6

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.vinted.flink.bigquery.schema.SchemaTransformer;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.Executors;

public class BigQueryJsonClientProvider implements ClientProvider<JsonStreamWriter> {
Expand Down Expand Up @@ -61,17 +62,18 @@ public WriterSettings writeSettings() {
return this.writerSettings;
}

TableSchema getTableSchema(TableId table) {
var schema = BigQueryOptions
TableSchema getTableSchema(TableId tableId) {
var table = BigQueryOptions
.newBuilder()
.setProjectId(table.getProject())
.setProjectId(tableId.getProject())
.setCredentials(credentials.getCredentials())
.build()
.getService()
.getTable(table.getDataset(), table.getTable())
.getTable(tableId.getDataset(), tableId.getTable());
var schema = Optional.ofNullable(table)
.orElseThrow(() -> new IllegalArgumentException("Non existing table: " + tableId))
.getDefinition()
.getSchema();

return SchemaTransformer.convertTableSchema(schema);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public BigQueryWriteClient getClient() {
throw new RuntimeException(e);
}
}

return bigQueryWriteClient;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vinted/flink/bigquery/model/Rows.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Rows<A> updateBatch(List<A> data, long offset) {

public static <A> Rows<A> defaultStream(List<A> data, TableId table) {
var fullPath = TableName.of(table.getProject(), table.getDataset(), table.getTable()).toString();
return new Rows<>(data, -1, String.format("%s/_default", fullPath), table);
return new Rows<>(data, -1, String.format("%s/streams/_default", fullPath), table);
}

public Rows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
import org.apache.flink.streaming.api.windowing.windows.Window;
import org.apache.flink.util.Collector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class RowBatcher<A extends BigQueryRecord, K, W extends Window> extends ProcessWindowFunction<A, Rows<A>, K, W> {
private static final Logger logger = LoggerFactory.getLogger(RowBatcher.class);

@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/vinted/flink/bigquery/RowBatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void shouldReleaseTwoBatches(@FlinkTest.FlinkParam FlinkTest.PipelineRunn
assertThat(result)
.usingRecursiveComparison()
.isEqualTo(List.of(
new Rows<>(List.of(new Record("key", "1"), new Record("key", "2")), -1, "projects/test-project/datasets/test-dataset/tables/test-table/_default", testTable),
new Rows<>(List.of(new Record("key", "3"), new Record("key", "4")), -1, "projects/test-project/datasets/test-dataset/tables/test-table/_default", testTable)
new Rows<>(List.of(new Record("key", "1"), new Record("key", "2")), -1, "projects/test-project/datasets/test-dataset/tables/test-table/streams/_default", testTable),
new Rows<>(List.of(new Record("key", "3"), new Record("key", "4")), -1, "projects/test-project/datasets/test-dataset/tables/test-table/streams/_default", testTable)
));
}

Expand Down