radusecrieru commented on issue #26935:
URL: https://github.com/apache/beam/issues/26935#issuecomment-2589493759
Happened to me also, it looks like it's expecting a specific format, and the
query/result can be encoded by using the
`FakeBigQueryServices.encodeQueryResult` method; for my case, I also had to
expect a dry run query ... this is an example of a full setup, how I used it:
```
FakeDatasetService fakeDatasetService = new FakeDatasetService();
FakeJobService fakeJobService = new FakeJobService();
FakeBigQueryServices fakeBqServices = new FakeBigQueryServices()
.withDatasetService(fakeDatasetService)
.withJobService(fakeJobService);
FakeDatasetService.setUp();
fakeDatasetService.createDataset(PROJECT_ID, DATASET_ID, "EU", "Fake
dataset", 0L);
Table table = new Table().setTableReference(
new TableReference()
.setProjectId(PROJECT_ID)
.setDatasetId(DATASET_ID)
.setTableId(TABLE_ID)
).setSchema(
new TableSchema().setFields(List.of(
new TableFieldSchema()
.set("name", "FIELD1")
.set("type", "STRING"),
new TableFieldSchema()
.set("name", "FIELD2")
.set("type", "STRING"))
));
fakeDatasetService.createTable(table);
List<TableRow> rowsToInsert = List.of(
new TableRow().set("FIELD1", "field1value").set("FIELD2",
"field2value"),
new TableRow().set("FIELD1", "field1othervalue").set("FIELD2",
"field2othervalue")
);
String query = FakeBigQueryServices.encodeQueryResult(table, rows);
JobStatistics jobStatistics = new JobStatistics();
jobStatistics.setQuery(new JobStatistics2().setTotalBytesProcessed(1L));
FakeJobService jobService = (FakeJobService)
this.fakeBqServices.getJobService(options);
jobService.expectDryRunQuery(options.getProject(), query, jobStatistics);
return BigQueryIO.readTableRows()
.withTestServices(fakeBqServices)
.withoutValidation()
.fromQuery(query);
```
it's very weird, and not documented at all, but at least it works 😅
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]