tudfInt.h 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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_TUDF_INT_H
#define TDENGINE_TUDF_INT_H
#ifdef __cplusplus
extern "C" {
#endif

S
shenglian zhou 已提交
22 23 24
//TODO replaces them with fnDebug
//#define debugPrint(...) taosPrintLog("Function", DEBUG_INFO,  135, __VA_ARGS__)
#define debugPrint(...) {fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n");}
25 26 27 28 29 30 31
enum {
  UDF_TASK_SETUP = 0,
  UDF_TASK_CALL = 1,
  UDF_TASK_TEARDOWN = 2

};

S
shenglian zhou 已提交
32
enum {
33 34
  TSDB_UDF_CALL_AGG_INIT = 0,
  TSDB_UDF_CALL_AGG_PROC,
S
slzhou 已提交
35
  TSDB_UDF_CALL_AGG_MERGE,
36
  TSDB_UDF_CALL_AGG_FIN,
S
shenglian zhou 已提交
37 38 39
  TSDB_UDF_CALL_SCALA_PROC,
};

40
typedef struct SUdfSetupRequest {
S
shenglian zhou 已提交
41 42
  char udfName[TSDB_FUNC_NAME_LEN];
  SEpSet epSet;
43 44 45 46 47 48 49 50
} SUdfSetupRequest;

typedef struct SUdfSetupResponse {
  int64_t udfHandle;
} SUdfSetupResponse;

typedef struct SUdfCallRequest {
  int64_t udfHandle;
S
shenglian zhou 已提交
51
  int8_t callType;
52

53
  SSDataBlock block;
S
shenglian zhou 已提交
54
  SUdfInterBuf interBuf;
55
  SUdfInterBuf interBuf2;
56
  int8_t initFirst;
57 58 59
} SUdfCallRequest;

typedef struct SUdfCallResponse {
60 61
  int8_t callType;
  SSDataBlock resultData;
S
slzhou 已提交
62
  SUdfInterBuf resultBuf;
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
} SUdfCallResponse;


typedef struct SUdfTeardownRequest {
  int64_t udfHandle;
} SUdfTeardownRequest;


typedef struct SUdfTeardownResponse {
} SUdfTeardownResponse;

typedef struct SUdfRequest {
  int32_t msgLen;
  int64_t seqNum;

  int8_t type;
S
shenglian zhou 已提交
79 80 81 82 83
  union {
    SUdfSetupRequest setup;
    SUdfCallRequest call;
    SUdfTeardownRequest teardown;
  };
84 85 86 87 88 89 90 91
} SUdfRequest;

typedef struct SUdfResponse {
  int32_t msgLen;
  int64_t seqNum;

  int8_t type;
  int32_t code;
S
shenglian zhou 已提交
92 93 94 95 96
  union {
    SUdfSetupResponse setupRsp;
    SUdfCallResponse callRsp;
    SUdfTeardownResponse teardownRsp;
  };
97 98
} SUdfResponse;

99 100 101 102 103
int32_t encodeUdfRequest(void **buf, const SUdfRequest* request);
void* decodeUdfRequest(const void *buf, SUdfRequest* request);

int32_t encodeUdfResponse(void **buf, const SUdfResponse *response);
void* decodeUdfResponse(const void* buf, SUdfResponse *response);
104

S
shenglian zhou 已提交
105 106 107 108
void freeUdfColumnData(SUdfColumnData *data);
void freeUdfColumn(SUdfColumn* col);
void freeUdfDataDataBlock(SUdfDataBlock *block);

S
slzhou 已提交
109 110 111
int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock);
int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block);

112 113 114 115 116
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TUDF_INT_H