Google-cloud-java: update field description

Created on 3 Apr 2019  路  6Comments  路  Source: googleapis/google-cloud-java

i am trying to update the description of the field, can you guys please suggest me how can I change the field description using java

bigquery question

All 6 comments

for tables i am doing...
com.google.cloud.bigquery.Table beforeTable = bigquery.getTable(datasetId, tableName);
TableInfo tableInfo = beforeTable.toBuilder().setDescription("test").build();
com.google.cloud.bigquery.Table afterTable = bigquery.update(tableInfo);

need the way to update fields description as well.. its urgent

@shollyman, do you have any advice?

For java, I believe you need to access this through the table definition abstraction. e.g. schema would be present in beforeTable.getDefinition().getSchema() from your example.

You can walk the schema to set descriptions per field, and then apply them to your tableInfo for then calling update. You'd want to ensure you're not extending the schema in other ways (manipulating field order, data types, etc) as that would not be a valid schema augmentation.

Hope this helps, please let me know if more guidance is needed. We've defined tasks to add more of these kinds of samples in our backlog, but haven't had a chance to address them.

Thanks for the advice.. @shollyman
i tried as your suggestion but no luck..
com.google.cloud.bigquery.Table beforeTable = bigquery.getTable(datasetId, tableName);
beforeTable.getDefinition().getSchema().getFields().get("complaint_type").toBuilder().setDescription("testField").build();
TableInfo tableInfo = beforeTable.toBuilder().setDescription("schema_test").build();
com.google.cloud.bigquery.Table afterTable = bigquery.update(tableInfo);

can you please guide me to make this slove.

@prasannakumar909
Table getTable = bigquery.getTable("yourdataset", "yourtable"); Schema tableSchema = getTable.getDefinition().getSchema(); FieldList fieldList = tableSchema.getFields(); Field fieldName = fieldList.get("yourField"); Field yourField = fieldName.toBuilder().setDescription("your updated text value").build(); Schema schema = Schema.of(yourField); TableDefinition tableDefinition = StandardTableDefinition.of(schema); Table updatedTable = bigquery.update(TableInfo.of(tableId, tableDefinition));
you can update your description using this code.

@pmakani Thanks this worked out for me.

Was this page helpful?
0 / 5 - 0 ratings