def compile(self): from ibis.expr.api import schema buf = StringIO() buf.write(self._create_line()) def _push_schema(x): formatted = format_schema(x) buf.write('{0}'.format(formatted)) if self.partition is not None: modified_schema = [] partition_schema = [] for name, dtype in zip(self.schema.names, self.schema.types): if name in self.partition: partition_schema.append((name, dtype)) else: modified_schema.append((name, dtype)) buf.write('\n') _push_schema(schema(modified_schema)) buf.write('\nPARTITIONED BY ') _push_schema(schema(partition_schema)) else: buf.write('\n') _push_schema(self.schema) format_ddl = self.table_format.to_ddl() if format_ddl: buf.write(format_ddl) buf.write(self._location()) return buf.getvalue()
def compile(self): from ibis.expr.api import schema buf = BytesIO() buf.write(self._create_line()) def _push_schema(x): formatted = format_schema(x) buf.write('{0}'.format(formatted)) if self.partition is not None: modified_schema = [] partition_schema = [] for name, dtype in zip(self.schema.names, self.schema.types): if name in self.partition: partition_schema.append((name, dtype)) else: modified_schema.append((name, dtype)) buf.write('\n') _push_schema(schema(modified_schema)) buf.write('\nPARTITIONED BY ') _push_schema(schema(partition_schema)) else: buf.write('\n') _push_schema(self.schema) format_ddl = self.table_format.to_ddl() if format_ddl: buf.write(format_ddl) buf.write(self._location()) return buf.getvalue()
def pandas_to_ibis_schema(frame): from ibis.expr.api import schema # no analog for decimal in pandas pairs = [] for col_name in frame: ibis_type = pandas_col_to_ibis_type(frame[col_name]) pairs.append((col_name, ibis_type)) return schema(pairs)
def test_column_relabel(table): # GH #551. Keeping the test case very high level to not presume that # the relabel is necessarily implemented using a projection types = ['int32', 'string', 'double'] table = api.table(zip(['foo', 'bar', 'baz'], types)) result = table.relabel({'foo': 'one', 'baz': 'three'}) schema = result.schema() ex_schema = api.schema(zip(['one', 'bar', 'three'], types)) assert_equal(schema, ex_schema)
def test_column_relabel(self): # GH #551. Keeping the test case very high level to not presume that # the relabel is necessarily implemented using a projection types = ['int32', 'string', 'double'] table = api.table(zip(['foo', 'bar', 'baz'], types)) result = table.relabel({'foo': 'one', 'baz': 'three'}) schema = result.schema() ex_schema = api.schema(zip(['one', 'bar', 'three'], types)) assert_equal(schema, ex_schema)
def schema_kudu_to_ibis(kschema, drop_nn=False): ibis_types = [] for i in range(len(kschema)): col = kschema[i] typeclass = _kudu_type_to_ibis_typeclass[col.type.name] if drop_nn: # For testing, because Impala does not have nullable types itype = typeclass(True) else: itype = typeclass(col.nullable) ibis_types.append((col.name, itype)) return schema(ibis_types)