test_encoding.py 2.0 KB

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