BigqueryIO Unable to Write to Date-Partitioned Table

1.7k views Asked by At

I am following the instructions in the following post to write to a date-partitioned table in BigQuery. I am using a serializable function to map the the window to a partition-location using the $ syntax and I get the following error:

Invalid table ID \"table$19700822\". Table IDs must be alphanumeric (plus underscores) and must be at most 1024 characters long.

Am I missing something here?

Edit adding code:

p.apply(Window.<TableRow>into(FixedWindows.of(Duration.standardDays(1))))
    .apply(BigQueryIO.Write
    .named("Write")
    .withSchema(schema)
    .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
    .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
    .to(new SerializableFunction<BoundedWindow, String>() {
      public String apply(BoundedWindow window) {
        String dayString = DateTimeFormat.forPattern("yyyyMMdd")
             .withZone(DateTimeZone.UTC)
             .print(((IntervalWindow) window).start());
        return "project_id:dataset.table$" + dayString;
      }
    }));
1

There are 1 answers

3
Sonya On BEST ANSWER

Make sure that the table you're trying to access already exists. You can't create a table with "$" in it, and you're using "create if needed", so that your code might end up creating the table in addition to trying to write to it.