tsort.h 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TDENGINE_TSORT_H
#define TDENGINE_TSORT_H

#ifdef __cplusplus
extern "C" {
#endif

S
common  
Shengliang Guan 已提交
23
#include "tcommon.h"
24 25 26
#include "os.h"

enum {
H
Haojun Liao 已提交
27 28
  SORT_MULTISOURCE_MERGE = 0x1,
  SORT_SINGLESOURCE_SORT = 0x2,
29 30 31 32 33 34 35 36
};

typedef struct SMultiMergeSource {
  int32_t      type;
  int32_t      rowIndex;
  SSDataBlock *pBlock;
} SMultiMergeSource;

wmmhello's avatar
wmmhello 已提交
37
typedef struct SSortSource {
38
  SMultiMergeSource src;
wmmhello's avatar
wmmhello 已提交
39 40 41 42 43 44 45
  union{
    struct{
      SArray*           pageIdList;
      int32_t           pageIndex;
    };
    void             *param;
  };
46

wmmhello's avatar
wmmhello 已提交
47
} SSortSource;
48

49 50 51 52 53 54
typedef struct SMsortComparParam {
  void        **pSources;
  int32_t       numOfSources;
  SArray       *orderInfo;   // SArray<SBlockOrderInfo>
} SMsortComparParam;

55 56 57 58 59 60 61 62 63 64 65
typedef struct SSortHandle SSortHandle;
typedef struct STupleHandle STupleHandle;

typedef SSDataBlock* (*_sort_fetch_block_fn_t)(void* param);
typedef int32_t (*_sort_merge_compar_fn_t)(const void* p1, const void* p2, void* param);

/**
 *
 * @param type
 * @return
 */
66
SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, SArray* pIndexMap, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr);
67 68 69 70 71

/**
 *
 * @param pSortHandle
 */
H
Haojun Liao 已提交
72
void tsortDestroySortHandle(SSortHandle* pSortHandle);
73 74 75 76 77 78

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
79
int32_t tsortOpen(SSortHandle* pHandle);
80 81 82 83 84 85

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
86
int32_t tsortClose(SSortHandle* pHandle);
87 88 89 90 91

/**
 *
 * @return
 */
92
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), void* param);
93 94 95 96 97 98 99

/**
 *
 * @param pHandle
 * @param fp
 * @return
 */
H
Haojun Liao 已提交
100
int32_t tsortSetComparFp(SSortHandle* pHandle, _sort_merge_compar_fn_t fp);
101 102 103 104 105 106 107

/**
 *
 * @param pHandle
 * @param pSource
 * @return success or failed
 */
H
Haojun Liao 已提交
108
int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource);
109 110 111 112 113 114

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
115
STupleHandle* tsortNextTuple(SSortHandle* pHandle);
116 117 118 119

/**
 *
 * @param pHandle
120
 * @param colId
121 122
 * @return
 */
123
bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colId);
124 125 126 127

/**
 *
 * @param pHandle
128
 * @param colId
129 130
 * @return
 */
131 132 133 134 135 136 137 138
void* tsortGetValue(STupleHandle* pVHandle, int32_t colId);

/**
 *
 * @param pSortHandle
 * @return
 */
SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle);
139

140 141 142 143 144 145 146 147
/**
 * return the sort execution information.
 *
 * @param pHandle
 * @return
 */
SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle);

148 149 150 151 152
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TSORT_H