sqljdbcimpala

Get an error during processing query Impala JDBCDriver


Hello I have a strange behaviour with a query. the query is working fine, when it is executed in WebSQL, but I get the following error with Impala JDBCDriver:

Query: [SmOpenAsns] -> [Cloudera]ImpalaJDBCDriver ERROR processing query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000, errorMessage:ParseException: Syntax error in line 1: ....asn_id AS order_id FROM ${siteidlowercase}.f_receivin...

Encountered: Unexpected character Expected: ADD, ALTER, AND, ARRAY, AS, ASC, BETWEEN, BIGINT, BINARY, BLOCK_SIZE, BOOLEAN, CACHED, CASCADE, CHANGE, CHAR, COMMENT, COMPRESSION, CROSS, DATE, DATETIME, DECIMAL, DEFAULT, DESC, DIV, REAL, DROP, ELSE, ENCODING, END, FLOAT, FOLLOWING, FROM, FULL, GROUP, IGNORE, HAVING, ILIKE, IN, INNER, INTEGER, IREGEXP, IS, JOIN, LEFT, LIKE, LIMIT, LOCATION, MAP, NOT, NULL, NULLS, OFFSET, ON, OR, ORDER, PARTITION, PARTITIONED, PRECEDING, PRIMARY, PURGE, RANGE, RECOVER, REGEXP, RENAME, REPLACE, RESTRICT, RIGHT, RLIKE, ROW, ROWS, SELECT, SET, SMALLINT, SORT, STORED, STRAIGHT_JOIN, STRING, STRUCT, TABLESAMPLE, TBLPROPERTIES, THEN, TIMESTAMP, TINYINT, TO, UNCACHED, UNION, USING, VALUES, VARCHAR, WHEN, WHERE, WITH, COMMA, IDENTIFIER

CAUSED BY: Exception: Syntax error ), Query: WITH sm_orders_total AS(SELECT CASE WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -1), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) <= concat(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN 'Older' END AS creation_date, fact.asn_id AS order_id FROM ${siteidlowercase}.f_receiving fact JOIN ${siteidlowercase}.d_wms_cust_article art ON art.article_id = fact.article_id WHERE fact.po_number is NULL AND fact.asn_type !='RETURN' AND fact.asn_status in ('LOADED', 'OPEN', 'RECEIVING', 'REGISTERED') GROUP BY fact.asn_id , fact.creation_time), sm_orders_frozen AS (SELECT CASE WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -1), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) <= concat(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN 'Older' END AS creation_date, fact.asn_id AS order_id FROM ${siteidlowercase}.f_receiving fact JOIN ${siteidlowercase}.d_wms_cust_article art ON art.article_id = fact.article_id WHERE fact.po_number is NULL AND fact.asn_type !='RETURN' AND fact.asn_status in ('LOADED', 'OPEN', 'RECEIVING', 'REGISTERED') AND art.classification_name like 'frozen%' GROUP BY fact.asn_id, fact.creation_time) SELECT sm_orders_total.creation_date sm_creation_date, COUNT(DISTINCT sm_orders_frozen.order_id) sm_frozen_asns, COUNT(DISTINCT sm_orders_total.order_id) sm_total_asns FROM sm_orders_total JOIN sm_orders_frozen ON sm_orders_total.creation_date = sm_orders_total.creation_date GROUP BY sm_creation_date ORDER BY split_part(SUBSTR(sm_orders_total.creation_date, 1, 10), '.', 2) desc, split_part(SUBSTR(sm_orders_total.creation_date, 1, 10), '.', 1) desc LIMIT 1000000 /* [SmOpenAsns] */.

Query:

WITH sm_orders_total AS(
    SELECT 
        CASE 
            WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -1), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') 
            WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') 
            WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) <= concat(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN 'Older' 
        END AS creation_date, 
        fact.asn_id AS order_id 
    FROM ${siteidlowercase}.f_receiving fact 
    JOIN ${siteidlowercase}.d_wms_cust_article art ON art.article_id = fact.article_id 
    WHERE fact.po_number is NULL 
    AND fact.asn_type !='RETURN' 
    AND fact.asn_status in ('LOADED', 'OPEN', 'RECEIVING', 'REGISTERED') 
    GROUP BY fact.asn_id , fact.creation_time), 
    sm_orders_frozen AS (
        SELECT 
        CASE 
            WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -1), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') 
            WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) >= CONCAT(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN from_timestamp(to_timestamp(SUBSTR(fact.creation_time, 1, 10), 'yyyy-MM-dd'), 'dd.MM.yyyy') 
            WHEN CONCAT(SUBSTR(fact.creation_time, 1, 10), ' ', SUBSTR(fact.creation_time, 12, 8)) <= concat(from_timestamp(DAYS_ADD(now(), -2), 'yyyy-MM-dd'), ' ', '23:00:00') THEN 'Older' 
        END AS creation_date, 
        fact.asn_id AS order_id 
        FROM ${siteidlowercase}.f_receiving fact 
        JOIN ${siteidlowercase}.d_wms_cust_article art ON art.article_id = fact.article_id 
        WHERE fact.po_number is NULL 
        AND fact.asn_type !='RETURN' 
        AND fact.asn_status in ('LOADED', 'OPEN', 'RECEIVING', 'REGISTERED') 
        AND art.classification_name like 'frozen%' 
        GROUP BY fact.asn_id, fact.creation_time) 
        SELECT 
        sm_orders_total.creation_date sm_creation_date, 
        COUNT(DISTINCT sm_orders_frozen.order_id) sm_frozen_asns, 
        COUNT(DISTINCT sm_orders_total.order_id) sm_total_asns 
        FROM sm_orders_total 
        JOIN sm_orders_frozen ON sm_orders_frozen.creation_date = sm_orders_total.creation_date 
        GROUP BY sm_creation_date 
        ORDER BY split_part(SUBSTR(sm_orders_total.creation_date, 1, 10), '.', 2) desc, split_part(SUBSTR(sm_orders_total.creation_date, 1, 10), '.', 1) desc;

I'm not able to find any error in the query. I don't know whats wrong with it. Thank you.


Solution

  • I found the error in the query.

    It was realy the paramters which are written wrongly. The paramter is written completely in lower case but the "L" needs to be upper case.

    Wrong:

    ${siteidlowercase}.f_receiving fact 
    

    Correct:

    ${siteidLowercase}.f_receiving fact 
    

    Now everything is working as it should.