Skip to content

Commit

Permalink
changed columnar iterator interface to single-call
Browse files Browse the repository at this point in the history
  • Loading branch information
glookka committed Apr 2, 2023
1 parent 8171c1a commit 5ccffa0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 78 deletions.
41 changes: 14 additions & 27 deletions columnar/accessor/accessorbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,52 +182,39 @@ class Iterator_Bool_c : public Iterator_i, public Accessor_Bool_c
using BASE::Accessor_Bool_c;

public:
uint32_t AdvanceTo ( uint32_t tRowID ) final { return DoAdvance(tRowID); }
int64_t Get() final { return DoGet(); }

int64_t Get ( uint32_t tRowID ) final { return DoGet(tRowID); }
void Fetch ( const Span_T<uint32_t> & dRowIDs, Span_T<int64_t> & dValues ) final;

int Get ( const uint8_t * & pData ) final { assert ( 0 && "INTERNAL ERROR: requesting blob from bool iterator" ); return 0; }
uint8_t * GetPacked() final { assert ( 0 && "INTERNAL ERROR: requesting blob from bool iterator" ); return nullptr; }
int GetLength() final { assert ( 0 && "INTERNAL ERROR: requesting string length from bool iterator" ); return 0; }
int Get ( uint32_t tRowID, const uint8_t * & pData ) final { assert ( 0 && "INTERNAL ERROR: requesting blob from bool iterator" ); return 0; }
uint8_t * GetPacked ( uint32_t tRowID ) final { assert ( 0 && "INTERNAL ERROR: requesting blob from bool iterator" ); return nullptr; }
int GetLength ( uint32_t tRowID ) final { assert ( 0 && "INTERNAL ERROR: requesting string length from bool iterator" ); return 0; }

void AddDesc ( std::vector<IteratorDesc_t> & dDesc ) const override { dDesc.push_back ( { m_tHeader.GetName(), "iterator" } ); };

private:
FORCE_INLINE uint32_t DoAdvance ( uint32_t tRowID );
FORCE_INLINE int64_t DoGet();
FORCE_INLINE int64_t DoGet ( uint32_t tRowID );
};


uint32_t Iterator_Bool_c::DoAdvance ( uint32_t tRowID )
{
assert ( tRowID < BASE::m_tHeader.GetNumDocs() );

uint32_t uBlockId = RowId2BlockId(tRowID);
if ( uBlockId!=BASE::m_uBlockId )
BASE::SetCurBlock(uBlockId);

BASE::m_tRequestedRowID = tRowID;

return tRowID;
}


void Iterator_Bool_c::Fetch ( const Span_T<uint32_t> & dRowIDs, Span_T<int64_t> & dValues )
{
uint32_t * pRowID = dRowIDs.begin();
uint32_t * pRowIDEnd = dRowIDs.end();
int64_t * pValue = dValues.begin();
while ( pRowID<pRowIDEnd )
{
DoAdvance ( *pRowID++ );
*pValue++ = DoGet();
}
*pValue++ = DoGet ( *pRowID++ );
}


int64_t Iterator_Bool_c::DoGet()
int64_t Iterator_Bool_c::DoGet ( uint32_t tRowID )
{
assert ( tRowID < BASE::m_tHeader.GetNumDocs() );

uint32_t uBlockId = RowId2BlockId(tRowID);
if ( uBlockId!=BASE::m_uBlockId )
BASE::SetCurBlock(uBlockId);

BASE::m_tRequestedRowID = tRowID;
assert ( BASE::m_fnReadValue );
return (*this.*BASE::m_fnReadValue)();
}
Expand Down
26 changes: 7 additions & 19 deletions columnar/accessor/accessorint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,17 @@ class Iterator_INT_T : public Iterator_i, public Accessor_INT_T<T>
using BASE::Accessor_INT_T;

public:
uint32_t AdvanceTo ( uint32_t tRowID ) final { return DoAdvance(tRowID); }
int64_t Get() final { return DoGet(); }

int64_t Get ( uint32_t tRowID ) final { return DoGet(tRowID); }
void Fetch ( const Span_T<uint32_t> & dRowIDs, Span_T<int64_t> & dValues ) final;

int Get ( const uint8_t * & pData ) final { assert ( 0 && "INTERNAL ERROR: requesting blob from int iterator" ); return 0; }
uint8_t * GetPacked() final { assert ( 0 && "INTERNAL ERROR: requesting blob from int iterator" ); return nullptr; }
int GetLength() final { assert ( 0 && "INTERNAL ERROR: requesting blob length from int iterator" ); return 0; }
int Get ( uint32_t tRowID, const uint8_t * & pData ) final { assert ( 0 && "INTERNAL ERROR: requesting blob from int iterator" ); return 0; }
uint8_t * GetPacked ( uint32_t tRowID ) final { assert ( 0 && "INTERNAL ERROR: requesting blob from int iterator" ); return nullptr; }
int GetLength ( uint32_t tRowID ) final { assert ( 0 && "INTERNAL ERROR: requesting blob length from int iterator" ); return 0; }

