betodealmeida edited a comment on issue #13491:
URL: https://github.com/apache/superset/issues/13491#issuecomment-791845156


   > **[Topic 2]** Most critically, with the current Superset codebase (as of 
apache-superset v.1.0.1) an error occurs when attempting to perform a simple 
SELECT query in the SQL Lab; see Figure 1 below. Namely, observe in Figure 1 
the "Syntax Error: expected something between the word '<table_Name>' and the 
'LIMIT' keyword". The root cause for this error is the improper translation to 
Teradata SQL of the 'LIMIT' keyword in the Superset back-end. Teradata SQL uses 
the 'TOP' or 'SAMPLE' keywords instead of 'LIMIT'. Observe that issue #11405 
appears to be closely related to this issue.
   
   This is an easy fix:
   
   ```python
   class TeradataEngineSpec(BaseEngineSpec):
       """Dialect for Teradata DB."""
   
       limit_method = LimitMethod.FETCH_MANY
       ...
   ```
   
   This error happens because in SQL Lab we try to limit the query to prevent 
fetching too much data. There are 3 strategies for this:
   
   1. `WRAP_SQL`: if the dropdown limit is 1000, wrap the SQL Lab query and 
apply a limit to the outer select:
   
   ```sql
   SELECT * FROM (
       $SQL_QUERY
   ) LIMIT 1000;
   ```
   
   This method is great because it doesn't require parsing the SQL query, and 
is mostly foolproof. Not all databases support this, though.
   
   2. `FORCE_LIMIT`: parse the SQL Lab query and insert a LIMIT or replace the 
existing LIMIT if present. This method is more error-prone, since it requires 
parsing the original query. And as you saw, not all databases support the 
`LIMIT` clause.
   
   3. `FETCH_MANY`: do not modify the SQL query, but fetch only a limited 
number of rows. With this method, the SQL Lab query is run as is, and we fetch 
a number of rows equal to the limit dropdown. This is the least efficient 
method, since the query might produce 1 million rows for us to fetch only 1000. 
Firebird uses this.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to