Given a SQLAlchemy Table object, return a Shelf description suitable
    for passing to Shelf.from_config.
967473
def introspect_table(table):
    
    d = {}
    for c in table.columns:
        if isinstance(c.type, String):
            d[c.name] = {'kind': 'Dimension', 'field': c.name}
        if isinstance(c.type, (Integer, Float)):
            d[c.name] = {'kind': 'Metric', 'field': c.name}
    return d
600537
def table_describe(table_name):
    
    desc = orca.get_table(table_name).to_frame().describe()
    return (
        desc.to_json(orient='split', date_format='iso'),
        200,
        {'Content-Type': 'application/json'})
1118774
def DBObject(table_name, versioning=VersioningTypes.NONE):
    """"""
    def wrapped(cls):
        field_names = set()
        all_fields = []

        for name in dir(cls):
            fld = getattr(cls, name)
            if fld and isinstance(fld, Field):
                fld.name = name
                all_fields.append(fld)
                field_names.add(name)

        def add_missing_field(name, default='', insert_pos=None):
            if name not in field_names:
                fld = Field(default=default)
                fld.name = name
                all_fields.insert(
                    len(all_fields) if insert_pos is None else insert_pos,
                    fld
                )

        add_missing_field('id', insert_pos=0)
        add_missing_field('_create_date')
        add_missing_field('_last_update')
        if versioning == VersioningTypes.DELTA_HISTORY:
            add_missing_field('_version_hist', default=list)

        # Things we count on as part of our processing
        cls.__table_name__ = table_name
        cls.__versioning__ = versioning
        cls.__fields__ = all_fields

        # Give them a ctor for free - but make sure we aren't clobbering one
        if not ctor_overridable(cls):
            raise TypeError(
                'Classes with user-supplied __init__ should not be decorated '
                'with DBObject. Use the setup method'
            )
        cls.__init__ = _auto_init

        # Duck-type the class for our data methods
        cls.get_table_name = classmethod(_get_table_name)
        cls.get_id = _get_id
        cls.set_id = _set_id
        cls.to_data = _to_data
        cls.from_data = classmethod(_from_data)
        cls.index_names = classmethod(_index_names)
        cls.indexes = _indexes
        # Bonus methods they get for using gludb.simple
        cls.get_version_hist = _get_version_hist

        # Register with our abc since we actually implement all necessary
        # functionality
        Storable.register(cls)

        # And now that we're registered, we can also get the database
        # read/write functionality for free
        cls = DatabaseEnabled(cls)

        if versioning == VersioningTypes.DELTA_HISTORY:
            cls.save = _delta_save(cls.save)

        return cls

    return wrapped
575745
def sqlalchemy(self, is_top=True):
        """"""
        table_def = self.table_backref_remover.sub('', self.table.__repr__())

        # inject UNIQUE constraints into table definition
        constraint_defs = []
        for constraint in self.table.constraints:
            if isinstance(constraint, sa.sql.schema.UniqueConstraint):
                col_list = ', '.join("'%s'" % c.name
                                     for c in constraint.columns)
                constraint_defs.append('UniqueConstraint(%s)' % col_list)
        if constraint_defs:
            constraint_defs = ',\n  '.join(constraint_defs) + ','
            table_def = table_def.replace('schema=None', '\n  ' + constraint_defs + 'schema=None')

        table_def = table_def.replace("MetaData(bind=None)", "metadata")
        table_def = table_def.replace("Column(", "\n  Column(")
        table_def = table_def.replace("schema=", "\n  schema=")
        result = [table_def, ]
        result.extend(c.sqlalchemy(is_top=False) for c in self.children.values())
        result = "\n%s = %s" % (self.table_name, "\n".join(result))
        if is_top:
            sqla_imports = set(self.capitalized_words.findall(table_def))
            sqla_imports &= set(dir(sa))
            sqla_imports = sorted(sqla_imports)
            result = self.sqlalchemy_setup_template % (
                ", ".join(sqla_imports), result, self.table.name)
            result = textwrap.dedent(result)
        return result
1112509
def table_definitions(self):
        
        prop = self._get_sub_prop("tableDefinitions")
        if prop is not None:
            prop = _from_api_repr_table_defs(prop)
        return prop
991540
def describe_table(self, table: str) -> List[List[Any]]:
        """"""
        return self.flavour.describe_table(self, table)
850291
def restore_descriptor(self, table_name, columns, constraints, autoincrement_column=None):
        

        # Fields
        fields = []
        for column in columns:
            if column.name == autoincrement_column:
                continue
            field_type = self.restore_type(column.type)
            field = {'name': column.name, 'type': field_type}
            if not column.nullable:
                field['constraints'] = {'required': True}
            fields.append(field)

        # Primary key
        pk = []
        for constraint in constraints:
            if isinstance(constraint, sa.PrimaryKeyConstraint):
                for column in constraint.columns:
                    if column.name == autoincrement_column:
                        continue
                    pk.append(column.name)

        # Foreign keys
        fks = []
        if self.__dialect == 'postgresql':
            for constraint in constraints:
                if isinstance(constraint, sa.ForeignKeyConstraint):
                    resource = ''
                    own_fields = []
                    foreign_fields = []
                    for element in constraint.elements:
                        own_fields.append(element.parent.name)
                        if element.column.table.name != table_name:
                            resource = self.restore_bucket(element.column.table.name)
                        foreign_fields.append(element.column.name)
                    if len(own_fields) == len(foreign_fields) == 1:
                        own_fields = own_fields.pop()
                        foreign_fields = foreign_fields.pop()
                    fks.append({
                        'fields': own_fields,
                        'reference': {'resource': resource, 'fields': foreign_fields},
                    })

        # Desscriptor
        descriptor = {}
        descriptor['fields'] = fields
        if len(pk) > 0:
            if len(pk) == 1:
                pk = pk.pop()
            descriptor['primaryKey'] = pk
        if len(fks) > 0:
            descriptor['foreignKeys'] = fks

        return descriptor
