def test_add_format_fields_reserved_field_schema_compatibility(self):
        schema_conflict_format = bigquery.TableSchema()
        calls_record = bigquery.TableFieldSchema(
            name=bigquery_util.ColumnKeyConstants.CALLS,
            type=bigquery_util.TableFieldConstants.TYPE_RECORD,
            mode=bigquery_util.TableFieldConstants.MODE_REPEATED,
            description='One record for each call.')
        calls_record.fields.append(
            bigquery.TableFieldSchema(
                name='GQ',
                type=bigquery_util.TableFieldConstants.TYPE_STRING,
                mode=bigquery_util.TableFieldConstants.MODE_NULLABLE,
                description='desc'))
        schema_conflict_format.fields.append(calls_record)
        with self.assertRaises(ValueError):
            schema_converter.generate_header_fields_from_schema(
                schema_conflict_format)

        formats_allow_incompatible_schema = OrderedDict()
        schema_converter._add_format_fields(calls_record,
                                            formats_allow_incompatible_schema,
                                            allow_incompatible_schema=True)
        expected_formats = OrderedDict([('GQ', Format('GQ', 1, 'String',
                                                      'desc'))])
        self.assertEqual(formats_allow_incompatible_schema, expected_formats)
示例#2
0
  def test_add_format_fields_reserved_field(self):
    calls_record_with_desc = bigquery.TableFieldSchema(
        name=bigquery_util.ColumnKeyConstants.CALLS,
        type=bigquery_util.TableFieldConstants.TYPE_RECORD,
        mode=bigquery_util.TableFieldConstants.MODE_REPEATED,
        description='One record for each call.')
    calls_record_with_desc.fields.append(bigquery.TableFieldSchema(
        name='GQ',
        type=bigquery_util.TableFieldConstants.TYPE_INTEGER,
        mode=bigquery_util.TableFieldConstants.MODE_NULLABLE,
        description='bigquery desc'))
    formats = OrderedDict()
    schema_converter._add_format_fields(calls_record_with_desc,
                                        formats)
    expected_formats = OrderedDict([
        ('GQ', createFormat('GQ', 1, 'Integer', 'bigquery desc'))])
    self.assertEqual(formats, expected_formats)

    calls_record_without_desc = bigquery.TableFieldSchema(
        name=bigquery_util.ColumnKeyConstants.CALLS,
        type=bigquery_util.TableFieldConstants.TYPE_RECORD,
        mode=bigquery_util.TableFieldConstants.MODE_REPEATED,
        description='One record for each call.')
    calls_record_without_desc.fields.append(bigquery.TableFieldSchema(
        name='GQ',
        type=bigquery_util.TableFieldConstants.TYPE_INTEGER,
        mode=bigquery_util.TableFieldConstants.MODE_NULLABLE,
        description=''))
    formats = OrderedDict()
    schema_converter._add_format_fields(calls_record_without_desc,
                                        formats)
    expected_formats = OrderedDict([
        ('GQ', createFormat(
            'GQ', 1, 'Integer', 'Conditional genotype quality'))])
    self.assertEqual(formats, expected_formats)