Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

FAILED_PRECONDITION: request failed: Failed to convert table schema to Avro record schema

Hello community,
I'm facing below error while trying to read BQ table data using storage read api
FAILED_PRECONDITION: request failed: Failed to convert table schema to Avro record schema. field name column with space, error Invalid name:column with space
Note: column with space is name of a column in my table.
This error doesn't occur when the column names do not have a space.

My Questions
1. Does Avro format support a column name with space?
2. Is there a way to retrieve data for my table data that contains a column like column with space using storage read api ?

Artifact: Code snippet

String tableReference = "projects/myproject/datasets/mydataset/tables/mytable";

ReadSession.TableReadOptions.Builder options = ReadSession.TableReadOptions.newBuilder();
options.addSelectedFields("column1");
options.addSelectedFields("column2");
options.addSelectedFields("column with space");

ReadSession.Builder sessionBuilder =
ReadSession.newBuilder()
.setTable(tableReference)
.setDataFormat(DataFormat.AVRO)
.setReadOptions(options);

CreateReadSessionRequest createReadSessionRequest =
CreateReadSessionRequest.newBuilder()
.setParent("projects/myproject")
.setReadSession(sessionBuilder)
.setMaxStreamCount(4)
.build();

ReadSession session = readClient.createReadSession(createReadSessionRequest);

// process session.getStreamsList()

I'm getting the error while trying to createReadSession.

Artifact: Java SDK version

"com.google.cloud:google-cloud-bigquerystorage:3.2.0"
"com.google.cloud:google-cloud-bigquery:2.5.1",

I appreciate any help here.
Thanks

Solved Solved
0 1 1,411
1 ACCEPTED SOLUTION

Looking at the Avro spec here ... https://avro.apache.org/docs/1.11.1/specification/#names ... it appears that Avro does not support column names that contain a space.   While I have no idea whether it will work, maybe try and create a view on the table with the column with spaces replaced with one without spaces.  It might work if we are lucky.  Otherwise, you might have to start contemplating renaming the column (with all the associated impact) to remove the space.

View solution in original post

1 REPLY 1

Looking at the Avro spec here ... https://avro.apache.org/docs/1.11.1/specification/#names ... it appears that Avro does not support column names that contain a space.   While I have no idea whether it will work, maybe try and create a view on the table with the column with spaces replaced with one without spaces.  It might work if we are lucky.  Otherwise, you might have to start contemplating renaming the column (with all the associated impact) to remove the space.