AWS Glue Studio to Redshift

0

Hello everyone !

I am trying to import data from one RDS SQL Server to Redshift but I have a query with a recursive cte like that :

WITH RECURSIVE table(n) AS (
    select 1
  UNION ALL
    SELECT n+1 FROM table WHERE n < 100
)
SELECT n FROM table;

On Redshift there is no error but if I execute the query in an aws glue job (Transform - SQL Query) then i get this error :

ParseException: no viable alternative at input 'WITH RECURSIVE table

What am I missing ?

2개 답변
0

Hello,

Thanks for your answer ! You are right glue doesn't support recursive function, thus i created a view in SQL server. Then i imported this view as a table in glue and replaced te recusrive function in the script ;)

답변함 일 년 전
-1

Hello,

I would like to inform you that Glue/Spark doesn't support recursive query. But you can use spark dataframe with the wildcard to load data from the recursive way.

Let say you have data inside the following s3 path: s3://kg-testing/test2/2018/07/10/*.files.

Then you can use the following glue code to read it recursively using wildcard (*).

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

print("**********DF printing*********")
spark.read .csv("s3://kg-testing/test2/*/*/*/*").createOrReplaceTempView("testsample")

sqlDF=spark.sql("select * from testsample")
print(sqlDF.show ())

In order for me to troubleshoot further, by taking a look at the logs in the backend, please feel free to open a support case with AWS using the following link with the sanitized script, the job run and we would be happy to help.

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