void AddDesc ( std::vector<IteratorDesc_t> & dDesc ) const override { dDesc.push_back ( { BASE::m_tHeader.GetName(), "iterator" } ); };

private:
FORCE_INLINE uint32_t DoAdvance ( uint32_t tRowID );
FORCE_INLINE int64_t DoGet();
FORCE_INLINE int64_t DoGet ( uint32_t tRowID );
};

template<typename T>
Expand All @@ -417,14 +414,11 @@ void Iterator_INT_T<T>::Fetch ( const Span_T<uint32_t> & dRowIDs, Span_T<int64_t
uint32_t * pRowIDEnd = dRowIDs.end();
int64_t * pValue = dValues.begin();
while ( pRowID<pRowIDEnd )
{
DoAdvance ( *pRowID++ );
*pValue++ = DoGet();
}
*pValue++ = DoGet ( *pRowID++ );
}

template<typename T>
uint32_t Iterator_INT_T<T>::DoAdvance ( uint32_t tRowID )
int64_t Iterator_INT_T<T>::DoGet ( uint32_t tRowID )
{
assert ( tRowID < BASE::m_tHeader.GetNumDocs() );

Expand All @@ -434,12 +428,6 @@ uint32_t Iterator_INT_T<T>::DoAdvance ( uint32_t tRowID )

BASE::m_tRequestedRowID = tRowID;

return tRowID;
}

template<typename T>
int64_t Iterator_INT_T<T>::DoGet()
{
assert ( BASE::m_fnReadValue );
return (*this.*BASE::m_fnReadValue)();
}
Expand Down
32 changes: 20 additions & 12 deletions columnar/accessor/accessormva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,34 +587,38 @@ class Iterator_MVA_T : public Iterator_i, public Accessor_MVA_T<T>
using BASE::Accessor_MVA_T;

public:
uint32_t AdvanceTo ( uint32_t tRowID ) final;

int64_t Get() final { assert ( 0 && "INTERNAL ERROR: requesting int from MVA iterator" ); return 0; }
int64_t Get ( uint32_t tRowID ) final { assert ( 0 && "INTERNAL ERROR: requesting int from MVA iterator" ); return 0; }
void Fetch ( const Span_T<uint32_t> & dRowIDs, Span_T<int64_t> & dValues ) final { assert ( 0 && "INTERNAL ERROR: requesting batch int from MVA iterator" ); }
int Get ( const uint8_t * & pData ) final;
uint8_t * GetPacked() final;
int GetLength() final;
int Get ( uint32_t tRowID, const uint8_t * & pData ) final;
uint8_t * GetPacked ( uint32_t tRowID ) final;
int GetLength ( uint32_t tRowID ) final;

void AddDesc ( std::vector<IteratorDesc_t> & dDesc ) const final { dDesc.push_back ( { BASE::m_tHeader.GetName(), "iterator" } ); }

private:
FORCE_INLINE void AdvanceTo ( uint32_t tRowID );
};

template <typename T>
uint32_t Iterator_MVA_T<T>::AdvanceTo ( uint32_t tRowID )
void Iterator_MVA_T<T>::AdvanceTo ( uint32_t tRowID )
{
assert ( tRowID < BASE::m_tHeader.GetNumDocs() );

if ( BASE::m_tRequestedRowID==tRowID ) // might happen on GetLength/Get calls
return;

uint32_t uBlockId = RowId2BlockId(tRowID);
if ( uBlockId!=BASE::m_uBlockId )
BASE::SetCurBlock(uBlockId);

BASE::m_tRequestedRowID = tRowID;

return tRowID;
}

template <typename T>
int Iterator_MVA_T<T>::Get ( const uint8_t * & pData )
int Iterator_MVA_T<T>::Get ( uint32_t tRowID, const uint8_t * & pData )
{
AdvanceTo(tRowID);

assert(BASE::m_fnReadValue);
(*this.*BASE::m_fnReadValue)();

Expand All @@ -625,8 +629,10 @@ int Iterator_MVA_T<T>::Get ( const uint8_t * & pData )
}

