* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ---------------------------------------------------------------------------------------
*
* vsonicarray.h
* Routines to handle Sonic datum array.
* SonicDatumArray is the base class to store data and flag.
*
* IDENTIFICATION
* src/include/vectorsonic/vsonicarray.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_
#define SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_
#include "vecexecutor/vechashjoin.h"
#include "vecexecutor/vechashtable.h"
#include "vecexecutor/vecexecutor.h"
#include "vecexecutor/vectorbatch.inl"
#include "postgres.h"
#include "knl/knl_variable.h"
#include "executor/executor.h"
#include "commands/explain.h"
#include "utils/anls_opt.h"
#include "utils/biginteger.h"
#include "utils/builtins.h"
#include "utils/numeric.h"
#include "miscadmin.h"
#include "vecexecutor/vecexpression.h"
#include "fmgr.h"
#include "foreign/fdwapi.h"
#include "tcop/utility.h"
#include "utils/bloom_filter.h"
#include "utils/lsyscache.h"
struct atom {
char* data;
char* nullFlag;
};
struct DatumDesc {
Oid typeId;
int typeMod;
int typeSize;
int dataType;
DatumDesc()
{
typeId = InvalidOid;
typeMod = -1;
typeSize = 0;
dataType = 0;
};
};
#pragma pack(1)
struct n1pack {
uint8 scale;
uint8 val;
};
struct n2pack {
uint8 scale;
uint16 val;
};
struct n4pack {
uint8 scale;
uint32 val;
};
struct n8pack {
uint8 scale;
uint64 val;
};
#pragma pack()
struct ArrayIdx {
int arrIdx;
int16 atomIdx;
};
#define INIT_ARR_CONTAINER_SIZE 16
#define MAX_DIC_ENCODE_ITEMS 256
#define INIT_DATUM_ARRAY_SIZE (16 * 1024)
#define SONIC_INT_TYPE 0
#define SONIC_FIXLEN_TYPE 1
#define SONIC_CHAR_DIC_TYPE 2
#define SONIC_VAR_TYPE 3
#define SONIC_NUMERIC_COMPRESS_TYPE 4
#define SONIC_TOTAL_TYPES 5
#define getArrayIndx(nth, nbit) (nth >> (nbit))
#define getArrayLoc(nth, mask) (nth & (unsigned int)(mask))
class SonicDatumArray : public BaseObject {
public:
SonicDatumArray(MemoryContext cxt, int capacity);
virtual ~SonicDatumArray()
{}
MemoryContext m_cxt;
DatumDesc m_desc;
bool m_nullFlag;
int m_arrSize;
const uint32 m_atomSize;
int m_atomTypeSize;
const uint32 m_nbit;
atom** m_arr;
atom* m_curAtom;
int m_arrIdx;
int m_atomIdx;
char* m_curData;
uint8* m_curFlag;
public:
virtual void genNewArray(bool genBitMap);
void putArray(ScalarValue* vals, uint8* flag, int rows);
void loadArrayByRow(void* file);
void loadArray(void* file, int64 rows);
int64 getRows();
FORCE_INLINE
uint8 getNthNullFlag(int arrIdx, int atomIdx)
{
return m_arr[arrIdx]->nullFlag[atomIdx];
}
void getNthDatumFlag(uint32 nth, ScalarValue* val, uint8* toflag);
Datum getNthDatum(uint32 nth);
void getArrayAtomIdx(int nrows, uint32* locs, ArrayIdx* arrayIdx);
ScalarValue replaceVariable(ScalarValue oldVal, ScalarValue val);
FORCE_INLINE
void setNthNullFlag(uint32 nth, bool isNull)
{
int arrIdx;
int atomIdx;
arrIdx = getArrayIndx(nth, m_nbit);
atomIdx = getArrayLoc(nth, m_atomSize - 1);
m_arr[arrIdx]->nullFlag[atomIdx] = isNull;
}
FORCE_INLINE
void setNthNullFlag(int arrIdx, int atomIdx, bool isNull)
{
m_arr[arrIdx]->nullFlag[atomIdx] = isNull;
}
virtual void setNthDatum(uint32 nth, ScalarValue* val)
{
Assert(false);
}
virtual void setValue(ScalarValue val, bool isNull, int arrIndx, int atomIndx)
{
Assert(false);
}
virtual void getDatumArray(int nrows, int* arrayIdx, int* atomIdx, Datum* data)
{
Assert(false);
}
virtual void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag)
{
Assert(false);
}
virtual void getDatumFlagArrayWithMatch(
int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx)
{
Assert(false);
}
virtual size_t flushDatumFlagArrayByRow(
int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows)
{
return 0;
}
virtual size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows)
{
return 0;
}
virtual void loadIntValArray(void* file, int nrows)
{
Assert(false);
}
virtual void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows)
{
Assert(false);
}
virtual void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* toflag)
{
Assert(false);
}
private:
void putNullFlagArray(uint8* flag, int rows);
virtual void loadDatumFlagArray(void* file, int rows)
{
Assert(false);
}
virtual void loadDatumFlagArrayByRow(void* file, int leftrows)
{
Assert(false);
}
virtual Datum getDatum(int arrIdx, int atomIdx)
{
Assert(false);
return 0;
}
};
extern int getDataMinLen(Oid typeOid, int typeMod);
extern void getDataDesc(DatumDesc* desc, int typeSize, Form_pg_attribute attr, bool isHashKey);
#endif