Support Questions
Find answers, ask questions, and share your expertise

Call external service from Pig

Explorer

Hi,

I want to post data to external service using curl command from Pig. Is it possible to run curl command from Pig?

2 REPLIES 2

@priyal patel,

Yes. You can run curl command in pig. You can run shell commands in pig using "sh {command}"

Here is the sample.

[root@test-instance-1 ~]$ pig
grunt> sh curl -k -u admin:admin -H "X-Requested-By:ambari" http://localhost:8080/api/v1/clusters
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
{
  "href" : "http://localhost:8080/api/v1/clusters",
  "items" : [  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    {
100   236  100   236    0     0   3808      0 --:--:-- --:--:-- --:--:--  3868      "href" : "http://localhost:8080/api/v1/clusters/cl1",
      "Clusters" : {
        "cluster_name" : "cl1",
        "version" : "HDP-2.6"
      }
    }
  ]
}

Additional reference : https://pig.apache.org/docs/r0.11.1/cmds.html#sh

Please accept the answer if this helps.

.

-Aditya

Explorer

@Aditya Sirna

I want to post pig relation output to external service using curl. How to pass pig relation values in a below curl command :

curl -X POST http://xxx.xx.xxx.xx/services//api/data -H "accept: application/json" -H "authorization: authorization-token value" -H "cache-control: no-cache" -H "content-type: multipart/form-data;boundary=----xxxxxxxxxxxxxxxxx" -H "postman-token:postman-token value" -F "title=the value which i want to fetch from pig relation " -F "description=descirption"

i want to fetch value for title from pig relation.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.