简体   繁体   中英

cube.js join compile error does not match any of the allowed types

I am new to cube.js and have been working through the documentation and can't seem to figure out why I get this error. Any ideas? I am joining two tables, one contains daily data and the other table contains attributes that I would like to use for segmenting data.

I was able to generate the schema nearly entirely from the postgres tables, the only changed I had to make were to tag the columns as primary key.

postgres ddl

drop table if exists daily_volumes;
drop table if exists wells;

create table if not exists wells (
    id integer not null,
    well_name varchar(255),
    api_10 varchar(13),
    area varchar(255),
    run varchar(255),
    engineering_id varchar(50),
    accounting_id varchar(50),
    active_flag int,
    primary key (id)
);

create table if not exists daily_volumes(   
    well_id integer not null,
    record_date timestamp not null, 
    oil_prod_bbl float not null,
    water_prod_bbl float not null,
    gas_prod_mcf float not null,
    primary key (well_id, record_date),
    constraint fk_well_id foreign key (well_id) references wells(id)
);


cube.js error

Error: Error: Compile errors:
DailyVolumes cube: "dimensions.wellId" does not match any of the allowed types
Possible reasons (one of):
    * (dimensions.wellId.case) is required
    * (dimensions.wellId.sql = () => `well_id`) is not allowed
    * (dimensions.wellId.primary_key = true) is not allowed

schema/Wells.js

cube(`Wells`, {
  sql: `SELECT * FROM public.wells`,
  
  preAggregations: {
    // Pre-Aggregations definitions go here
    // Learn more here: https://cube.dev/docs/caching/pre-aggregations/getting-started  
  },
  
  joins: {
    
  },
  
  measures: {
    count: {
      type: `count`,
      drillMembers: [id, wellName, engineeringId, accountingId]
    }
  },
  
  dimensions: {
    id: {
      sql: `id`,
      type: `number`,
      primaryKey: true
    },
    
    wellName: {
      sql: `well_name`,
      type: `string`
    },
    
    api10: {
      sql: `api_10`,
      type: `string`,
      title: `Api 10`
    },
    
    area: {
      sql: `area`,
      type: `string`
    },
    
    run: {
      sql: `run`,
      type: `string`
    },
    
    engineeringId: {
      sql: `engineering_id`,
      type: `string`
    },
    
    accountingId: {
      sql: `accounting_id`,
      type: `string`
    }
  },
  
  dataSource: `default`
});

schema/DailyVolumes.js

cube(`DailyVolumes`, {
  sql: `SELECT * FROM public.daily_volumes`,

  preAggregations: {
    // Pre-Aggregations definitions go here
    // Learn more here: https://cube.dev/docs/caching/pre-aggregations/getting-started
  },

  joins: {
    Wells: {
      sql: `${CUBE}.well_id = ${Wells}.id`,
      relationship: `belongsTo`,
    },
  },

  measures: {
    count: {
      type: `count`,
      sql: `id`,
      // drillMembers: [recordDate],
    },
  },

  dimensions: {
    recordDate: {
      sql: `record_date`,
      type: `time`,
    },
    wellId: {
      sql: `well_id`,
      type: `number`,
      primary_key: true,
    },
  },

  dataSource: `default`,
});

Setting primaryKey to true will change the default value of the shown parameter to false. If you still want shown to be true — set it manually.

Extracted from Documentation Page .

I think the issue was that you used primary_key (snake case) instead of primaryKey (camel case), as described in docs: https://cube.dev/docs/schema/reference/dimensions#primary-key

I also have to admit that the error message is not very helpful now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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