Rate This Document
Findability
Accuracy
Completeness
Readability

offlineCalculate

Generates bucket data on the server for fast online query.

int offlineCalculate(
    DG_TeeCtx *dgTeeCtx,
    DG_TeeInput *input,
    DG_Buckets **buckets
)

Parameters

Parameter

Description

Value Range

Input/Output

dgTeeCtx

MPC context

Context initialized in section DG_InitPsmOpts.

Input

input

Input data

-

Input

buckets

Bucket data generated

-

Output

Table 1 DG_TeeInput structure

Member

Type

Description

data

DG_MpcDataUnion

The types of the input data strings, doubleNumbers, and u64Numbers are respectively DG_String *, double *, and u64 *.

size

uint64_t

Data volume

dataType

DG_MpcDataType

The enumerated data type is as follows:

MPC_STRING (PSM query)

Table 2 DG_MpcDataUnion

Member

Type

Description

strings

DG_String

String array

u64Numbers

u64

u64 array

doubleNumbers

double

Double array

Return Values

  • Success: 0 is returned.
  • Failure: The error code is returned.

Error Codes

Error Code

Value

Description

Remarks

DG_SUCCESS

0

Success

None.

DG_FAILURE

1

Failure

Failed to add data to the bucket.

DG_ERR_MALLOC_FAIL

51

Memory allocation failure

None.

DG_ERR_MPC_TEE_INVALID_NODE_INFO

4503

Invalid TEE node information

None.

DG_ERR_MPC_TEE_INVALID_PARAM

4501

Parameter verification failure

dgCfg is null or the dgTeeCtx double pointer is null.

Dependency

  • dgCfg depends on the MPC configuration in section DataGuard APIs for Configuring an Operation Set, and the configured dgCfg is used as the input parameter of this API.
  • psmOpts depends on the successful initialization in section DG_InitPsmOpts of the function group for the PSM operator.
  • #include "data_guard_mpc.h": required header file

Example

#include  "data_guard_mpc.h"
void BuildDgString(std::vector<std::string> &strings, DG_String **dg, unsigned int &size)
{
    size = strings.size();
    DG_String *dgString = new DG_String[strings.size()];
    for (size_t i = 0; i < strings.size(); i++) {
        dgString[i].str = strdup(strings[i].c_str());
        dgString[i].size = strings[i].size() + 1;
    }
    *dg = dgString;
}
DG_TeeInput BuildTeeInput(std::vector<std::string> inputData)
{
    DG_String *dgInput;
    unsigned int size;
    BuildDgString(inputData, &dgInput, size);
    DG_TeeInput dgTeeInput = {};
    dgTeeInput.dataType = MPC_STRING;
    dgTeeInput.data.strings = dgInput;
    dgTeeInput.size = size;
    return dgTeeInput;
}
DG_Buckets *buckets = nullptr;
DG_TeeInput dgTeeInput = BuildTeeInput("name", "age", "a");
// psmOpts is the result of the successful DG_InitPsmOpts call, and dgTee is the result of the successful initTeeMpcSql call.
rv = psmOpts.OfflineCalculate(nodeCtx, &dgTeeInput, &buckets);
if (rv != 0) {
    return rv;
}

Call the initTeeCtx API using the psmOpts output of the successful DG_InitPsmOpts call.