Find the set of fields missing from record, and set of extra fields from record, based on the db schema.
    Return (missing, extra)
435542
def namedb_find_missing_and_extra(cur, record, table_name):
    
    rec_missing = []
    rec_extra = []
    
    # sanity check: all fields must be defined
    name_fields_rows = db_query_execute(cur, 'PRAGMA table_info({})'.format(table_name), ())
    name_fields = []
    for row in name_fields_rows:
        name_fields.append( row['name'] )

    # make sure each column has a record field
    for f in name_fields:
        if f not in record.keys():
            rec_missing.append( f )

    # make sure each record field has a column
    for k in record.keys():
        if k not in name_fields:
            rec_extra.append( k )

    return rec_missing, rec_extra
722122
private TableFieldSchema getSchemaOfRepeatedFields(Field field) {
    Class<?> parameterType = BigQueryFieldUtil.getParameterTypeOfRepeatedField(field);
    TableFieldSchema tf = parseFieldAnnotations(field);
    tf.setMode(BigQueryFieldMode.REPEATED.getValue());
    if (BigqueryFieldMarshallers.getMarshaller(parameterType) != null) {
      return tf.setType(BigQueryDataTypeUtil.getBigQueryType(
          BigqueryFieldMarshallers.getMarshaller(parameterType).getSchemaType()));
    }
    tf.setType(BigQueryConstants.RECORD_TYPE);
    return tf.setFields(getSchema(parameterType));
  }
907501
def _get_existing_records(cr, fp, module_name):
    """"""
    def yield_element(node, path=None):
        if node.tag not in ['openerp', 'odoo', 'data']:
            if node.tag == 'record':
                xmlid = node.attrib['id']
                if '.' not in xmlid:
                    module = module_name
                else:
                    module, xmlid = xmlid.split('.', 1)
                cr.execute(
                    'select id from ir_model_data where module=%s and name=%s',
                    (module, xmlid)
                )
                if not cr.rowcount:
                    return
            result = StringIO(etree.tostring(path, encoding='unicode'))
            result.name = None
            yield result
        else:
            for child in node:
                for value in yield_element(
                        child,
                        etree.SubElement(path, node.tag, node.attrib)
                        if path else etree.Element(node.tag, node.attrib)
                ):
                    yield value
    return yield_element(etree.parse(fp).getroot())
1120250
def check_extraneous(config, schema):
    """"""
    if not isinstance(config, dict):
        raise ValueError("Config {} is not a dictionary".format(config))
    for k in config:
        if k not in schema:
            raise ValueError("Unexpected config key `{}` not in {}".format(
                k, list(schema.keys())))
        v, kreq = schema[k]
        if v is None:
            continue
        elif isinstance(v, type):
            if not isinstance(config[k], v):
                if v is str and isinstance(config[k], string_types):
                    continue
                raise ValueError(
                    "Config key `{}` has wrong type {}, expected {}".format(
                        k,
                        type(config[k]).__name__, v.__name__))
        else:
            check_extraneous(config[k], v)
181683
def description(self):
        """"""
        result = self.query.result()
        return [field for field in result.schema]
805495
def _get_mapping(self, schema):
        
        properties = {}
        for field, field_schema in schema.items():
            field_mapping = self._get_field_mapping(field_schema)
            if field_mapping:
                properties[field] = field_mapping
        return {'properties': properties}
107384
def find_by_field(self, table, field, field_value):
        '''
        
        '''
        sql = "select * from {} where {} = '{}'".format(
            table, field, field_value)
        res = self.query(sql)
        return res
440952
def validate(self, data):
        
        for s in [self._schema(s, error=self._error, ignore_extra_keys=self._ignore_extra_keys) for s in self._args]:
            data = s.validate(data)
        return data
1331227
def does_field_exist(self,collection,field_name):
        '''
        
        '''
        schema = self.get_schema_fields(collection)
        logging.info(schema)
        return True if field_name in [field['name'] for field in schema['fields']] else False
541438
def get_set(self, fieldname):
        """"""
        set_items = set()
        for ntdata in self.nts:
            set_items |= getattr(ntdata, fieldname)
        return set_items
1002629
def schema(self):
        
        schema = _helpers._get_sub_prop(self._properties, ["load", "schema", "fields"])
        if schema is None:
            return
        return [SchemaField.from_api_repr(field) for field in schema]
864412
def get_field_list(fields, schema):
  
  # If the fields weren't supplied get them from the schema.
  if schema:
    all_fields = [f['name'] for f in schema._bq_schema if f['type'] != 'RECORD']

  if isinstance(fields, list):
    if schema:
      # validate fields exist
      for f in fields:
        if f not in all_fields:
          raise Exception('Cannot find field %s in given schema' % f)
    return fields
  if isinstance(fields, basestring) and fields != '*':
    if schema:
      # validate fields exist
      for f in fields.split(','):
        if f not in all_fields:
          raise Exception('Cannot find field %s in given schema' % f)
      return fields.split(',')
  if not schema:
    return []
  return all_fields
1219384
def merge_record_extra(record, target, reserved):
    
    for key, value in record.__dict__.items():
        # this allows to have numeric keys
        if (key not in reserved
            and not (hasattr(key, "startswith")
                     and key.startswith('_'))):
            target[key] = value
    return target
486656
def collections(record, key, value):
    """"""
    return {
        'primary': value.get('a'),
        'secondary': value.get('b'),
        'deleted': value.get('c'),
    }
875117
def _get_record_fields(d):
    
    if isinstance(d, dict):
        if "fields" in d:
            return d["fields"]
        else:
            for v in d.values():
                fields = _get_record_fields(v)
                if fields:
                    return fields
221933
def restore_row(self, row, schema):
        
        for index, field in enumerate(schema.fields):
            if field.type == 'datetime':
                row[index] = parse(row[index])
            if field.type == 'date':
                row[index] = parse(row[index]).date()
            if field.type == 'time':
                row[index] = parse(row[index]).time()
        return schema.cast_row(row)
126780
def refetch_fields(self, missing_fields):
        
        db_fields = self.mongokat_collection.find_one({"_id": self["_id"]}, fields={k: 1 for k in missing_fields})

        self._fetched_fields += tuple(missing_fields)

        if not db_fields:
            return

        for k, v in db_fields.items():
            self[k] = v