Problem with Athena query when used in Glue ETL

Hi all,

Inside a glue ETL job I need to elaborate data with a SQL query. To develop and test the query, I used Athena. In this way was easier to preceed step by step.

But once I copy-paste it in the Glue ETL Job, using “MyDataSource” as main table, I don’t have any result out of it. I tried both with 1000 rows preview and I also ran the job entirely.

I tried with a simpler query (select * from the first subquery that you can see below), and still I don’t see any data, just column names.

What am I missing? As I understood Glue ETL uses a sort of Spark SQL, differently from Athena. Does a converter exist?

Glue has admin access.

Thanks id advance to all the heroes in this subreddit that solve strangers problems :wink:

Here the query:

with first_filter as (

    SELECT DISTINCT *
    FROM myDataSource
    WHERE user_id IN (
        SELECT user_id FROM myDataSource WHERE page = 'www.recuperosociale.it/contatti/il_nostro_stabile' AND session_length >= 60
    ) AND user_id IN (
        SELECT user_id FROM myDataSource WHERE page = 'www.recuperosociale.it/documento/descrizione_servizi'
    )

),

second_filter_prob1 as(

    SELECT DISTINCT user_id
    FROM first_filter
    WHERE user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema1/sottopagina1' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema1/sottopagina2' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema1/sottopagina3' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema1/sottopagina4' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema1/sottopagina5' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/guide/pronto_aiuto/problema1' AND session_length >= 1500
    ) AND user_id IN ( 
        SELECT user_id
            FROM (
                SELECT user_id, 
                       SUM(CASE WHEN page IN ('www.recuperosociale.it/storie_pazienti/problema1/storia1', 
                                              'www.recuperosociale.it/storie_pazienti/problema1/storia2', 
                                              'www.recuperosociale.it/storie_pazienti/problema1/storia3', 
                                              'www.recuperosociale.it/storie_pazienti/problema1/storia4', 
                                              'www.recuperosociale.it/storie_pazienti/problema1/storia5') 
                                AND session_length >= 900 THEN 1 ELSE 0 END) AS visits
                FROM myDataSource
                GROUP BY user_id
            )
            WHERE visits >= 3
    ) 

),

second_filter_prob2 as(

    SELECT DISTINCT user_id
    FROM first_filter
    WHERE user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema2/sottopagina1' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema2/sottopagina2' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema2/sottopagina3' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema2/sottopagina4' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema2/sottopagina5' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/guide/pronto_aiuto/problema2' AND session_length >= 1500
    ) AND user_id IN ( 
        SELECT user_id
            FROM (
                SELECT user_id, 
                       SUM(CASE WHEN page IN ('www.recuperosociale.it/storie_pazienti/problema2/storia1', 
                                              'www.recuperosociale.it/storie_pazienti/problema2/storia2', 
                                              'www.recuperosociale.it/storie_pazienti/problema2/storia3', 
                                              'www.recuperosociale.it/storie_pazienti/problema2/storia4', 
                                              'www.recuperosociale.it/storie_pazienti/problema2/storia5') 
                                AND session_length >= 900 THEN 1 ELSE 0 END) AS visits
                FROM myDataSource
                GROUP BY user_id
            )
            WHERE visits >= 3
    ) 

),


second_filter_prob3 as(

    SELECT DISTINCT user_id
    FROM first_filter
    WHERE user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema3/sottopagina1' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema3/sottopagina2' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema3/sottopagina3' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema3/sottopagina4' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/blog/problema3/sottopagina5' AND session_length >= 600
    ) AND user_id IN (
        SELECT user_id FROM first_filter WHERE page = 'www.recuperosociale.it/guide/pronto_aiuto/problema3' AND session_length >= 1500
    ) AND user_id IN ( 
        SELECT user_id
            FROM (
                SELECT user_id, 
                       SUM(CASE WHEN page IN ('www.recuperosociale.it/storie_pazienti/problema3/storia1', 
                                              'www.recuperosociale.it/storie_pazienti/problema3/storia2', 
                                              'www.recuperosociale.it/storie_pazienti/problema3/storia3', 
                                              'www.recuperosociale.it/storie_pazienti/problema3/storia4', 
                                              'www.recuperosociale.it/storie_pazienti/problema3/storia5') 
                                AND session_length >= 900 THEN 1 ELSE 0 END) AS visits
                FROM myDataSource
                GROUP BY user_id
            )
            WHERE visits >= 3
    ) 

)

SELECT *
from second_filter_prob1

Screen preview Glue ETL

Screen output same query but with Athena

Here the entire Glue ETL job, maybe it could help

https://imgur.com/a/CO0BpGe

Recovered from imgur album CO0BpGe (the album’s full listing is gone, but this item survived).

Hello, without knowing much details about your setup. What do you see if u query in glue - select * from mydatasource limit 10; — just ruling out any data filters etc. is mydatasource a glue table/s3 source. Are the permissions setup similar to athena and glue. Any luck from glue job runtime logs if any error?

  1. with select * from myDataSource, it works https://imgur.com/a/whKJUsx

  2. it is in the middle of the Glue ETL job, so it is like the consequence of a join and another sql query

  3. for this specific glue job I used admin permissions

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: “",
“Resource”: "
”
}
]
}

For Athena, I’m using a user with Admin permissions. So I would say that in both cases there are the same rights

  1. In the last run, I got this error message

Error Category: QUERY_ERROR; Spark Error Class: MISSING_COLUMN; AnalysisException: Column ‘prob1’ does not exist. Did you mean one of the following? ; line 3 pos 26;

But it is related to a node that comes later in the job. I didn’t check inside Glue Job logs because I’m quite new to aws and I’m not able to read them unfortunately… but I can imagine that I’m not the first that writes something in Athena and that doesn’t work in Glue :sweat_smile:

Recovered from imgur album whKJUsx (the album’s full listing is gone, but this item survived).

SOLVED: I simply divided this etl in 3 different jobs. Saving the results of the first job in an glue catalog table solved the issue