cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Genie "Field" error: Table name or alias is required for column 'amount'

dkxxx-rc
Contributor

The documentation at https://docs.databricks.com/aws/en/genie-agents/tune-quality#define-sql-expressions says that you can create a "Field" in a genie agent (in the Examples section of config) with the code 

CASE WHEN amount < 10000 THEN 'Small' WHEN amount < 50000 THEN 'Medium' ELSE 'Large' END

However, entering this code yields an error 

Table name or alias is required for column 'amount'

presumably because the field names aren't specified as belonging to a specific table.

So #1, that's an error in the documentation, right?

#2, what does "alias" mean in the error message?  I get that if I were creating an example Query, I could create table aliases for the result of the query.  But such aliases do not appear to be valid for using in the Field definition.

Is there a separate method for defining an "alias" in the context of a Genie Agent?

field.png

1 ACCEPTED SOLUTION

Accepted Solutions

VK210287
New Contributor III

Hi @dkxxx-rc, Greetings. 

#1 โ€” Documentation inconsistency: Yes, this appears to be an error in the docs. Notice that the Filter example on the same page correctly qualifies the column: orders.amount > 10000, but the Field example leaves amount unqualified. The Genie Agent expression engine requires column references to be qualified with the table name, so the Field example should read something like CASE WHEN orders.amount < 10000 THEN 'Small' ....

#2 โ€” What "alias" means here: In this context, "alias" refers to the table name as it's registered in the Genie Agent. When you add a table to the agent (e.g., catalog.schema.orders), the expression parser expects you to reference columns using that table name as a prefix โ€” orders.amount, not just amount. There is no separate mechanism to define custom aliases like you would in a SQL FROM clause (FROM orders AS o).

From your screenshot, t in COUNT(DISTINCT t.Author Identifier) is rejected because t isn't the name of any table in your agent. You'd need to use the actual table name as it appears in the agent's table list โ€” e.g., if the table is my_catalog.my_schema.publications, you'd write COUNT(DISTINCT publications.\Author Identifier`)`.

So,  "table name or alias" in the error is the last segment of the fully qualified table name registered in your agent โ€” that's the only valid qualifier for column references in these expressions.

 

 

Vannurswamy Kuruba

View solution in original post

2 REPLIES 2

VK210287
New Contributor III

Hi @dkxxx-rc, Greetings. 

#1 โ€” Documentation inconsistency: Yes, this appears to be an error in the docs. Notice that the Filter example on the same page correctly qualifies the column: orders.amount > 10000, but the Field example leaves amount unqualified. The Genie Agent expression engine requires column references to be qualified with the table name, so the Field example should read something like CASE WHEN orders.amount < 10000 THEN 'Small' ....

#2 โ€” What "alias" means here: In this context, "alias" refers to the table name as it's registered in the Genie Agent. When you add a table to the agent (e.g., catalog.schema.orders), the expression parser expects you to reference columns using that table name as a prefix โ€” orders.amount, not just amount. There is no separate mechanism to define custom aliases like you would in a SQL FROM clause (FROM orders AS o).

From your screenshot, t in COUNT(DISTINCT t.Author Identifier) is rejected because t isn't the name of any table in your agent. You'd need to use the actual table name as it appears in the agent's table list โ€” e.g., if the table is my_catalog.my_schema.publications, you'd write COUNT(DISTINCT publications.\Author Identifier`)`.

So,  "table name or alias" in the error is the last segment of the fully qualified table name registered in your agent โ€” that's the only valid qualifier for column references in these expressions.

 

 

Vannurswamy Kuruba

Louis_Frolio
Databricks Employee
Databricks Employee

Greetings @dkxxx-rc, I did some digging and here is what I found.

Vannurswamy Kuruba already nailed the core of this, so I'll build on his reply.

On #1: yes, it's a doc inconsistency. On the same page, the Filter example qualifies the column (orders.amount > 10000), but the Field example uses a bare amount. The Measure example is unqualified too. The fix is to prefix the column with the table name as it appears under Configure > Sources:

CASE
  WHEN orders.amount < 10000 THEN 'Small'
  WHEN orders.amount < 50000 THEN 'Medium'
  ELSE 'Large'
END

On #2: there's no way to declare your own alias in a Field. It's an expression, not a query, so there's no FROM ... AS ... where t could come from. My read is that "alias" refers to names Genie generates itself. The docs mention it does this for the right-hand table in self-joins or repeated joins. The docs don't describe any user-defined alias syntax, so the actual table name is the safe bet.

One more thing from your screenshot: Author Identifier has a space, so it needs backticks, something like COUNT(DISTINCT publications.`Author Identifier`). Swap in your real table name.

If the qualified version still fails, post the table name as shown under Sources, the exact expression, and whether the agent has joins or multiple tables. At that point it may be a product validation issue rather than a SQL one. It's also worth using the feedback option on the doc page so the examples get fixed.

References:

Hope this helps.

Regards, Louis.