tudfInt.h 2.5 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_TUDF_INT_H
#define TDENGINE_TUDF_INT_H

#ifdef __cplusplus
extern "C" {
#endif

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

};

S
shenglian zhou 已提交
33 34 35 36 37 38
enum {
  TSDB_UDF_CALL_AGG_PROC = 0,
  TSDb_UDF_CALL_AGG_FIN,
  TSDB_UDF_CALL_SCALA_PROC,
};

39 40 41 42 43 44 45 46 47 48 49 50 51 52
typedef struct SUdfSetupRequest {
  char udfName[16]; //
  int8_t scriptType; // 0:c, 1: lua, 2:js
  int8_t udfType; //udaf, udf
  int16_t pathSize;
  char *path;
} SUdfSetupRequest;

typedef struct SUdfSetupResponse {
  int64_t udfHandle;
} SUdfSetupResponse;

typedef struct SUdfCallRequest {
  int64_t udfHandle;
S
shenglian zhou 已提交
53
  int8_t callType;
54

S
shenglian zhou 已提交
55 56 57
  SUdfDataBlock block;
  SUdfInterBuf interBuf;
  bool initFirst;
58 59 60
} SUdfCallRequest;

typedef struct SUdfCallResponse {
S
shenglian zhou 已提交
61 62
  SUdfColumnData resultData;
  SUdfInterBuf interBuf;
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;

S
shenglian zhou 已提交
99
int32_t decodeRequest(char *buf, int32_t bufLen, SUdfRequest *pRequest);
100
int32_t encodeRequest(char **buf, int32_t *bufLen, SUdfRequest *request);
S
shenglian zhou 已提交
101 102
int32_t decodeResponse(char *buf, int32_t bufLen, SUdfResponse *pResponse);
int32_t encodeResponse(char **buf, int32_t *bufLen, SUdfResponse *response);
103 104 105 106 107 108

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TUDF_INT_H