<commit_before>os.environ['SPARK_CLASSPATH'] = "/usr/share/java/mysql-connector-java.jar"

from pyspark.sql import SQLContext
sqlC = SQLContext(sc)
jdbcurl = "jdbc:mysql://quickstart.cloudera:3306/retail_db?user=retail_dba&password=<PASSWORD>"
rdd = sqlC.load(source="jdbc",url=jdbcurl,dbtable="departments")

for r in rdd.collect():
    print r
rdd.count()
<commit_msg>Update pyspark.txt<commit_after>os.environ['SPARK_CLASSPATH'] = "/usr/share/java/mysql-connector-java.jar"

from pyspark.sql import SQLContext
sqlC = SQLContext(sc)
jdbcurl = "jdbc:mysql://quickstart.cloudera:3306/retail_db?user=retail_dba&password=<PASSWORD>"
df = sqlC.load(source="jdbc",url=jdbcurl,dbtable="departments")

for d in df.collect():
    print d
    # print d.deparment_id, d.department_name
df.count()

print df.count()

#---------------------Submiting a pySpark Job---------------------#

# create target folder
hdfs dfs -mkdir pyspark

#create workspace
mkdir spark

# create script to read and save files in hdfs
vi saveFile.py
###
from pyspark import SparkContext, SparkConf

conf = SparkConf().setAppName("pySparkApp-Test").setMaster(yarn)
sc = SparkContext(conf=conf)
rdd = sc.textFile("/user/cloudera/sqoop_import/departments")
for line in rdd.collect():
    print line

rdd.saveAsTextFile("/user/cloudera/pyspark/testdepartments")

:wq
###

# check if source exists
#hdfs dfs -cat /user/cloudera/sqoop_import/departments/*


{'fraction_non_alphanumeric': 0.1614950634696756, 'fraction_numerical': 0.005641748942172073, 'mean_word_length': 4.791836734693877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3466833', 'n_tokens_mistral': 536, 'n_tokens_neox': 517, 'n_words': 97}