Open FredrikMeyer opened 1 month ago
Hi @FredrikMeyer ,
Schemas are stored in TableResult and not necessarily FieldValueList. FieldValueList is used for table rows and the schema is not assessable. The schema in FieldValueList is for indexing by field name.
To get the schema for your table, you can simply:
var res2 = bigQuery.query(queryJobConfiguration);
// Read query table schema.
System.out.println(r.hasSchema());
// Get the schema for the field "arr"
System.out.println(r.getSchema().getFields().get("arr"));
res2.iterateAll().forEach(r -> {
// Read table row results.
});
I hope this helps,
Thanks for the answer @PhongChuong
My main problem is that since the schema is not in the FieldValueList, I cannot get the fields by name. So now my code looks like this:
private fun periodeFromFieldValue(periodeRecord: FieldValue) = Periode(
// cannot do recordValue.get("fraDato") because schema is not propagated
fraDato = LocalDate.parse(periodeRecord.recordValue[0].stringValue),
tilDato = LocalDate.parse(periodeRecord.recordValue[1].stringValue),
)
Which seems to rely on the order the fields appear - which seem to coincide with the order they were defined in the table schema (by accident or by construction?).
The field will appear as they are defined in the table schema by construction.
If you want, it is possible to provide the schema manually providing the schema by creating FieldValueList. However, it's not pretty and probably not worth the effort.
// Read query table schema. System.out.println(r.hasSchema()); // Get the schema for the field "arr" System.out.println(r.getSchema().getFields().get("arr"));
res2.iterateAll().forEach(r -> { // Read table row results. });
Hi, sorry for the late reply, but is there really a method getSchema
here? Here r
is of type FieldValueList
.
Environment details
Steps to reproduce
Code example
Reproduced here: https://github.com/FredrikMeyer/bigquery-bug/blob/main/src/test/java/no/fredrikmeyer/MainTest.java
Any additional information below
When having an array of structs, the schema does not seem to be propagated to the fields. Thanks!