test_encoding.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import array
  2. import StringIO
  3. import unittest
  4. import parquet.encoding
  5. class TestBitPacked(unittest.TestCase):
  6. def testFromExample(self):
  7. raw_data_in = [0b10001000, 0b11000110, 0b11111010]
  8. encoded_bitstring = array.array('B', raw_data_in).tostring()
  9. fo = StringIO.StringIO(encoded_bitstring)
  10. count = 3 << 1
  11. res = parquet.encoding.read_bitpacked(fo, count, 3)
  12. self.assertEquals(range(8), res)
  13. class TestBitPackedDeprecated(unittest.TestCase):
  14. def testFromExample(self):
  15. encoded_bitstring = array.array('B',
  16. [0b00000101, 0b00111001, 0b01110111])
  17. fo = StringIO.StringIO(encoded_bitstring)
  18. res = parquet.encoding.read_bitpacked_deprecated(fo, 3, 3)
  19. self.assertEquals(range(8), res)
  20. class TestWidthFromMaxInt(unittest.TestCase):
  21. def testWidths(self):
  22. self.assertEquals(0, parquet.encoding.width_from_max_int(0))
  23. self.assertEquals(1, parquet.encoding.width_from_max_int(1))
  24. self.assertEquals(2, parquet.encoding.width_from_max_int(2))
  25. self.assertEquals(2, parquet.encoding.width_from_max_int(3))
  26. self.assertEquals(3, parquet.encoding.width_from_max_int(4))
  27. self.assertEquals(3, parquet.encoding.width_from_max_int(5))
  28. self.assertEquals(3, parquet.encoding.width_from_max_int(6))
  29. self.assertEquals(3, parquet.encoding.width_from_max_int(7))
  30. self.assertEquals(4, parquet.encoding.width_from_max_int(8))
  31. self.assertEquals(4, parquet.encoding.width_from_max_int(15))
  32. self.assertEquals(5, parquet.encoding.width_from_max_int(16))
  33. self.assertEquals(5, parquet.encoding.width_from_max_int(31))
  34. self.assertEquals(6, parquet.encoding.width_from_max_int(32))
  35. self.assertEquals(6, parquet.encoding.width_from_max_int(63))
  36. self.assertEquals(7, parquet.encoding.width_from_max_int(64))
  37. self.assertEquals(7, parquet.encoding.width_from_max_int(127))
  38. self.assertEquals(8, parquet.encoding.width_from_max_int(128))
  39. self.assertEquals(8, parquet.encoding.width_from_max_int(255))