691173
def AutomaticShelf(table):
    
    if hasattr(table, '__table__'):
        table = table.__table__
    config = introspect_table(table)
    return Shelf.from_config(config, table)
245955
def describe_table(self, table_name):
        
        data = {'TableName' : table_name}
        json_input = json.dumps(data)
        return self.make_request('DescribeTable', json_input)
587807
def column_describe(table_name, col_name):
    
    col_desc = orca.get_table(table_name).get_column(col_name).describe()
    return (
        col_desc.to_json(orient='split'),
        200,
        {'Content-Type': 'application/json'})
1260499
def describe_table(self, tablename):
        
        try:
            response = self.call(
                'describe_table', TableName=tablename)['Table']
            return Table.from_response(response)
        except DynamoDBError as e:
            if e.kwargs['Code'] == 'ResourceNotFoundException':
                return None
            else:  # pragma: no cover
                raise
514810
def create_table_from_object(self, obj):
        '''
        
        '''
        get_type = lambda item: str(type(item)).split("'")[1]
        if not os.path.exists(os.path.join(self.db_path, obj._TABLE)):
            with gzip.open(os.path.join(self.db_path, obj._TABLE), 'wb') as table_file:
                csv.writer(table_file).writerow(['{col}:{type}'.format(col=elm[0], type=get_type(elm[1]))
                                                 for elm in tuple(obj.__dict__.items())])
            self._tables[obj._TABLE] = self._load_table(obj._TABLE)
209120
def describe_formatted(self, name, database=None):
        
        from ibis.impala.metadata import parse_metadata

        stmt = self._table_command(
            'DESCRIBE FORMATTED', name, database=database
        )
        query = ImpalaQuery(self, stmt)
        result = query.execute()

        # Leave formatting to pandas
        for c in result.columns:
            result[c] = result[c].str.strip()

        return parse_metadata(result)
1025725
def get_database_configuration():
    """"""
    db_config = get_database_config_file()
    if db_config is None:
        return None
    with open(db_config, 'r') as ymlfile:
        cfg = yaml.load(ymlfile)
    return cfg
908255
def make_dict(cls, table):
        """"""
        ret_dict = {}
        for row in table:
            job_details = cls.create_from_row(row)
        ret_dict[job_details.dbkey] = job_details
        return ret_dict
654362
def get_table_description(self, cursor, table_name):
        ""
        # As cursor.description does not return reliably the nullable property,
        # we have to query the information_schema (#7783)
        cursor.execute("""
            SELECT column_name, is_nullable, column_default
            FROM information_schema.columns
            WHERE table_schema = %s and table_name = %s""", [self.connection.schema_name, table_name])
        field_map = {line[0]: line[1:] for line in cursor.fetchall()}
        cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
        return [FieldInfo(*((force_text(line[0]),) + line[1:6] +
                            (field_map[force_text(line[0])][0] == 'YES', field_map[force_text(line[0])][1])))
                for line in cursor.description]
847411
def _build_table(self, info, order, max_col_len=40, only_changed=False):
        

        info_dict, bounds_dict = {}, {}
        (params, val_dict, changed) = info
        col_widths = dict((k,0) for k in order)

        for name, p in params.items():
            if only_changed and not (name in changed):
                continue

            constant = 'C' if p.constant else 'V'
            readonly = 'RO' if p.readonly else 'RW'
            allow_None = ' AN' if hasattr(p, 'allow_None') and p.allow_None else ''

            mode = '%s %s%s' % (constant, readonly, allow_None)
            info_dict[name] = {'name': name, 'type':p.__class__.__name__,
                               'mode':mode}

            if hasattr(p, 'bounds'):
                lbound, ubound = (None,None) if p.bounds is None else p.bounds

                mark_lbound, mark_ubound = False, False
                # Use soft_bounds when bounds not defined.
                if hasattr(p, 'get_soft_bounds'):
                    soft_lbound, soft_ubound = p.get_soft_bounds()
                    if lbound is None and soft_lbound is not None:
                        lbound = soft_lbound
                        mark_lbound = True
                    if ubound is None and soft_ubound is not None:
                        ubound = soft_ubound
                        mark_ubound = True

                if (lbound, ubound) != (None,None):
                    bounds_dict[name] = (mark_lbound, mark_ubound)
                    info_dict[name]['bounds'] = '(%s, %s)' % (lbound, ubound)

            value = repr(val_dict[name])
            if len(value) > (max_col_len - 3):
                value = value[:max_col_len-3] + '...'
            info_dict[name]['value'] = value

            for col in info_dict[name]:
                max_width = max([col_widths[col], len(info_dict[name][col])])
                col_widths[col] = max_width

        return self._tabulate(info_dict, col_widths, changed, order, bounds_dict)