malloydata / malloy

Malloy is an experimental language for describing data relationships and transformations.
http://www.malloydata.dev
MIT License
1.99k stars 76 forks source link

"unknown dialect" exceptions in parser #387

Closed mtoy-googly-moogly closed 2 years ago

mtoy-googly-moogly commented 2 years ago

This file

explore: contributions is table('bigquery-public-data.fec.indiv20') {
  measure: total_amt is sum(transaction_amt)
  dimension: candidate_id is REGEXP_EXTRACT(memo_text, r'(C\d\d\d\d+)')
  join_one: candidate is candidates with candidate_id
}

explore: candidates is table('bigquery-public-data.fec.cn20') {
  primary_key: cand_pcc
}

Parses and highlights the incorrect forward reference.

However if I add ...

query: contributions -> {
  top: 5
  where: candidate_id != NULL
  group_by: candidate_id
  aggregate: total_amt
  order_by: total_amt desc
}

Then the entirety of the error text available to the user is "unknown dialect" ... somehow the IDE is reaching in and getting a fake error query which should never be used because the model didn't compile.

mtoy-googly-moogly commented 2 years ago

@lloydtabb I suspect this is also the source of your "unknown dialect" error.

christopherswenson commented 2 years ago

I don't think this has anything to do with the IDE. Consider these two tests:

This test passes:

test("unknown dialect issue (okay)", () => {
  const code = `
    explore: flights is table('aTable') {
      join_one: my_join is not_yet_defined with astr
    }

    explore: not_yet_defined is table('aTable') {
      primary_key: astr
    }
  `;
  const m = new BetaModel(code);
  m.translate();
  const errList = m.errors().errors;
  expect(errList[0].message).toBe("Undefined data source 'not_yet_defined'")
});

This test fails:

test("unknown dialect issue (bad)", () => {
  const code = `
    explore: exp is table('aTable') {
      join_one: my_join is not_yet_defined with astr
    }

    explore: not_yet_defined is table('aTable') {
      primary_key: astr
    }

    query: exp -> { project: * }
  `;
  const m = new BetaModel(code);
  m.translate();
  const errList = m.errors().errors;
  expect(errList[0].message).toBe("Undefined data source 'not_yet_defined'")
});
● unknown dialect issue (bad)

    Unknown Dialect //undefined_errror_dialect

      21 |   const d = dialectMap.get(name);
      22 |   if (d === undefined) {
    > 23 |     throw new Error(`Unknown Dialect ${name}`);
         |           ^
      24 |   }
      25 |   return d;
      26 | }

      at getDialect (packages/malloy/src/dialect/dialect_map.ts:23:11)
      at new QueryStruct (packages/malloy/src/model/malloy_query.ts:2651:30)
      at QueryStruct.addFieldsFromFieldList (packages/malloy/src/model/malloy_query.ts:2668:13)
      at new QueryStruct (packages/malloy/src/model/malloy_query.ts:2653:10)
      at Function.nextStructDef (packages/malloy/src/model/malloy_query.ts:1145:16)
      at opOutputStruct (packages/malloy/src/lang/ast/ast-main.ts:86:28)
      at Object.outputSpace (packages/malloy/src/lang/ast/ast-main.ts:1520:25)
      at FullQuery.appendOps (packages/malloy/src/lang/ast/ast-main.ts:1743:21)
      at FullQuery.queryComp (packages/malloy/src/lang/ast/ast-main.ts:1906:31)
christopherswenson commented 2 years ago

Following the error up, we see first we log "Undefined data source 'not_yet_defined'", and return undefined from NamedSource.modelStruct(), then in the caller, NamedSource.structDef(), we get a ModelFactory.structDef which we pass up the chain.

That structDef has dialect = //undefined_errror_dialect

Trying to figure out why the query needs or cares about the dialect of the join, since it's not used.

mtoy-googly-moogly commented 2 years ago

You are right. Taking this bug.

mtoy-googly-moogly commented 2 years ago

Right, the error is returned when it is not possible to compute a non error version. what is supposed to happen is that because an error is generated, no one will try to use any compiled items. i'll track it down.