template <typename T>
uint8_t * Iterator_MVA_T<T>::GetPacked()
uint8_t * Iterator_MVA_T<T>::GetPacked ( uint32_t tRowID )
{
AdvanceTo(tRowID);

assert(BASE::m_fnReadValuePacked);
(*this.*BASE::m_fnReadValuePacked)();

Expand All @@ -638,8 +644,10 @@ uint8_t * Iterator_MVA_T<T>::GetPacked()


template <typename T>
int Iterator_MVA_T<T>::GetLength()
int Iterator_MVA_T<T>::GetLength ( uint32_t tRowID )
{
AdvanceTo(tRowID);

assert(BASE::m_fnGetValueLength);
return (*this.*BASE::m_fnGetValueLength)();
}
Expand Down
30 changes: 18 additions & 12 deletions columnar/accessor/accessorstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,17 @@ class Iterator_String_c : public Iterator_i, public Accessor_String_c
public:
Iterator_String_c ( const AttributeHeader_i & tHeader, FileReader_c * pReader );

uint32_t AdvanceTo ( uint32_t tRowID ) final;
int64_t Get() final { assert ( 0 && "INTERNAL ERROR: requesting int from string iterator" ); return 0; }
int64_t Get ( uint32_t tRowID ) final { assert ( 0 && "INTERNAL ERROR: requesting int from string iterator" ); return 0; }
void Fetch ( const Span_T<uint32_t> & dRowIDs, Span_T<int64_t> & dValues ) final { assert ( 0 && "INTERNAL ERROR: requesting batch int from string iterator" ); }

int Get ( const uint8_t * & pData ) final;
uint8_t * GetPacked() final;
int GetLength() final;
int Get ( uint32_t tRowID, const uint8_t * & pData ) final;
uint8_t * GetPacked ( uint32_t tRowID ) final;
int GetLength ( uint32_t tRowID ) final;

void AddDesc ( std::vector<IteratorDesc_t> & dDesc ) const final { dDesc.push_back ( { BASE::m_tHeader.GetName(), "iterator" } ); }

private:
FORCE_INLINE void AdvanceTo ( uint32_t tRowID );
};


Expand All @@ -527,25 +529,25 @@ Iterator_String_c::Iterator_String_c ( const AttributeHeader_i & tHeader, FileRe
{}


uint32_t Iterator_String_c::AdvanceTo ( uint32_t tRowID )
void Iterator_String_c::AdvanceTo ( uint32_t tRowID )
{
assert ( tRowID < BASE::m_tHeader.GetNumDocs() );

if ( m_tRequestedRowID==tRowID ) // might happen on GetLength/Get calls
return tRowID;
return;

uint32_t uBlockId = RowId2BlockId(tRowID);
if ( uBlockId!=m_uBlockId )
SetCurBlock(uBlockId);

m_tRequestedRowID = tRowID;

return tRowID;
}


int Iterator_String_c::Get ( const uint8_t * & pData )
int Iterator_String_c::Get ( uint32_t tRowID, const uint8_t * & pData )
{
AdvanceTo(tRowID);

assert(m_fnReadValue);
(*this.*m_fnReadValue)();

Expand All @@ -557,8 +559,10 @@ int Iterator_String_c::Get ( const uint8_t * & pData )
}


uint8_t * Iterator_String_c::GetPacked()
uint8_t * Iterator_String_c::GetPacked ( uint32_t tRowID )
{
AdvanceTo(tRowID);

assert(m_fnReadValuePacked);
(*this.*m_fnReadValuePacked)();

Expand All @@ -569,8 +573,10 @@ uint8_t * Iterator_String_c::GetPacked()
}


int Iterator_String_c::GetLength()
int Iterator_String_c::GetLength ( uint32_t tRowID )
{
AdvanceTo(tRowID);

assert(m_fnGetValueLength);
return (*this.*m_fnGetValueLength)();
}
Expand Down
13 changes: 5 additions & 8 deletions columnar/columnar.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ namespace util
namespace columnar
{

static const int LIB_VERSION = 20;
static const int LIB_VERSION = 21;

class Iterator_i
{
public:
virtual ~Iterator_i() = default;

virtual uint32_t AdvanceTo ( uint32_t tRowID ) = 0;

virtual int64_t Get() = 0;

virtual int64_t Get ( uint32_t tRowID ) = 0;
virtual void Fetch ( const util::Span_T<uint32_t> & dRowIDs, util::Span_T<int64_t> & dValues ) = 0;

virtual int Get ( const uint8_t * & pData ) = 0;
virtual uint8_t * GetPacked() = 0;
virtual int GetLength() = 0;
virtual int Get ( uint32_t tRowID, const uint8_t * & pData ) = 0;
virtual uint8_t * GetPacked ( uint32_t tRowID ) = 0;
virtual int GetLength ( uint32_t tRowID ) = 0;

virtual void AddDesc ( std::vector<common::IteratorDesc_t> & dDesc ) const = 0;
};
Expand Down

0 comments on commit 5ccffa0

Please sign in to comment.