Azure-Samples / Synapse

Samples for Azure Synapse Analytics
MIT License
375 stars 351 forks source link

[Synapse - Apache Spark definition] - Python sample to copy local files to wabs #97

Closed ahuarte47 closed 3 years ago

ahuarte47 commented 3 years ago

Hi, It would be nice to have a sample code to copy files from local directories to wabs.

I am developing a Python script in a Spark definition and I would like to copy a local file already created in the temp directory to wasb.

I am trying to use mssparkutils (Maybe this is my error):

local_file = '/tmp/a.txt'
azure_file = 'wasbs://<container>@<storage_account>.blob.core.windows.net/outputs/a.txt'
from notebookutils import mssparkutils
mssparkutils.fs.cp(local_file, azure_file, True)

But, I get error:

Current content of Temp folder:
   /tmp/eea_discodata_task-9c3df798c1ff11ebaedc000d3ab6dc78.log.json
   /tmp/ca-certificates.tmp.3cqtU8
Traceback (most recent call last):
  File "datapipelineapp.py", line 179, in <module>
    main()
  File "datapipelineapp.py", line 158, in main
    mssparkutils.fs.mv(file_rs, dataset_fn, True)
  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/notebookutils/mssparkutils/fs.py", line 12, in mv
    return fs.mv(src, dest, create_path, overwrite)
  File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/notebookutils/mssparkutils/handlers/fsHandler.py", line 56, in mv
    return self.fsutils.mv(src, dest, create_path, overwrite)
  File "/opt/spark/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
  File "/opt/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 69, in deco
  File "/opt/spark/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:mssparkutils.fs.mv.
: java.io.FileNotFoundException: /tmp/eea_discodata_task-9c3df798c1ff11ebaedc000d3ab6dc78.log.json
    at com.microsoft.spark.notebook.msutils.impl.MSFsUtilsImpl.mv(MSFsUtilsImpl.scala:228)
    at mssparkutils.fs$.mv(fs.scala:20)
    at mssparkutils.fs.mv(fs.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)

I see that dbutils package is not available in this context, it is used in Databricks environments. Thanks in advance

ahuarte47 commented 3 years ago

I close this Issue. The Azure Storage Blobs client library for Python does this task.