MCPcopy Create free account
hub / github.com/apache/arrow / test_store_decimal_as_integer

Function test_store_decimal_as_integer

python/pyarrow/tests/parquet/test_basic.py:406–457  ·  view source on GitHub ↗
(tempdir)

Source from the content-addressed store, hash-verified

404
405
406def test_store_decimal_as_integer(tempdir):
407 arr_decimal_1_9 = pa.array(list(map(Decimal, range(100))),
408 type=pa.decimal128(5, 2))
409 arr_decimal_10_18 = pa.array(list(map(Decimal, range(100))),
410 type=pa.decimal128(16, 9))
411 arr_decimal_gt18 = pa.array(list(map(Decimal, range(100))),
412 type=pa.decimal128(22, 2))
413 arr_bool = pa.array([True, False] * 50)
414 data_decimal = [arr_decimal_1_9, arr_decimal_10_18, arr_decimal_gt18]
415 table = pa.Table.from_arrays(data_decimal, names=['a', 'b', 'c'])
416
417 # Check with store_decimal_as_integer.
418 _check_roundtrip(table,
419 expected=table,
420 compression="gzip",
421 use_dictionary=False,
422 store_decimal_as_integer=True)
423
424 # Check physical type in parquet schema
425 pqtestfile_path = os.path.join(tempdir, 'test.parquet')
426 pq.write_table(table, pqtestfile_path,
427 compression="gzip",
428 use_dictionary=False,
429 store_decimal_as_integer=True)
430
431 pqtestfile = pq.ParquetFile(pqtestfile_path)
432 pqcol_decimal_1_9 = pqtestfile.schema.column(0)
433 pqcol_decimal_10_18 = pqtestfile.schema.column(1)
434
435 assert pqcol_decimal_1_9.physical_type == 'INT32'
436 assert pqcol_decimal_10_18.physical_type == 'INT64'
437
438 # Check with store_decimal_as_integer and delta-int encoding.
439 # DELTA_BINARY_PACKED requires parquet physical type to be INT64 or INT32
440 _check_roundtrip(table,
441 expected=table,
442 compression="gzip",
443 use_dictionary=False,
444 store_decimal_as_integer=True,
445 column_encoding={
446 'a': 'DELTA_BINARY_PACKED',
447 'b': 'DELTA_BINARY_PACKED'
448 })
449
450 # Check with mixed column types.
451 mixed_table = pa.Table.from_arrays(
452 [arr_decimal_1_9, arr_decimal_10_18, arr_decimal_gt18, arr_bool],
453 names=['a', 'b', 'c', 'd'])
454 _check_roundtrip(mixed_table,
455 expected=mixed_table,
456 use_dictionary=False,
457 store_decimal_as_integer=True)
458
459
460def test_column_encoding():

Callers

nothing calls this directly

Calls 7

_check_roundtripFunction · 0.90
listFunction · 0.85
mapFunction · 0.85
arrayMethod · 0.45
joinMethod · 0.45
write_tableMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected