From a given record type, extract type for a given field.
339865
public SemanticType extractFieldType(SemanticType.Record type, Identifier field) {
		if (type == null) {
			return null;
		} else {
			SemanticType fieldType = type.getField(field);
			if (fieldType == null) {
				// Indicates an invalid field selection
				syntaxError(field, INVALID_FIELD);
			}
			return fieldType;
		}
	}
1111539
def _load_records(self, record_type_idstrs):
        """"""
        for record_type_idstr in record_type_idstrs:
            try:
                self._init_record(record_type_idstr)
            except (ImportError, KeyError):
                pass
822530
def _get_field_type(self, key, value):
        
        if isinstance(value, bool):
            return BooleanField(name=key)
        elif isinstance(value, int):
            return IntegerField(name=key)
        elif isinstance(value, float):
            return FloatField(name=key)
        elif isinstance(value, str):
            return StringField(name=key)
        elif isinstance(value, time):
            return TimeField(name=key)
        elif isinstance(value, datetime):
            return DateTimeField(name=key)
        elif isinstance(value, date):
            return DateField(name=key)
        elif isinstance(value, timedelta):
            return TimedeltaField(name=key)
        elif isinstance(value, Enum):
            return EnumField(name=key, enum_class=type(value))
        elif isinstance(value, (dict, BaseDynamicModel, Mapping)):
            return ModelField(name=key, model_class=self.__dynamic_model__ or self.__class__)
        elif isinstance(value, BaseModel):
            return ModelField(name=key, model_class=value.__class__)
        elif isinstance(value, (list, set, ListModel)):
            if not len(value):
                return None
            field_type = self._get_field_type(None, value[0])
            return ArrayField(name=key, field_type=field_type)
        elif value is None:
            return None
        else:
            raise TypeError("Invalid parameter: %s. Type not supported." % (key,))
300389
def from_record(self, record):
        
        kwargs = self.get_field_kwargs(record)
        return self.sequenced_item_class(**kwargs)
1308264
def format(self, record):
        
        if not hasattr(record, "type"):
            record.type = "   "
        return self._formatter.format(record)
854096
def field_type(field):
    
    if hasattr(field, 'field') and field.field:
        return field.field.__class__.__name__.lower()
    return ''
841256
function extract(type) {
			for(var index = 0; index < 3; index++) {
				if (typeof args[index] === type) { return args[index]; }
			}
		}
1094790
def _get_solr_type(self, field):
        
        field_type = 'string'
        try:
            field_type = FIELD_TYPE_CONVERSION_MAP[field]
            return field_type
        except:
            pass
        fta = field.split('_')
        if len(fta) > 1:
            ft = fta[len(fta) - 1]
            try:
                field_type = FIELD_TYPE_CONVERSION_MAP[ft]
                # cache the type so it's used next time
                FIELD_TYPE_CONVERSION_MAP[field] = field_type
            except:
                pass
        return field_type
625749
def _get_record(self, record_type):
        """"""
        if not self.has_record_type(record_type):
            raise errors.Unsupported()
        if str(record_type) not in self._records:
            raise errors.Unimplemented()
        return self._records[str(record_type)]
414553
def from_record(cls, record):
        
        if not isinstance(record, pymarc.Record):
            raise TypeError('record must be of type pymarc.Record')
        record.__class__ = Record
        return record
1266293
def bigquery_field_to_ibis_dtype(field):
    """"""
    typ = field.field_type
    if typ == 'RECORD':
        fields = field.fields
        assert fields, 'RECORD fields are empty'
        names = [el.name for el in fields]
        ibis_types = list(map(dt.dtype, fields))
        ibis_type = dt.Struct(names, ibis_types)
    else:
        ibis_type = _LEGACY_TO_STANDARD.get(typ, typ)
        ibis_type = _DTYPE_TO_IBIS_TYPE.get(ibis_type, ibis_type)
    if field.mode == 'REPEATED':
        ibis_type = dt.Array(ibis_type)
    return ibis_type
929535
def _to_variable_type(x, records):
    
    var_mapping = {"string": "String", "File": "File", "null": "String",
                   "long": "Float", "double": "Float", "int": "Int"}
    if isinstance(x, dict):
        if x["type"] == "record":
            struct_name, records = _record_to_struct(x, records)
            return struct_name, records
        else:
            assert x["type"] == "array", x
            cur_type, records = _to_variable_type(x["items"], records)
            return "Array[%s]" % cur_type, records
    elif isinstance(x, (list, tuple)):
        vars = [v for v in x if v != "null"]
        return var_mapping[vars[0]], records
    else:
        return var_mapping[x], records
722590
def _build_field_type_map(base_class):
    """"""
    mapping = {}

    for cls in _get_recursive_subclasses(base_class):
        if cls.field_type:
            if isinstance(cls.field_type, tuple):
                for field_type in cls.field_type:
                    mapping[field_type] = cls
            elif isinstance(cls.field_type, _string_types):
                mapping[cls.field_type] = cls
            else:
                raise ValueError('Field type must be str or tuple, cannot understand type "{}" on class "{}"'.format(
                    type(cls.field_type),
                    cls
                ))

    return mapping
956357
def restore_type(self, type):
        

        # All dialects
        mapping = {
            ARRAY: 'array',
            sa.Boolean: 'boolean',
            sa.Date: 'date',
            sa.DateTime: 'datetime',
            sa.Float: 'number',
            sa.Integer: 'integer',
            JSONB: 'object',
            JSON: 'object',
            sa.Numeric: 'number',
            sa.Text: 'string',
            sa.Time: 'time',
            sa.VARCHAR: 'string',
            UUID: 'string',
        }

        # Get field type
        field_type = None
        for key, value in mapping.items():
            if isinstance(type, key):
                field_type = value

        # Not supported
        if field_type is None:
            message = 'Type "%s" is not supported'
            raise tableschema.exceptions.StorageError(message % type)

        return field_type
938333
def parse(self):
        """"""

        self.parse_fields()
        records = []
        for line in self.t['data'].split('\n'):
            if EMPTY_ROW.match(line):
                continue
            row = [self.autoconvert(line[start_field:end_field+1])
                   for start_field, end_field in self.fields]
            records.append(tuple(row))
        self.records = records
901709
def _extract_table_type(type):
    
    if isinstance(type, str):
        type = type.lower()
        if type[0:7] == 'binary':
            table_type = BINARY_TBL
        elif type[0:6] == 'ascii':
            table_type = ASCII_TBL
        else:
            raise ValueError(
                "table type string should begin with 'binary' or 'ascii' "
                "(case insensitive)")
    else:
        type = int(type)
        if type not in [BINARY_TBL, ASCII_TBL]:
            raise ValueError(
                "table type num should be BINARY_TBL (%d) or "
                "ASCII_TBL (%d)" % (BINARY_TBL, ASCII_TBL))
        table_type = type

    return table_type
1352997
private static TsType extractOriginalTsType(TsType type) {
        if (type instanceof TsType.OptionalType) {
            return extractOriginalTsType(((TsType.OptionalType)type).type);
        }
        if (type instanceof TsType.UnionType) {
            TsType.UnionType union = (TsType.UnionType)type;
            List<TsType> originalTypes = new ArrayList<>();
            for (TsType curType : union.types) {
                if (isOriginalTsType(curType)) {
                    originalTypes.add(curType);
                }
            }
            return originalTypes.size() == 1
                ? extractOriginalTsType(originalTypes.get(0))
                : type;
        }
        if (type instanceof TsType.BasicArrayType) {
            return extractOriginalTsType(((TsType.BasicArrayType)type).elementType);
        }
        return type;
    }