def generate_header_fields_from_schema(schema,
                                       allow_incompatible_schema=False):
    # type: (bigquery.TableSchema, bool) -> vcf_header_io.VcfHeader
    """Returns header fields converted from BigQuery schema.

  This is a best effort reconstruction of header fields. Only INFO and FORMAT
  are considered. For each header field, the type is mapped from BigQuery
  schema field type to VCF type, and the number is inferred based on BigQuery
  schema field type and mode.

  Args:
    schema: BigQuery schema that is used to convert to header fields.
    allow_incompatible_schema: If true, the type and mode compatibility
      validation between `schema` and the reserved fields are skipped.
  Raises:
    ValueError: If the field schema type/mode is not consistent with the
      reserved type/mode.
  """
    infos = OrderedDict()  # type: OrderedDict[str, _Info]
    formats = OrderedDict()  # type: OrderedDict[str, _Format]
    for field in schema.fields:
        if (field.type
                not in bigquery_util.get_supported_bigquery_schema_types()
                or field.name in _NON_INFO_OR_FORMAT_CONSTANT_FIELDS):
            continue
        if field.name == bigquery_util.ColumnKeyConstants.CALLS:
            _add_format_fields(field, formats, allow_incompatible_schema)
        else:
            _add_info_fields(field, infos, allow_incompatible_schema)

    return vcf_header_io.VcfHeader(infos=infos, formats=formats)
Beispiel #2
0
def _get_query_columns(schema):
  # type: (bigquery_v2.TableSchema) -> List[str]
  """Returns a list of columns to be selected for the query.

  Only the fields with supported schema types are loaded from BigQuery. e.g.,
  in the clustered table, the field with type DATE will be ignored. Also,
  it assumes that all sub fields in the RECORD fields have valid types.
  """
  columns = []
  for table_field in schema.fields:
    if table_field.type in bigquery_util.get_supported_bigquery_schema_types():
      columns.append(table_field.name)
  return columns