You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Learn how to use Curl to run Apache Sqoop jobs on an Apache Hadoop cluster in HDInsight. This article demonstrates how to export data from Azure storage and import it into a SQL Server database using Curl. This article is a continuation of [Use Apache Sqoop with Hadoop in HDInsight](./hdinsight-use-sqoop.md).
16
+
Learn how to use Curl to run Apache Sqoop jobs on an Apache Hadoop cluster in HDInsight. This article demonstrates how to export data from Azure Storage and import it into a SQL Server database using Curl. This article is a continuation of [Use Apache Sqoop with Hadoop in HDInsight](./hdinsight-use-sqoop.md).
16
17
17
18
Curl is used to demonstrate how you can interact with HDInsight by using raw HTTP requests to run, monitor, and retrieve the results of Sqoop jobs. This works by using the WebHCat REST API (formerly known as Templeton) provided by your HDInsight cluster.
18
19
19
20
## Prerequisites
20
21
21
22
* Completion of [Set up test environment](./hdinsight-use-sqoop.md#create-cluster-and-sql-database) from [Use Apache Sqoop with Hadoop in HDInsight](./hdinsight-use-sqoop.md).
22
23
23
-
* A client to query the Azure SQL database. Consider using [SQL Server Management Studio](../../sql-database/sql-database-connect-query-ssms.md) or [Visual Studio Code](../../sql-database/sql-database-connect-query-vscode.md).
24
+
* A client to query the Azure SQL Database. Consider using [SQL Server Management Studio](../../sql-database/sql-database-connect-query-ssms.md) or [Visual Studio Code](../../sql-database/sql-database-connect-query-vscode.md).
24
25
25
26
*[Curl](https://curl.haxx.se/). Curl is a tool to transfer data from or to a HDInsight cluster.
26
27
27
28
*[jq](https://stedolan.github.io/jq/). The jq utility is used to process the JSON data returned from REST requests.
28
29
30
+
* Familiarity with Sqoop. For more information, see [Sqoop User Guide](https://sqoop.apache.org/docs/1.4.7/SqoopUserGuide.html).
31
+
29
32
## Submit Apache Sqoop jobs by using Curl
30
33
31
-
Use Curl to export data using Apache Sqoop jobs from Azure storage to SQL Server.
34
+
Use Curl to export data using Apache Sqoop jobs from Azure Storage to SQL Server.
32
35
33
36
> [!NOTE]
34
37
> When using Curl or any other REST communication with WebHCat, you must authenticate the requests by providing the user name and password for the HDInsight cluster administrator. You must also use the cluster name as part of the Uniform Resource Identifier (URI) used to send the requests to the server.
35
38
36
39
For the commands in this section, replace `USERNAME` with the user to authenticate to the cluster, and replace `PASSWORD` with the password for the user account. Replace `CLUSTERNAME` with the name of your cluster.
37
-
40
+
38
41
The REST API is secured via [basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). You should always make requests by using Secure HTTP (HTTPS) to help ensure that your credentials are securely sent to the server.
39
42
43
+
1. For ease of use, set the variables below. This example is based on a Windows environment, revise as needed for your environment.
44
+
45
+
```cmd
46
+
set CLUSTERNAME=
47
+
set USERNAME=admin
48
+
set PASSWORD=
49
+
set SQLDATABASESERVERNAME=
50
+
set SQLDATABASENAME=
51
+
set SQLPASSWORD=
52
+
set SQLUSER=sqluser
53
+
```
54
+
40
55
1. From a command line, use the following command to verify that you can connect to your HDInsight cluster:
You should receive a response similar to the following:
@@ -49,65 +64,69 @@ The REST API is secured via [basic authentication](https://en.wikipedia.org/wiki
49
64
{"status":"ok","version":"v1"}
50
65
```
51
66
52
-
2. Replace `SQLDATABASESERVERNAME`, `USERNAME@SQLDATABASESERVERNAME`, `PASSWORD`, `SQLDATABASENAME` with the appropriate values from the prerequisites. Use the following to submit a sqoop job:
The parameters used in this command are as follows:
59
74
60
-
* **-d** - Since `-G` is not used, the request defaults to the POST method. `-d` specifies the data values that are sent with the request.
75
+
* **-d** - Since `-G` isn't used, the request defaults to the POST method. `-d` specifies the data values that are sent with the request.
61
76
62
77
* **user.name** - The user that is running the command.
63
78
64
79
* **command** - The Sqoop command to execute.
65
80
66
81
* **statusdir** - The directory that the status for this job will be written to.
67
82
68
-
This command shall return a job ID that can be used to check the status of the job.
83
+
This command will return a job ID that can be used to check the status of the job.
69
84
70
85
```json
71
86
{"id":"job_1415651640909_0026"}
72
87
```
73
88
74
-
3. To check the status of the job, use the following command. Replace `JOBID` with the value returned in the previous step. For example, if the return value was `{"id":"job_1415651640909_0026"}`, then `JOBID` would be `job_1415651640909_0026`.
89
+
1. To check the status of the job, use the following command. Replace `JOBID` with the value returned in the previous step. For example, if the return value was `{"id":"job_1415651640909_0026"}`, then `JOBID` would be `job_1415651640909_0026`. Revise location of `jq` as needed.
If the job has finished, the state will be **SUCCEEDED**.
81
-
98
+
82
99
> [!NOTE]
83
100
> This Curl request returns a JavaScript Object Notation (JSON) document with information about the job; jq is used to retrieve only the state value.
84
101
85
-
4. Once the state of the job has changed to **SUCCEEDED**, you can retrieve the results of the job from Azure Blob storage. The `statusdir` parameter passed with the query contains the location of the output file; in this case, `wasb:///example/data/sqoop/curl`. This address stores the output of the job in the `example/data/sqoop/curl` directory on the default storage container used by your HDInsight cluster.
102
+
1. Once the state of the job has changed to **SUCCEEDED**, you can retrieve the results of the job from Azure Blob storage. The `statusdir` parameter passed with the query contains the location of the output file; in this case, `wasb:///example/data/sqoop/curl`. This address stores the output of the job in the `example/data/sqoop/curl` directory on the default storage container used by your HDInsight cluster.
86
103
87
104
You can use the Azure portal to access stderr and stdout blobs.
88
105
89
-
5. To verify that data was exported, use the following queries from your SQL client to view the exported data:
106
+
1. To verify that data was exported, use the following queries from your SQL client to view the exported data:
90
107
91
108
```sql
92
109
SELECT COUNT(*) FROM [dbo].[log4jlogs] WITH (NOLOCK);
93
110
SELECT TOP(25) * FROM [dbo].[log4jlogs] WITH (NOLOCK);
94
111
```
95
112
96
113
## Limitations
97
-
* Bulk export - With Linux-based HDInsight, the Sqoop connector used to export data to Microsoft SQL Server or Azure SQL Database does not currently support bulk inserts.
114
+
115
+
* Bulk export - With Linux-based HDInsight, the Sqoop connector used to export data to Microsoft SQL Server or Azure SQL Database doesn't currently support bulk inserts.
98
116
* Batching - With Linux-based HDInsight, When using the `-batch` switch when performing inserts, Sqoop will perform multiple inserts instead of batching the insert operations.
99
117
100
118
## Summary
119
+
101
120
As demonstrated in this document, you can use a raw HTTP request to run, monitor, and view the results of Sqoop jobs on your HDInsight cluster.
102
121
103
122
For more information on the REST interface used in this article, see the <a href="https://sqoop.apache.org/docs/1.99.3/RESTAPI.html" target="_blank">Apache Sqoop REST API guide</a>.
104
123
105
124
## Next steps
125
+
106
126
[Use Apache Sqoop with Apache Hadoop on HDInsight](hdinsight-use-sqoop.md)
107
127
108
128
For other HDInsight articles involving curl:
109
-
129
+
110
130
* [Create Apache Hadoop clusters using the Azure REST API](../hdinsight-hadoop-create-linux-clusters-curl-rest.md)
111
131
* [Run Apache Hive queries with Apache Hadoop in HDInsight using REST](apache-hadoop-use-hive-curl.md)
112
-
* [Run MapReduce jobs with Apache Hadoop on HDInsight using REST](apache-hadoop-use-mapreduce-curl.md)
113
-
132
+
* [Run MapReduce jobs with Apache Hadoop on HDInsight using REST](apache-hadoop-use-mapreduce-curl.md)
0 commit comments