Created
May 1, 2020 11:01
-
-
Save cordon-thiago/574d4fec71bc8292b43f4ff979dde153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from pyspark import SparkConf, SparkContext | |
from pyspark.sql import SparkSession | |
########################## | |
# You can configure master here if you do not pass the spark.master paramenter in conf | |
########################## | |
#master = "spark://spark:7077" | |
#conf = SparkConf().setAppName("Spark Hello World").setMaster(master) | |
#sc = SparkContext(conf=conf) | |
#spark = SparkSession.builder.config(conf=conf).getOrCreate() | |
# Create spark context | |
sc = SparkContext() | |
# Get the second argument passed to spark-submit (the first is the python app) | |
logFile = sys.argv[1] | |
# Read file | |
logData = sc.textFile(logFile).cache() | |
# Get lines with A | |
numAs = logData.filter(lambda s: 'a' in s).count() | |
# Get lines with B | |
numBs = logData.filter(lambda s: 'b' in s).count() | |
# Print result | |
print("Lines with a: {}, lines with b: {}".format(numAs, numBs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment