Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

在分区表中使用移动函数context by添加新列报错

我有一张分区表(不是分布式表),以date,ticker分区(date是第一分区),保存股票的收盘价:

date ticker close


2010.01.04 600151.SH 11.63
2010.01.04 600723.SH 10.849999999999999
2010.01.04 000838.SZ 10.63
2010.01.04 600239.SH 26.879999999999999
2010.01.04 600591.SH 7.230000000000001
2010.01.04 600250.SH 7.34
2010.01.04 600460.SH 12.4
2010.01.04 600664.SH 18.129999999999998
2010.01.04 000803.SZ 7.820000000000001
2010.01.04 601168.SH 14.56
2010.01.04 600385.SH 6.900000000000001
2010.01.04 601002.SH 7.950000000000001
2010.01.04 600489.SH 57.409999999999996
2010.01.04 002069.SZ 38.060000000000002
2010.01.04 000610.SZ 7.54
2010.01.04 600220.SH 5.8

我想计算close 的五日均线,但是报错 “The first contextBy column must be the partition column of the segmented table.”:

t = loadTable(db, `Close, memoryMode=true);
update t set mp5=msum(close,5) context by ticker;

The first contextBy column must be the partition column of the segmented table.

另外即使context by date也会报错(尽管逻辑上结果无意义)

update t set mp5=msum(close,5) from t context by date;

SegmentedTable does not support direct access. Please use sql query to retrieve data

之所以使用update语句是因为我注意到python api中的例子,比如:

t1.contextby(["PERMNO"]).update(["decay7", "decay8"], ["mavg(mcorr(vwap, msum(adv5, 26), 5), 1..7)","mavg(mrank(9 - mimin(mcorr(rank_open, rank_adv15, 21), 9), true, 7), 1..8)"]).execute()

请问python api中使用update是否一定也是通过update实现的?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

下面代码可以

update trades set mp5=msum(close,5) context by date,ticker;

python api中使用update也是通过update实现的。更新也可以通过update!函数。
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...