Skip to content

Instantly share code, notes, and snippets.

View arapat's full-sized avatar

Julaiti Alafate arapat

View GitHub Profile
class ClassName:
def __init__(self):
parser = argparse.ArgumentParser(description="")
parser.add_argument("task", help="select the task to perform,")
args = parser.parse_args(sys.argv[1:2])
getattr(self, args.task)()
def task(self):
parser = argparse.ArgumentParser(description="")
parser.add_argument("--arg", help="")
@arapat
arapat / log_accumulator.py
Last active March 17, 2020 19:17
Spark trick: use accumulators to collect logs from the worker nodes.
from pyspark import SparkContext
from pyspark.accumulators import AccumulatorParam
# Spark only implements Accumulator parameter for numeric types.
# This class extends Accumulator support to the string type.
class StringAccumulatorParam(AccumulatorParam):
def zero(self, value):
return value
def addInPlace(self, val1, val2):
return val1 + val2