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

Using JobId (in Java) when querying, causes 'no such table' error to be returned #273

Open
xersiee opened this issue Feb 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@xersiee
Copy link

xersiee commented Feb 26, 2024

What happened?

I'm using Java, bigquery-emulator and testcontainers to write integration tests for my app. Thing is, when I am providing my own JobId (even empty one) when creating QueryJobConfiguration, emulator seems to build incorrect (not existing) table name and returns error.
This one bigQuery.query(queryConfig) works, but this one bigQuery.query(queryConfig, jobId) triggers errors. More details below.

What did you expect to happen?

Fact of providing (or not) jobId shouldn't affect the way query is processed

How can we reproduce it (as minimally and precisely as possible)?

Below is a minimal code I'm using to reproduce this error. First query prints 2 as expected. Second one throws
com.google.cloud.bigquery.BigQueryException: failed to query select * from tableA: no such table: test-project_tableA.
I can only guess that after adding jobId, table name is missing dataset name?

    var bigQueryContainer = new BigQueryEmulatorContainer(
            DockerImageName.parse("ghcr.io/goccy/bigquery-emulator:latest")
    );
    bigQueryContainer.start();

    var bigQuery = BigQueryOptions.newBuilder()
            .setCredentials(NoCredentials.getInstance())
            .setProjectId(bigQueryContainer.getProjectId())
            .setHost(bigQueryContainer.getEmulatorHttpEndpoint()).build().getService();

    DatasetInfo datasetInfo = DatasetInfo.newBuilder("datasetA").build();
    bigQuery.create(datasetInfo);

    TableId tableId = TableId.of("datasetA", "tableA");

    Schema schema = Schema.of(Field.of("name", StandardSQLTypeName.STRING));

    TableDefinition tableDefinition = StandardTableDefinition.of(schema);
    TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
    bigQuery.create(tableInfo);

    var row1 = InsertAllRequest.RowToInsert.of(Map.of("name", "AAA"));
    var row2 = InsertAllRequest.RowToInsert.of(Map.of("name", "BBB"));
    InsertAllRequest insertRequest = InsertAllRequest.newBuilder(tableId)
            .addRow(row1).addRow(row2).build();
    bigQuery.insertAll(insertRequest);

    var query = "select * from tableA";

    // Works
    var queryConfig1 = QueryJobConfiguration.newBuilder(query).setDefaultDataset("datasetA").build();
    var result1 = bigQuery.query(queryConfig1);
    System.out.println(result1.getTotalRows());

    // Doesn't work
    var queryConfig2 = QueryJobConfiguration.newBuilder(query).setDefaultDataset("datasetA").build();
    var jobId = JobId.newBuilder().build();
    var result2 = bigQuery.query(queryConfig2, jobId); // this line throws
    System.out.println(result2.getTotalRows());

Anything else we need to know?

No response

@xersiee xersiee added the bug Something isn't working label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant