How do I read a non-UTF-8 file in AWS Glue PySpark?
I have a glue schema that works for most CSVs. but sometimes clients upload a CSV with CP1252 encoded fields. When I try to do anything with a dynamicFrame from such a file, I get an error:datasource0.toDF().show(1)
An error occurred while calling o221.toDF.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 5.0 failed 4 times, most recent failure: Lost task 1.3 in stage 5.0 (TID 17, ip-172-31-11-73.ec2.internal, executor 2): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx11142018.csv
I tried decoding/encoding each line. but it doesn't work:
def sanitizeString(rawValue):
value = re.sub('\s+', ' ', rawValue)
value = re.sub('\\', '', value)
value = value.decode('CP1252').encode('utf-8')
return value
def sanitizeLine(rawLine):
line = rawLine.map(sanitizeString)
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
datasource0 = datasourceRaw.map(sanitizeLine)
# datasource3.toDF().show(1)
It gives the exact same error
I've also tried loading it through RDD, using
rdd0 = sc.textFile(filepath, use_unicode=False)
rdd0 = rdd0.map(sanitizeLine) # have to add an extra line to sanitizeLine() to split() the line
rdd0.toDF().show(2)
this works, but there's 2 problems:
- For whatever reason, Its waaayy slower than using the DynamicFrame
- It gives me the whole line as a string to map through. I suppose I can split on
,
but then I want to turn it back into a DynamicFrame and for that I need a schema. I tried getting that from the catalog, but (you guessed it), I get the same error:
-
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
print datasourceRaw.schema()
An error occurred while calling o434.schema.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 9.0 failed 4 times, most recent failure: Lost task 1.3 in stage 9.0 (TID 47, ip-172-31-11-73.ec2.internal, executor 5): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx_11142018.csv
utf-8 character-encoding pyspark etl aws-glue
add a comment |
I have a glue schema that works for most CSVs. but sometimes clients upload a CSV with CP1252 encoded fields. When I try to do anything with a dynamicFrame from such a file, I get an error:datasource0.toDF().show(1)
An error occurred while calling o221.toDF.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 5.0 failed 4 times, most recent failure: Lost task 1.3 in stage 5.0 (TID 17, ip-172-31-11-73.ec2.internal, executor 2): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx11142018.csv
I tried decoding/encoding each line. but it doesn't work:
def sanitizeString(rawValue):
value = re.sub('\s+', ' ', rawValue)
value = re.sub('\\', '', value)
value = value.decode('CP1252').encode('utf-8')
return value
def sanitizeLine(rawLine):
line = rawLine.map(sanitizeString)
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
datasource0 = datasourceRaw.map(sanitizeLine)
# datasource3.toDF().show(1)
It gives the exact same error
I've also tried loading it through RDD, using
rdd0 = sc.textFile(filepath, use_unicode=False)
rdd0 = rdd0.map(sanitizeLine) # have to add an extra line to sanitizeLine() to split() the line
rdd0.toDF().show(2)
this works, but there's 2 problems:
- For whatever reason, Its waaayy slower than using the DynamicFrame
- It gives me the whole line as a string to map through. I suppose I can split on
,
but then I want to turn it back into a DynamicFrame and for that I need a schema. I tried getting that from the catalog, but (you guessed it), I get the same error:
-
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
print datasourceRaw.schema()
An error occurred while calling o434.schema.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 9.0 failed 4 times, most recent failure: Lost task 1.3 in stage 9.0 (TID 47, ip-172-31-11-73.ec2.internal, executor 5): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx_11142018.csv
utf-8 character-encoding pyspark etl aws-glue
add a comment |
I have a glue schema that works for most CSVs. but sometimes clients upload a CSV with CP1252 encoded fields. When I try to do anything with a dynamicFrame from such a file, I get an error:datasource0.toDF().show(1)
An error occurred while calling o221.toDF.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 5.0 failed 4 times, most recent failure: Lost task 1.3 in stage 5.0 (TID 17, ip-172-31-11-73.ec2.internal, executor 2): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx11142018.csv
I tried decoding/encoding each line. but it doesn't work:
def sanitizeString(rawValue):
value = re.sub('\s+', ' ', rawValue)
value = re.sub('\\', '', value)
value = value.decode('CP1252').encode('utf-8')
return value
def sanitizeLine(rawLine):
line = rawLine.map(sanitizeString)
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
datasource0 = datasourceRaw.map(sanitizeLine)
# datasource3.toDF().show(1)
It gives the exact same error
I've also tried loading it through RDD, using
rdd0 = sc.textFile(filepath, use_unicode=False)
rdd0 = rdd0.map(sanitizeLine) # have to add an extra line to sanitizeLine() to split() the line
rdd0.toDF().show(2)
this works, but there's 2 problems:
- For whatever reason, Its waaayy slower than using the DynamicFrame
- It gives me the whole line as a string to map through. I suppose I can split on
,
but then I want to turn it back into a DynamicFrame and for that I need a schema. I tried getting that from the catalog, but (you guessed it), I get the same error:
-
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
print datasourceRaw.schema()
An error occurred while calling o434.schema.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 9.0 failed 4 times, most recent failure: Lost task 1.3 in stage 9.0 (TID 47, ip-172-31-11-73.ec2.internal, executor 5): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx_11142018.csv
utf-8 character-encoding pyspark etl aws-glue
I have a glue schema that works for most CSVs. but sometimes clients upload a CSV with CP1252 encoded fields. When I try to do anything with a dynamicFrame from such a file, I get an error:datasource0.toDF().show(1)
An error occurred while calling o221.toDF.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 5.0 failed 4 times, most recent failure: Lost task 1.3 in stage 5.0 (TID 17, ip-172-31-11-73.ec2.internal, executor 2): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx11142018.csv
I tried decoding/encoding each line. but it doesn't work:
def sanitizeString(rawValue):
value = re.sub('\s+', ' ', rawValue)
value = re.sub('\\', '', value)
value = value.decode('CP1252').encode('utf-8')
return value
def sanitizeLine(rawLine):
line = rawLine.map(sanitizeString)
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
datasource0 = datasourceRaw.map(sanitizeLine)
# datasource3.toDF().show(1)
It gives the exact same error
I've also tried loading it through RDD, using
rdd0 = sc.textFile(filepath, use_unicode=False)
rdd0 = rdd0.map(sanitizeLine) # have to add an extra line to sanitizeLine() to split() the line
rdd0.toDF().show(2)
this works, but there's 2 problems:
- For whatever reason, Its waaayy slower than using the DynamicFrame
- It gives me the whole line as a string to map through. I suppose I can split on
,
but then I want to turn it back into a DynamicFrame and for that I need a schema. I tried getting that from the catalog, but (you guessed it), I get the same error:
-
datasourceRaw = glueContext.create_dynamic_frame.from_catalog(database = "glue_db", table_name = "glue_table", transformation_ctx = "datasourceRaw")
print datasourceRaw.schema()
An error occurred while calling o434.schema.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 9.0 failed 4 times, most recent failure: Lost task 1.3 in stage 9.0 (TID 47, ip-172-31-11-73.ec2.internal, executor 5): com.amazonaws.services.glue.util.FatalException: Unable to parse file: xxxx_11142018.csv
utf-8 character-encoding pyspark etl aws-glue
utf-8 character-encoding pyspark etl aws-glue
asked Nov 16 '18 at 3:22
JonTroncosoJonTroncoso
369214
369214
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330951%2fhow-do-i-read-a-non-utf-8-file-in-aws-glue-pyspark%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330951%2fhow-do-i-read-a-non-utf-8-file-in-aws-glue-pyspark%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown