def test_convert_with_table_metadata(self, converter):
        pkey_col1 = RedshiftSQLColumn(
            'pkey_col_one',
            redshift_data_types.RedshiftInteger(),
            primary_key_order=1,
            sort_key_order=2,
            is_dist_key=True
        )
        pkey_col2 = RedshiftSQLColumn(
            'pkey_col_two',
            redshift_data_types.RedshiftInteger(),
            primary_key_order=2,
            sort_key_order=1
        )
        col = RedshiftSQLColumn('col', redshift_data_types.RedshiftInteger())
        sql_table = RedshiftSQLTable(
            self.table_name, [pkey_col2, pkey_col1, col], diststyle='all'
        )

        expected_schema = {
            'type': 'record',
            'name': self.table_name,
            'namespace': '',
            'fields': [
                {
                    'name': pkey_col2.name,
                    'type': ['null', 'int'],
                    'default': None,
                    AvroMetaDataKeys.PRIMARY_KEY: 2,
                    AvroMetaDataKeys.SORT_KEY: 1
                },
                {
                    'name': pkey_col1.name,
                    'type': ['null', 'int'],
                    'default': None,
                    AvroMetaDataKeys.PRIMARY_KEY: 1,
                    AvroMetaDataKeys.DIST_KEY: True,
                    AvroMetaDataKeys.SORT_KEY: 2
                },
                {
                    'name': col.name,
                    'type': ['null', 'int'],
                    'default': None
                },
            ],
            AvroMetaDataKeys.PRIMARY_KEY: [pkey_col1.name, pkey_col2.name],
            AvroMetaDataKeys.SORT_KEY: [pkey_col2.name, pkey_col1.name],
            AvroMetaDataKeys.DIST_KEY: pkey_col1.name,
            AvroMetaDataKeys.DISTSTYLE: 'all'
        }

        actual_schema = converter.convert(sql_table)
        assert expected_schema == actual_schema
    def test_convert_with_table_namespace_and_aliases(self, converter):
        doc = 'I am doc'
        aliases = ['foo']
        metadata = {
            MetaDataKey.NAMESPACE: self.namespace,
            MetaDataKey.ALIASES: aliases
        }
        col_name = 'col'
        sql_table = RedshiftSQLTable(
            self.table_name,
            [
                RedshiftSQLColumn(
                    col_name, redshift_data_types.RedshiftInteger()
                )
            ],
            doc=doc,
            **metadata
        )

        expected_schema = {
            'type': 'record',
            'name': self.table_name,
            'namespace': self.namespace,
            'fields': [
                {'name': col_name, 'type': ['null', 'int'], 'default': None}
            ],
            'doc': doc,
            'aliases': aliases
        }

        actual_schema = converter.convert(sql_table)
        assert expected_schema == actual_schema
 def test_convert_with_col_integer(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         RedshiftSQLColumn(
             'col_integer', redshift_data_types.RedshiftInteger()
         ),
         {'name': 'col_integer', 'type': ['null', 'int'], 'default': None}
     )
Beispiel #4
0
 def test_convert_with_unsigned_int_column(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name,
          'type': ['null', 'int'],
          'default': None,
          'unsigned': True},
         SQLColumn(self.col_name, redshift_types.RedshiftInteger())
     )
Beispiel #5
0
 def test_convert_with_column_default_value(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name, 'type': ['int', 'null'], 'default': 10},
         SQLColumn(
             self.col_name,
             redshift_types.RedshiftInteger(),
             default_value=10
         )
     )
 def test_convert_with_column_default_value(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         RedshiftSQLColumn(
             'col',
             redshift_data_types.RedshiftInteger(),
             default_value=10
         ),
         {'name': 'col', 'type': ['int', 'null'], 'default': 10}
     )
Beispiel #7
0
 def test_convert_with_non_nullable_without_default_column(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name, 'type': 'int'},
         SQLColumn(
             self.col_name,
             redshift_types.RedshiftInteger(),
             is_nullable=False
         )
     )
Beispiel #8
0
 def test_get_column_def_sql_with_attributes(self, migration):
     attributes = [SQLAttribute('attr_one')]
     column = SQLColumn('foo',
                        data_types.RedshiftInteger(),
                        is_nullable=False,
                        default_value='',
                        attributes=attributes,
                        aliases='bar')
     expected = 'foo integer not null default \'\' attr_one'
     actual = migration.get_column_def_sql(column)
     assert expected == actual
 def test_convert_with_non_nullable_column(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         RedshiftSQLColumn(
             'col',
             redshift_data_types.RedshiftInteger(),
             is_nullable=False,
             default_value=0
         ),
         {'name': 'col', 'type': 'int', 'default': 0}
     )
Beispiel #10
0
 def test_convert_with_column_with_alias(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name, 'type': 'int', 'aliases': ['abc']},
         SQLColumn(
             self.col_name,
             redshift_types.RedshiftInteger(),
             is_nullable=False,
             **{MetaDataKey.ALIASES: ['abc']}
         )
     )
Beispiel #11
0
 def test_convert_with_primary_key_column(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name,
          'type': ['null', 'int'],
          'default': None,
          AvroMetaDataKeys.PRIMARY_KEY: True},
         SQLColumn(
             self.col_name,
             redshift_types.RedshiftInteger(),
             primary_key_order=1
         ),
     )
Beispiel #12
0
 def test_convert_with_composite_primary_keys(self, converter):
     record_schema = {
         'type': 'record',
         'name': self.avro_schema_name,
         'namespace': None,
         'fields': [
             {
                 'name': self.col_name,
                 'type': 'int',
                 AvroMetaDataKeys.PRIMARY_KEY: 2
             },
             {
                 'name': 'bar',
                 'type': 'int',
                 AvroMetaDataKeys.PRIMARY_KEY: 1
             }
         ],
         'doc': 'sample doc',
     }
     expected_column_col = SQLColumn(
         self.col_name,
         redshift_types.RedshiftInteger(),
         is_nullable=False,
         primary_key_order=2
     )
     expected_column_bar = SQLColumn(
         'bar',
         redshift_types.RedshiftInteger(),
         is_nullable=False,
         primary_key_order=1
     )
     expected_table = SQLTable(
         self.avro_schema_name,
         columns=[expected_column_col, expected_column_bar],
         doc=record_schema.get('doc')
     )
     actual_table = converter.convert(record_schema)
     assert expected_table == actual_table
Beispiel #13
0
 def test_convert_with_no_table_metadata(self, converter):
     record_schema = {
         'type': 'record',
         'name': self.avro_schema_name,
         'namespace': None,
         'fields': [{'name': self.col_name, 'type': 'int'}],
         'doc': 'sample doc',
     }
     expected_column = SQLColumn(
         self.col_name,
         redshift_types.RedshiftInteger(),
         is_nullable=False
     )
     expected_table = SQLTable(
         self.avro_schema_name,
         columns=[expected_column],
         doc=record_schema.get('doc')
     )
     actual_table = converter.convert(record_schema)
     assert expected_table == actual_table
Beispiel #14
0
 def test_get_column_def_sql(self, migration):
     column = SQLColumn('foo', data_types.RedshiftInteger())
     expected = 'foo integer'
     actual = migration.get_column_def_sql(column)
     assert expected == actual
Beispiel #15
0
 def random_col(self):
     return SQLColumn('col', data_types.RedshiftInteger())
Beispiel #16
0
 def second_primary_key_column(self):
     return SQLColumn('second_pkey_col',
                      data_types.RedshiftInteger(),
                      primary_key_order=2)
Beispiel #17
0
 def primary_key_column(self):
     return SQLColumn('primary_key_col',
                      data_types.RedshiftInteger(),
                      primary_key_order=1)
 def _convert_int_type(self, field):
     return redshift_data_types.RedshiftInteger()