Cube.js schema编译报错dimensions.wellId不符合允许类型解决方案咨询
问题根源
你在DailyVolumes cube的schema定义中存在3处语法和逻辑错误,触发了编译校验失败:
- 主键属性名拼写错误:Cube.js schema 要求主键标记使用驼峰属性名
primaryKey,你写的是下划线格式的primary_key,属于非法属性,因此触发校验报错。 - 联合主键配置错误:
daily_volumes表的主键是well_id和record_date的联合主键,不能单独将wellId维度标记为主键。 - 度量字段不存在:
count度量中指定的sql: id对应的字段在daily_volumes表中不存在,运行时也会触发查询错误。
修复方案
将schema/DailyVolumes.js替换为以下代码即可:
cube(`DailyVolumes`, { sql: `SELECT * FROM public.daily_volumes`, preAggregations: { // 预聚合定义写在这里 }, joins: { Wells: { sql: `${CUBE}.well_id = ${Wells}.id`, relationship: `belongsTo`, }, }, measures: { count: { type: `count`, // count类型不指定sql时默认统计行数,也可指定任意非空字段如well_id drillMembers: [wellId, recordDate], }, // 可根据业务需要补充产量指标,示例如下 oilProdBbl: { sql: `oil_prod_bbl`, type: `sum` }, waterProdBbl: { sql: `water_prod_bbl`, type: `sum` }, gasProdMcf: { sql: `gas_prod_mcf`, type: `sum` } }, dimensions: { recordDate: { sql: `record_date`, type: `time`, primaryKey: true }, wellId: { sql: `well_id`, type: `number`, primaryKey: true, }, }, dataSource: `default`, });
内容的提问来源于stack exchange,提问作者bfmcneill
相关产品推荐
相关产品推荐

