Skip to content

[Bug]: BQ TableRow does not accept column named 'f' #33531

Open

Description

@RustedBones

What happened?

When working with a BQ table with a column named 'f', construction of a TableRow object fails with

java.lang.IllegalArgumentException: Can not set java.util.List field com.google.api.services.bigquery.model.TableRow.f to java.lang.String

This happens because TableRow is a GenericJson and has a key field named f expecting a List<TableCell>.

When reading the javadoc for TableRow, it seems to me that this model is supposed to represent a BQ resultset in the form

{
  "f": [{"v":  1}, {"v": "value"}]
}

beam abuses the GenericJson capability and relies on the unknown fields to encode the result in the form

{
   "column1": 1,
   "column2": "value"
}

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Activity

  1. Abacn commented on Jan 21, 2025

    @Abacn
    Contributor

    This is a longstanding issue - similar fix made on #16872 (still has edge case left there). Which write method are you using (FILE_LOAD or STORAGE_WRITE_API) ?

  2. RustedBones commented on Jan 21, 2025

    @RustedBones
    ContributorAuthor

    This is not related to any BQ method.

    The problem lies on the model itself where the following fails

    new TableRow().set("f", data);

    So any BQ code attempting to set a field named f fails. This can happen for any BQ method

  3. github-actions commented on Jun 21, 2025

    @github-actions
    Contributor

    This issue has been marked as stale due to 150 days of inactivity. It will be closed in 30 days if no further activity occurs. If you think that’s incorrect or this issue still needs to be addressed, please simply write any comment. If closed, you can reopen the issue at any time. Thank you for your contributions.

  4. github-actions commented on Jul 21, 2025

    @github-actions
    Contributor

    This issue has been closed due to lack of activity. If you think that is incorrect, you can reopen the issue at any time.

  5. reopened this on Jul 21, 2025
  6. Abacn commented on Oct 3, 2025

    @Abacn
    Contributor

    For future reference, here is a example for workaround

    public class WriteTest {
      public static class DataType implements Serializable {
        public Integer key;
        public Instant timestamp;
        public DataType(Integer key) {
          this.key = key;
          this.timestamp = Instant.now();
        }
      }
    
      static SerializableFunction<DataType, TableRow> getTableRowFnc() {
        return (DataType data) -> {
          TableRow tableRow = new TableRow();
          tableRow.setF(ImmutableList.of(new TableCell().setV(data.key), new TableCell().setV(data.timestamp.getMillis() * 1000)));
          return tableRow;
        };
      }
    
      static SerializableFunction<DataType, String> getTagFnc() {
        return (DataType data) -> data.key.toString();
      }
    
      static TableSchema getTableSchema() {
        List<TableFieldSchema> fields = new ArrayList<>();
        fields.add(new TableFieldSchema().setName("f").setType("INT64").setMode("REQUIRED"));
        fields.add(new TableFieldSchema().setName("timestamp").setType("TIMESTAMP").setMode("NULLABLE"));
        return new TableSchema().setFields(fields);
      }
    
      public static void main(String argv[]) {
        PipelineOptions options = PipelineOptionsFactory.fromArgs(argv).withValidation().as(PipelineOptions.class);
        Pipeline p = Pipeline.create(options);
    
        p.apply(Create.of(new DataType(1), new DataType(2), new DataType(3)))
            .apply(BigQueryIO.<DataType>write()
                .to("<project>:<dataset>.<table>")
                .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
                .withSchema(getTableSchema())
                .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
                .withExtendedErrorInfo()
                .withFormatFunction(getTableRowFnc())
                .withDeterministicRecordIdFn(getTagFnc())
                .withMethod(BigQueryIO.Write.Method.STORAGE_WRITE_API)
            );
        p.run().waitUntilFinish();
      }
    }

    By providing a TableRow that set fields by "setF" directly, it makes the code path of the fix #16872 evaluated.

  7. liferoad commented on Oct 6, 2025

    @liferoad
    Contributor

    https://github.com/liferoad/df-bq-tests/ has more examples about how the workarounds work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions