org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile Error










1















in a new prjoct I would like to use Apache-Spark and elasticSearch i found many tutorial and i found this code that I have adapted:



import os
import json
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext

os.environ['PYSPARK_SUBMIT_ARGS'] = '--jars elasticsearch-spark_2.11-2.4.5.jar pyspark-shell'

sc = SparkContext(appName="AllCountries")

es_write_conf = "es.nodes": 'localhost', "es.port" : '9200', "es.resource" : 'testindex/testdoc', "es.batch.size.entries": 1, "es.input.json" : "yes", "es.mapping.id": "doc_id"

data = [ 'some_key': 'some_value', 'doc_id': 123, 'some_key': 'some_value', 'doc_id': 456, 'some_key': 'some_value', 'doc_id': 789 ]
rdd = sc.parallelize(data)

def format_data(x):
return (data[0]['doc_id'], json.dumps(data))

rdd = rdd.map(lambda x: format_data(x))

rdd.saveAsNewAPIHadoopFile(
path='-',
outputFormatClass="org.elasticsearch.hadoop.mr.EsOutputFormat",
keyClass="org.apache.hadoop.io.NullWritable",
valueClass="org.elasticsearch.hadoop.mr.LinkedMapWritable",
conf=es_write_conf)


But i have this error:



18/11/13 15:26:45 WARN Utils: Your hostname, bailleux-VirtualBox resolves to a loopback address: 127.0.1.1; using 10.0.2.15 instead (on interface enp0s3)
18/11/13 15:26:45 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
18/11/13 15:26:46 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

Traceback (most recent call last):
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/text.py", line 33, in <module>
conf=es_write_conf)
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/rdd.py", line 1438, in saveAsNewAPIHadoopFile
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile.
: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at org.apache.spark.api.python.PythonHadoopUtil$.mapToConf(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonRDD$.getMergedConf(PythonRDD.scala:445)
at org.apache.spark.api.python.PythonRDD$.saveAsNewAPIHadoopFile(PythonRDD.scala:557)
at org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile(PythonRDD.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


I do not understand where is my mistake, can someone have a solution?



Thank you for your help.










share|improve this question



















  • 1





    Looks like the error is on the config object. Try setting "es.batch.size.entries": "1" instead

    – cricket_007
    Nov 13 '18 at 15:24











  • Can you check why is it throwing java.lang.Integer cannot be cast to java.lang.String?

    – karma4917
    Nov 13 '18 at 15:51
















1















in a new prjoct I would like to use Apache-Spark and elasticSearch i found many tutorial and i found this code that I have adapted:



import os
import json
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext

os.environ['PYSPARK_SUBMIT_ARGS'] = '--jars elasticsearch-spark_2.11-2.4.5.jar pyspark-shell'

sc = SparkContext(appName="AllCountries")

es_write_conf = "es.nodes": 'localhost', "es.port" : '9200', "es.resource" : 'testindex/testdoc', "es.batch.size.entries": 1, "es.input.json" : "yes", "es.mapping.id": "doc_id"

data = [ 'some_key': 'some_value', 'doc_id': 123, 'some_key': 'some_value', 'doc_id': 456, 'some_key': 'some_value', 'doc_id': 789 ]
rdd = sc.parallelize(data)

def format_data(x):
return (data[0]['doc_id'], json.dumps(data))

rdd = rdd.map(lambda x: format_data(x))

rdd.saveAsNewAPIHadoopFile(
path='-',
outputFormatClass="org.elasticsearch.hadoop.mr.EsOutputFormat",
keyClass="org.apache.hadoop.io.NullWritable",
valueClass="org.elasticsearch.hadoop.mr.LinkedMapWritable",
conf=es_write_conf)


But i have this error:



18/11/13 15:26:45 WARN Utils: Your hostname, bailleux-VirtualBox resolves to a loopback address: 127.0.1.1; using 10.0.2.15 instead (on interface enp0s3)
18/11/13 15:26:45 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
18/11/13 15:26:46 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

Traceback (most recent call last):
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/text.py", line 33, in <module>
conf=es_write_conf)
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/rdd.py", line 1438, in saveAsNewAPIHadoopFile
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile.
: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at org.apache.spark.api.python.PythonHadoopUtil$.mapToConf(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonRDD$.getMergedConf(PythonRDD.scala:445)
at org.apache.spark.api.python.PythonRDD$.saveAsNewAPIHadoopFile(PythonRDD.scala:557)
at org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile(PythonRDD.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


I do not understand where is my mistake, can someone have a solution?



Thank you for your help.










share|improve this question



















  • 1





    Looks like the error is on the config object. Try setting "es.batch.size.entries": "1" instead

    – cricket_007
    Nov 13 '18 at 15:24











  • Can you check why is it throwing java.lang.Integer cannot be cast to java.lang.String?

    – karma4917
    Nov 13 '18 at 15:51














1












1








1








in a new prjoct I would like to use Apache-Spark and elasticSearch i found many tutorial and i found this code that I have adapted:



import os
import json
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext

os.environ['PYSPARK_SUBMIT_ARGS'] = '--jars elasticsearch-spark_2.11-2.4.5.jar pyspark-shell'

sc = SparkContext(appName="AllCountries")

es_write_conf = "es.nodes": 'localhost', "es.port" : '9200', "es.resource" : 'testindex/testdoc', "es.batch.size.entries": 1, "es.input.json" : "yes", "es.mapping.id": "doc_id"

data = [ 'some_key': 'some_value', 'doc_id': 123, 'some_key': 'some_value', 'doc_id': 456, 'some_key': 'some_value', 'doc_id': 789 ]
rdd = sc.parallelize(data)

def format_data(x):
return (data[0]['doc_id'], json.dumps(data))

rdd = rdd.map(lambda x: format_data(x))

rdd.saveAsNewAPIHadoopFile(
path='-',
outputFormatClass="org.elasticsearch.hadoop.mr.EsOutputFormat",
keyClass="org.apache.hadoop.io.NullWritable",
valueClass="org.elasticsearch.hadoop.mr.LinkedMapWritable",
conf=es_write_conf)


But i have this error:



18/11/13 15:26:45 WARN Utils: Your hostname, bailleux-VirtualBox resolves to a loopback address: 127.0.1.1; using 10.0.2.15 instead (on interface enp0s3)
18/11/13 15:26:45 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
18/11/13 15:26:46 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

Traceback (most recent call last):
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/text.py", line 33, in <module>
conf=es_write_conf)
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/rdd.py", line 1438, in saveAsNewAPIHadoopFile
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile.
: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at org.apache.spark.api.python.PythonHadoopUtil$.mapToConf(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonRDD$.getMergedConf(PythonRDD.scala:445)
at org.apache.spark.api.python.PythonRDD$.saveAsNewAPIHadoopFile(PythonRDD.scala:557)
at org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile(PythonRDD.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


I do not understand where is my mistake, can someone have a solution?



Thank you for your help.










share|improve this question
















in a new prjoct I would like to use Apache-Spark and elasticSearch i found many tutorial and i found this code that I have adapted:



import os
import json
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext

os.environ['PYSPARK_SUBMIT_ARGS'] = '--jars elasticsearch-spark_2.11-2.4.5.jar pyspark-shell'

sc = SparkContext(appName="AllCountries")

es_write_conf = "es.nodes": 'localhost', "es.port" : '9200', "es.resource" : 'testindex/testdoc', "es.batch.size.entries": 1, "es.input.json" : "yes", "es.mapping.id": "doc_id"

data = [ 'some_key': 'some_value', 'doc_id': 123, 'some_key': 'some_value', 'doc_id': 456, 'some_key': 'some_value', 'doc_id': 789 ]
rdd = sc.parallelize(data)

def format_data(x):
return (data[0]['doc_id'], json.dumps(data))

rdd = rdd.map(lambda x: format_data(x))

rdd.saveAsNewAPIHadoopFile(
path='-',
outputFormatClass="org.elasticsearch.hadoop.mr.EsOutputFormat",
keyClass="org.apache.hadoop.io.NullWritable",
valueClass="org.elasticsearch.hadoop.mr.LinkedMapWritable",
conf=es_write_conf)


But i have this error:



18/11/13 15:26:45 WARN Utils: Your hostname, bailleux-VirtualBox resolves to a loopback address: 127.0.1.1; using 10.0.2.15 instead (on interface enp0s3)
18/11/13 15:26:45 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
18/11/13 15:26:46 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

Traceback (most recent call last):
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/text.py", line 33, in <module>
conf=es_write_conf)
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/rdd.py", line 1438, in saveAsNewAPIHadoopFile
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
File "/home/bailleux/dev/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile.
: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonHadoopUtil$$anonfun$mapToConf$1.apply(PythonHadoopUtil.scala:160)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at org.apache.spark.api.python.PythonHadoopUtil$.mapToConf(PythonHadoopUtil.scala:160)
at org.apache.spark.api.python.PythonRDD$.getMergedConf(PythonRDD.scala:445)
at org.apache.spark.api.python.PythonRDD$.saveAsNewAPIHadoopFile(PythonRDD.scala:557)
at org.apache.spark.api.python.PythonRDD.saveAsNewAPIHadoopFile(PythonRDD.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


I do not understand where is my mistake, can someone have a solution?



Thank you for your help.







python apache-spark hadoop elasticsearch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 15:22









cricket_007

82.1k1143111




82.1k1143111










asked Nov 13 '18 at 15:08









Vianney BailleuxVianney Bailleux

5317




5317







  • 1





    Looks like the error is on the config object. Try setting "es.batch.size.entries": "1" instead

    – cricket_007
    Nov 13 '18 at 15:24











  • Can you check why is it throwing java.lang.Integer cannot be cast to java.lang.String?

    – karma4917
    Nov 13 '18 at 15:51













  • 1





    Looks like the error is on the config object. Try setting "es.batch.size.entries": "1" instead

    – cricket_007
    Nov 13 '18 at 15:24











  • Can you check why is it throwing java.lang.Integer cannot be cast to java.lang.String?

    – karma4917
    Nov 13 '18 at 15:51








1




1





Looks like the error is on the config object. Try setting "es.batch.size.entries": "1" instead

– cricket_007
Nov 13 '18 at 15:24





Looks like the error is on the config object. Try setting "es.batch.size.entries": "1" instead

– cricket_007
Nov 13 '18 at 15:24













Can you check why is it throwing java.lang.Integer cannot be cast to java.lang.String?

– karma4917
Nov 13 '18 at 15:51






Can you check why is it throwing java.lang.Integer cannot be cast to java.lang.String?

– karma4917
Nov 13 '18 at 15:51













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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283944%2forg-apache-spark-api-python-pythonrdd-saveasnewapihadoopfile-error%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















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283944%2forg-apache-spark-api-python-pythonrdd-saveasnewapihadoopfile-error%23new-answer', 'question_page');

);

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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo