简体   繁体   English

更新aTable设置a,b,c = func(x,y,z,...)

[英]update aTable set a,b,c = func(x,y,z,…)

I need a quick advice how-to. 我需要快速的建议。 I mention that the following scenario is based on the use of c_api available already to my monetdblite compilation on 64bit, intention is to use it with some adhoc C written functions. 我提到以下情况是基于对我的monetdblite编译在64位上已经可用的c_api的使用,其目的是将其与某些即席C编写的函数一起使用。

Short: how can I achieve or simulate the following scenario: update aTable set a,b,c = func(x,y,z,…) 简而言之:如何实现或模拟以下情形: 更新aTable设置a,b,c = func(x,y,z,...)

Long. 长。 Many algorithms are returning more than one variable as, for instance, multiple regression. 许多算法都返回多个变量,例如多元回归。

bool m_regression(IN const double **data, IN const int cols, IN const int rows, OUT double *fit_values, OUT double *residuals, OUT double *std_residuals, OUT double &p_value);

In order to minimize the transfer of data between monetdb and heavy computational function, all those results are generated in one step. 为了最大程度地减少monetdb和繁重的计算功能之间的数据传输,所有这些结果都将一步生成。 Question is how can I transfer them back at once, minimizing computational time and memory traffic between monetdb and external C/C++(/R/Python) function? 问题是如何立即将它们传输回去,以最小化monetdb和外部C / C ++(/ R / Python)函数之间的计算时间和内存流量?


My first thought to solve this is something like this: 我首先想到的解决方案是这样的:

1. update aTable set dummy = func_compute(x,y,z,…) 1.更新表集哑元= func_compute(x,y,z,...)

where dummy is a temporary __int64 field and func_compute will compute all the necessary outputs and store the result into a dummy pointer. 其中dummy是一个临时__int64字段,func_compute将计算所有必需的输出并将结果存储到哑指针中。 To make sure is no issue with constant estimation, first returned value in the array will be the real dummy pointer, the rest just an incremented value of dummy + i; 为了确保常量估计没有问题,数组中的第一个返回值将是真实的虚拟指针,其余的只是虚拟值+ i的递增值;

2. update aTable set a = func_ret(dummy, 1), b= func_ret (dummy, 2), c= func_ret (dummy, 3) [, dummy=func_free(dummy)]; 2.更新表集a = func_ret(dummy,1),b = func_ret(dummy,2),c = func_ret(dummy,3)[,dummy = func_free(dummy)];

Assuming the func_ret will get the dummy in the same order that it was returned on first call, I would just copy the prepared result into provided storage; 假设func_ret将以与第一次调用时返回的顺序相同的方式获取虚拟对象,我将复制准备好的结果到提供的存储中; In case the order is not preserved, I will need an extra step to get the minimum (real dummy pointer), then to use the offset of current value to lookup in my array. 如果不保留顺序,我将需要一个额外的步骤来获取最小值(真实的虚拟指针),然后使用当前值的偏移量在数组中查找。

__int64 real_dummy = __inputs[0][0];

double *my_pointer_data = (double *) (real_dummy + __inputs[1][0] * sizeof(double)* row_count);

memcpy(__outputs[0], my_pointer_data, sizeof(double)* row_count);

// or ============================ //或===========================

__int64 real_dummy = minimum(__inputs[0]);

double *my_pointer_data = (double *) (real_dummy + __inputs[0][1] * sizeof(double)* row_count);

for (int i=0;i<row_count;i++)
   __outputs[0][i] = my_pointer_data[__inputs[0][i] - real_dummy];

It is less relevant how am I going to free the temporary memory, can be in the last statement in update or in a new fake update statement using func_free. 与如何释放临时内存无关紧要,可以在update的最后一条语句中,也可以在使用func_free的新的伪更新语句中释放。 Problem is that it doesn't look to me that, even if I save some computational (big) time, the passing of the dummy is still done 3 times (any chance that memory is actually not copied?). 问题是,即使我节省了一些计算时间(大笔时间),对我来说,伪对象的传递仍然完成了3次(是否真的没有复制内存?)。

Is it any other better way of achieving this? 还有其他更好的方法来实现这一目标吗?

I am not aware of a good way of doing this, sorry. 抱歉,我不知道这样做的好方法。 You could retrieve the table, add your columns as BATs in whichever way you like and write it back. 您可以检索表,以任意方式将列添加为BAT并写回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM