Converting from CSV to parquet or avro reduces the size of the file and allows for faster read and write speeds. With Bacalhau, you can convert your CSV files stored on ipfs or on the web without the need to download files and install dependencies locally.
In this example tutorial we will convert a CSV file from a URL to parquet format and save the converted parquet file to IPFS
Prerequisites
To get started, you need to install the Bacalhau client, see more information
import pandas as pd
pd.read_parquet('transactions.parquet').head()
Containerize Script with Docker
To build your own docker container, create a Dockerfile, which contains instructions to build your image.
FROM python:3.8
RUN apt update && apt install git
RUN git clone https://github.com/bacalhau-project/Sparkov_Data_Generation
WORKDIR /Sparkov_Data_Generation/
RUN pip3 install -r requirements.txt
Build the container
We will run the docker build command to build the container:
docker build -t <hub-user>/<repo-name>:<tag> .
Before running the command replace:
repo-name with the name of the container, you can name it anything you want
tag this is not required but you can use the latest tag
In our case:
docker build -t jsacex/csv-to-arrow-or-parquet .
Push the container
Next, upload the image to the registry. This can be done by using the Docker hub username, repo name or tag.
docker push <hub-user>/<repo-name>:<tag>
In our case:
docker push jsacex/csv-to-arrow-or-parquet
Running a Bacalhau Job
With the command below, we are mounting the CSV file for transactions from IPFS
The job description should be saved in .yaml format, e.g. convertcsv.yaml, and then run with the command:
bacalhau job run convertcsv.yaml
Checking the State of your Jobs
Job status: You can check the status of the job using bacalhau job list.
bacalhau job list --id-filter ${JOB_ID}
When it says Published or Completed, that means the job is done, and we can get the results.
Job information: You can find out more information about your job by using bacalhau job describe.
bacalhau job describe ${JOB_ID}
Job download: You can download your job results directly by using bacalhau job get. Alternatively, you can choose to create a directory to store your results. In the command below, we created a directory (results) and downloaded our job output to be stored in that directory.
rm -rf results && mkdir -p results # Temporary directory to store the results
bacalhau job get ${JOB_ID} --output-dir results # Download the results
Viewing your Job Output
To view the file, run the following command:
ls results/outputs
transactions.parquet
Alternatively, you can do this:
import pandas as pd
import os
pd.read_parquet('results/outputs/transactions.parquet')
Support
You can find out more information about converter.py
You can skip this section entirely and directly go to
See more information on how to containerize your script/app
hub-user with your docker hub username. If you don’t have a docker hub account , and use the username of the account you created
The same job can be presented in the format. In this case, the description will look like this:
If you have questions or need support or guidance, please reach out to the (#general channel).