def convert_descriptor(self, bucket, descriptor, index_fields=[], autoincrement=None):
<EOL>columns = []<EOL>indexes = []<EOL>fallbacks = []<EOL>constraints = []<EOL>column_mapping = {}<EOL>table_name = self.convert_bucket(bucket)<EOL>table_comment = _get_comment(descriptor.get('<STR_LIT:title>', '<STR_LIT>'), descriptor.get('<STR_LIT:description>', '<STR_LIT>'))<EOL>schema = tableschema.Schema(descriptor)<EOL>if autoincrement is not None:<EOL><INDENT>columns.append(sa.Column(<EOL>autoincrement, sa.Integer, autoincrement=True, nullable=False))<EOL><DEDENT>for field in schema.fields:<EOL><INDENT>column_type = self.convert_type(field.type)<EOL>if not column_type:<EOL><INDENT>column_type = sa.Text<EOL>fallbacks.append(field.name)<EOL><DEDENT>nullable = not field.required<EOL>table_comment = _get_field_comment(field)<EOL>unique = field.constraints.get('<STR_LIT>', False)<EOL>column = sa.Column(field.name, column_type, nullable=nullable, comment=table_comment,<EOL>unique=unique)<EOL>columns.append(column)<EOL>column_mapping[field.name] = column<EOL><DEDENT>pk = descriptor.get('<STR_LIT>', None)<EOL>if pk is not None:<EOL><INDENT>if isinstance(pk, six.string_types):<EOL><INDENT>pk = [pk]<EOL><DEDENT><DEDENT>if autoincrement is not None:<EOL><INDENT>if pk is not None:<EOL><INDENT>pk = [autoincrement] + pk<EOL><DEDENT>else:<EOL><INDENT>pk = [autoincrement]<EOL><DEDENT><DEDENT>if pk is not None:<EOL><INDENT>constraint = sa.PrimaryKeyConstraint(*pk)<EOL>constraints.append(constraint)<EOL><DEDENT>if self.__dialect == '<STR_LIT>':<EOL><INDENT>fks = descriptor.get('<STR_LIT>', [])<EOL>for fk in fks:<EOL><INDENT>fields = fk['<STR_LIT>']<EOL>resource = fk['<STR_LIT>']['<STR_LIT>']<EOL>foreign_fields = fk['<STR_LIT>']['<STR_LIT>']<EOL>if isinstance(fields, six.string_types):<EOL><INDENT>fields = [fields]<EOL><DEDENT>if resource != '<STR_LIT>':<EOL><INDENT>table_name = self.convert_bucket(resource)<EOL><DEDENT>if isinstance(foreign_fields, six.string_types):<EOL><INDENT>foreign_fields = [foreign_fields]<EOL><DEDENT>composer = lambda field: '<STR_LIT:.>'.join([table_name, field])<EOL>foreign_fields = list(map(composer, foreign_fields))<EOL>constraint = sa.ForeignKeyConstraint(fields, foreign_fields)<EOL>constraints.append(constraint)<EOL><DEDENT><DEDENT>if self.__dialect == '<STR_LIT>':<EOL><INDENT>for index, index_definition in enumerate(index_fields):<EOL><INDENT>name = table_name + '<STR_LIT>' % index<EOL>index_columns = [column_mapping[field] for field in index_definition]<EOL>indexes.append(sa.Index(name, *index_columns))<EOL><DEDENT><DEDENT>return columns, constraints, indexes, fallbacks, table_comment<EOL>
Convert descriptor to SQL