Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions e6data_python_connector/datainputstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ def read_values_from_array(query_columns_description: list, dis: DataInputStream
try:
if dtype == "LONG":
value_array.append(dis.read_long())
elif dtype == "INTERVAL_DAY_SECOND":
value_array.append(timedelta(microseconds=dis.read_long()))
elif dtype == "DATE":
value_array.append(format_iso_date_from_epoch_micros(dis.read_long()))
elif dtype == "DATETIME":
Expand Down Expand Up @@ -582,6 +584,15 @@ def get_column_from_chunk(vector: Vector, strict=False) -> list:
continue
value_array.append(vector.data.int64Data.data[
row] if not vector.isConstantVector else vector.data.numericConstantData.data)
elif d_type == VectorType.INTERVAL_DAY_SECOND:
for row in range(vector.size):
if get_null(vector, row):
value_array.append(None)
continue
microseconds = (vector.data.int64Data.data[row]
if not vector.isConstantVector
else vector.data.numericConstantData.data)
value_array.append(timedelta(microseconds=microseconds))
elif d_type == VectorType.DATE:
# Use the JDBC-parity formatter so years > 9999 emit "+YYYYY-MM-DD"
# instead of raising. Per-row try/except keeps a single bad value
Expand Down
3 changes: 3 additions & 0 deletions e6data_python_connector/e6x_vector/ttypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion e6x_vector.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enum VectorType
ARRAY,
NULL,
TIMESTAMP_TZ,
DECIMAL128
DECIMAL128,
INTERVAL_DAY_SECOND
}

struct Vector
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import setuptools

VERSION = (3, 0, 1,)
VERSION = (3, 0, 2,)


def get_long_desc():
Expand Down
24 changes: 23 additions & 1 deletion test/unit/test_binary_decoder_contract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Binary decoding contracts using real bytes, Thrift structs and protocols."""
import io
import struct
from datetime import datetime
from datetime import datetime, timedelta
from decimal import Decimal, localcontext

import pytest
Expand Down Expand Up @@ -87,6 +87,28 @@ def test_int96_row_encoding_uses_julian_day_and_nanoseconds():
assert decoder.read_values_from_array([field],decoder.DataInputStream(io.BytesIO(payload)))==[expected]


def test_interval_day_second_row_and_vector_decoding():
assert getattr(wire.VectorType, 'INTERVAL_DAY_SECOND', None) == 17

field=decoder.FieldInfo('elapsed','INTERVAL_DAY_SECOND','','')
payload=b'\x01'+struct.pack('>q',86_400_000_001)
assert decoder.read_values_from_array([field],decoder.DataInputStream(io.BytesIO(payload)))==[
timedelta(days=1,microseconds=1)]

vector=wire.Vector(3,wire.VectorType.INTERVAL_DAY_SECOND,[False,False,True],
wire.Data(int64Data=wire.Int64Data([86_400_000_001,-1,0])),False)
assert decoder.get_column_from_chunk(vector)==[
timedelta(days=1,microseconds=1),timedelta(microseconds=-1),None]

constant=wire.Vector(2,wire.VectorType.INTERVAL_DAY_SECOND,[False],
wire.Data(numericConstantData=wire.NumericConstantData(-10_000)),True)
assert decoder.get_column_from_chunk(constant)==[timedelta(microseconds=-10_000)]*2

zero=wire.Vector(1,wire.VectorType.INTERVAL_DAY_SECOND,[False],
wire.Data(numericConstantData=wire.NumericConstantData(0)),True)
assert decoder.get_column_from_chunk(zero)==[timedelta(0)]


VECTOR_CASES=[
(wire.VectorType.LONG,'int64Data',wire.Int64Data,'numericConstantData',wire.NumericConstantData,42,42),
(wire.VectorType.INTEGER,'int32Data',wire.Int32Data,'numericConstantData',wire.NumericConstantData,-2,-2),
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_vector_wire_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ def test_truncated_thrift_struct_is_rejected(protocol):


def test_vector_enum_name_mapping_is_bijective():
assert len(wire.VectorType._VALUES_TO_NAMES) == 17
assert len(wire.VectorType._VALUES_TO_NAMES) == 18
for value, name in wire.VectorType._VALUES_TO_NAMES.items():
assert wire.VectorType._NAMES_TO_VALUES[name] == value
Loading