Serialize the state into the min string
| 115 | |
| 116 | // Serialize the state into the min string |
| 117 | BufferVal MinSerialize(FunctionContext* context, const BufferVal& intermediate) { |
| 118 | MinState* state = reinterpret_cast<MinState*>(intermediate); |
| 119 | if (state->value == NULL) return intermediate; |
| 120 | // Hack to persist the intermediate state's value without leaking. |
| 121 | // TODO: revisit BufferVal and design a better way to do this |
| 122 | StringVal copy_buffer(context, state->len); |
| 123 | memcpy(copy_buffer.ptr, state->value, state->len); |
| 124 | context->Free(state->value); |
| 125 | state->value = copy_buffer.ptr; |
| 126 | return intermediate; |
| 127 | } |
| 128 | |
| 129 | // Merge is the same as Update since the serialized format is the raw input format |
| 130 | void MinMerge(FunctionContext* context, const BufferVal& src, BufferVal* dst) { |