{"record":{"id":"adfe7e02c88266b3","repo":"cube-js/cube","slug":"pre-aggregation-yaml-must-be-a-map-object","errorCode":null,"errorMessage":"Pre-aggregation YAML must be a map/object","messagePattern":"Pre-aggregation YAML must be a map/object","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/converters/CubePreAggregationConverter.ts","lineNumber":89,"sourceCode":"          t.objectExpression([t.objectProperty(t.identifier(preAggregationName), preAggregationNode)])\n        )\n      );\n    } else {\n      (<t.ObjectExpression>anchor).properties.push(\n        t.objectProperty(t.identifier(preAggregationName), <t.ObjectExpression>preAggregationNode)\n      );\n    }\n  }\n\n  protected convertYaml(cubeDefSet: YamlSet) {\n    const { preAggregationName, code } = this.preAggregationDefinition;\n    const { cubeDefinition } = cubeDefSet;\n\n    const preAggDoc = YAML.parseDocument(code);\n    const preAggNode = preAggDoc.contents;\n\n    if (!preAggNode || !isMap(preAggNode)) {\n      throw new UserError('Pre-aggregation YAML must be a map/object');\n    }\n\n    const preAggsPair = cubeDefinition.items.find(\n      (pair: Pair) => isScalar(pair.key) && (pair.key.value === 'pre_aggregations' || pair.key.value === 'preAggregations')\n    );\n\n    if (preAggsPair) {\n      const seq = preAggsPair.value;\n      if (!YAML.isSeq(seq)) {\n        throw new UserError('\\'pre_aggregations\\' must be a sequence');\n      }\n\n      const exists = seq.items.some(item => {\n        if (isMap(item)) {\n          const namePair = item.items.find(\n            (pair: Pair) => isScalar(pair.key) && pair.key.value === 'name'\n          );\n          return namePair && isScalar(namePair.value) && namePair.value.value === preAggregationName;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/converters/CubePreAggregationConverter.ts#L71-L107","documentation":"convertYaml parses a pre-aggregation YAML document with the yaml library and requires the root node to be a map. If the document is empty, a scalar, or a sequence, it throws UserError 'Pre-aggregation YAML must be a map/object' because pre-aggregation definitions must be key/value maps keyed by rollup name.","triggerScenarios":"Passing YAML that is an empty document, a bare list of measures, or a scalar string as the pre-aggregation code to CubePreAggregationConverter when the cube definition came from YAML.","commonSituations":"Hand-editing YAML and deleting the top-level mapping, generating YAML from tools that emit sequences, or a file that is empty/only comments so the parsed root is null.","solutions":["Make the YAML root a mapping: pre_aggregations: - name: ... structure (or a map of pre-aggregation names to definitions)","Check the file is not empty or comment-only","Wrap list content under a top-level key instead of a root-level sequence","Validate the YAML parses to an object: YAML.parseDocument(code).contents is a YAMLMap"],"exampleFix":"# before\n- measures:\n    - orders.count\n\n# after\npre_aggregations:\n  - name: main\n    measures:\n      - orders.count","handlingStrategy":"validation","validationCode":"const YAML = require('yaml');\nfunction assertYamlIsMap(code) {\n  const doc = YAML.parseDocument(code);\n  if (!doc.contents || !YAML.isMap(doc.contents)) {\n    throw new Error('Pre-aggregation YAML must be a root-level map/object');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  converter.convert(astByCubeName);\n} catch (e) {\n  if (e.message === 'Pre-aggregation YAML must be a map/object') {\n    console.error('Check the pre-aggregation YAML file: root must be a mapping, not a list or empty doc');\n  }\n}","preventionTips":["Validate YAML files with a linter before committing","Never leave pre-aggregation YAML files empty or comment-only","Keep definitions nested under pre_aggregations, never at document root"],"tags":["yaml","pre-aggregations","validation"],"backgroundTag":"yaml-format-invalid","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}