def schema_from_table(table): # Convert SQLA table to Ibis schema names = table.columns.keys() types = [] for c in table.columns.values(): type_class = type(c.type) if isinstance(c.type, sa.types.NUMERIC): t = dt.Decimal(c.type.precision, c.type.scale, nullable=c.nullable) else: if c.type in _sqla_type_to_ibis: ibis_class = _sqla_type_to_ibis[c.type] elif type_class in _sqla_type_to_ibis: ibis_class = _sqla_type_to_ibis[type_class] elif isinstance(c.type, sa.DateTime): ibis_class = dt.Timestamp() else: for k, v in _sqla_type_to_ibis.items(): if isinstance(c.type, type(k)): ibis_class = v break else: raise NotImplementedError(c.type) t = ibis_class(c.nullable) types.append(t) return dt.Schema(names, types)
def schema_from_table(table): # Convert SQLA table to Ibis schema types = [ sqlalchemy_type_to_ibis_type(column.type, column.nullable) for column in table.columns.values() ] return dt.Schema(table.columns.keys(), types)
def schema_from_table(table): """Retrieve an ibis schema from a SQLAlchemy ``Table``. Parameters ---------- table : sa.Table Returns ------- schema : ibis.expr.datatypes.Schema An ibis schema corresponding to the types of the columns in `table`. """ # Convert SQLA table to Ibis schema types = [ sqlalchemy_type_to_ibis_type( column.type, nullable=column.nullable, default_timezone='UTC', ) for column in table.columns.values() ] return dt.Schema(table.columns.keys(), types)
def get_schema(self, table_name, database=None): """ Return a Schema object for the indicated table and database Parameters ---------- table_name : string May be fully qualified database : string, default None Returns ------- schema : ibis Schema """ qualified_name = self._fully_qualified_name(table_name, database) query = 'DESC {0}'.format(qualified_name) data, _ = self._execute(query) names, types = data[:2] ibis_types = map(clickhouse_to_ibis.get, types) return dt.Schema(names, ibis_types)
def _get_schema_using_query(self, query): _, types = self._execute(query) names, clickhouse_types = zip(*types) ibis_types = map(clickhouse_to_ibis.get, clickhouse_types) return dt.Schema(names, ibis_types)