'Python argparse unexpected behavior when passing "``" to the argument string in pysaprk cluster mode
I am trying to pass a string in my pyspark code and it works fine but when i pass the following string to escape reserved keyword
`date` or any value passed in ``
in it behaves unexpectedly.
below is the test code i am using:
import argparse
def getArgParser():
parser = argparse.ArgumentParser(description='Write Hive table to Mongo/Kafka')
parser.add_argument("--query", action="store",
help= "query", type=str)
return parser
def main(job_parameters: dict):
print(job_parameters.get('query', None))
if __name__ == '__main__':
parser = getArgParser()
args = parser.parse_args()
main(vars(args))
Now the command i using when i run
> spark-submit --master yarn --deploy-mode cluster test.py --query
> 'select `id`,from_unixtime(unix_timestamp(`date` ,"MM/dd/yyyy"),
> "yyyy-MM-dd") as dt from db.table '
I get
'select , from_unixtime(unix_timestamp(Fri May 6 15:05:30 UTC 2022 ,"MM/dd/yyyy"), "yyyy-MM-dd") from db.table '
that is in place of date i get todays date and the value in `` are missing.
but when the same code is ran into client mode the result is as expected.
> spark-submit --master yarn --deploy-mode cluster test.py --query
> 'select `id`,from_unixtime(unix_timestamp(`date` ,"MM/dd/yyyy"),
> "yyyy-MM-dd") as dt from db.table '
PS: My orignal code is pyspark this python code is for testing purpose. Can anyone help here to find the cause of the issue ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|