Ejemplo n.º 1
0
 def test_convert_with_field_string_with_max_len(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name,
          'type': ['null', 'string'],
          'default': None,
          AvroMetaDataKeys.MAX_LEN: 16},
         SQLColumn(self.col_name, redshift_types.RedshiftVarChar(32))
     )
Ejemplo n.º 2
0
 def test_convert_bytes_field_with_exceeded_max_len(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name,
          'type': ['null', 'bytes'],
          'default': None,
          AvroMetaDataKeys.MAX_LEN: 65536},
         SQLColumn(self.col_name, redshift_types.RedshiftVarChar(65535))
     )
Ejemplo n.º 3
0
 def test_get_column_def_sql_with_string_type(self, migration):
     column = SQLColumn(
         'foo',
         data_types.RedshiftVarChar(256),
         attributes=[SQLAttribute.create_with_value('attr', '')],
         aliases='bar')
     expected = 'foo varchar(256) attr \'\''
     actual = migration.get_column_def_sql(column)
     assert expected == actual
    def _convert_string_type(self, field, char_bytes=CHAR_BYTES):
        """Only supports char and varchar. If neither fix_len nor max_len
        is specified, an exception is thrown.
        """
        fix_len = field.props.get(AvroMetaDataKeys.FIX_LEN)
        if fix_len:
            # Columns with a CHAR data type only accept single-byte UTF-8
            # characters. This means we can't support char columns since they
            # will not be able to accept multibyte chars. We can instead use
            # VARCHAR columns, which accept multibyte UTF-8 characters.
            return redshift_data_types.RedshiftVarChar(fix_len)

        max_len = field.props.get(AvroMetaDataKeys.MAX_LEN)
        if max_len:
            return redshift_data_types.RedshiftVarChar(
                min(int(max_len) * char_bytes, self.MAX_VARCHAR_BYTES))

        raise SchemaConversionException(
            "Unable to convert `string` type without metadata {0} or {1}.".
            format(AvroMetaDataKeys.FIX_LEN, AvroMetaDataKeys.MAX_LEN))
 def test_convert_with_col_varchar(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         RedshiftSQLColumn(
             'col_varchar',
             redshift_data_types.RedshiftVarChar(16)
         ),
         {
             'name': 'col_varchar',
             'type': ['null', 'string'],
             'default': None,
             AvroMetaDataKeys.MAX_LEN: 16
         }
     )
Ejemplo n.º 6
0
 def test_convert_with_field_enum(self, converter):
     self._convert_and_assert_with_one_column(
         converter,
         {'name': self.col_name,
          'type': {
              'type': 'enum',
              'name': self.col_name,
              'symbols': ['1', '123', '12']}
          },
         SQLColumn(
             self.col_name,
             redshift_types.RedshiftVarChar(3),
             is_nullable=False
         ),
     )
 def _convert_enum_type(self, field):
     max_symbol_len = max(len(symbol) for symbol in field.symbols)
     return redshift_data_types.RedshiftVarChar(
         min(max_symbol_len, self.MAX_VARCHAR_BYTES))
Ejemplo n.º 8
0
 def same_col(self):
     return SQLColumn('same_col', data_types.RedshiftVarChar(64))