Skip to content

Commit 3cee6c8

Browse files
author
Cory Fowler
authored
Merge pull request #52861 from orspod/patch-5
Updated file as per Vladiks changes
2 parents bcbc55d + 8f95f78 commit 3cee6c8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

articles/data-explorer/python-ingest-data.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ For example, if your domain is *contoso.com*, the URL is: [https://login.windows
6060
"authorization_endpoint":"https://login.windows.net/6babcaad-604b-40ac-a9d7-9fd97c0b779f/oauth2/authorize"
6161
```
6262

63-
The tenant ID in this case is `6babcaad-604b-40ac-a9d7-9fd97c0b779f`. Set the values for AAD_TENANT_ID, KUSTO_ENGINE_CLUSTER, KUSTO_INGEST_CLUSTER, and KUSTO_DATABASE before running this code.
63+
The tenant ID in this case is `6babcaad-604b-40ac-a9d7-9fd97c0b779f`. Set the values for AAD_TENANT_ID, KUSTO_URI, KUSTO_INGEST_URI, and KUSTO_DATABASE before running this code.
6464

6565
```python
6666
AAD_TENANT_ID = "<TenantId>"
67-
KUSTO_ENGINE_CLUSTER = "https://<ClusterName>.<Region>.kusto.windows.net:443/"
68-
KUSTO_INGEST_CLUSTER = "https://ingest-<ClusterName>.<Region>.kusto.windows.net:443/"
67+
KUSTO_URI = "https://<ClusterName>.<Region>.kusto.windows.net:443/"
68+
KUSTO_INGEST_URI = "https://ingest-<ClusterName>.<Region>.kusto.windows.net:443/"
6969
KUSTO_DATABASE = "<DatabaseName>"
7070
```
7171

@@ -74,11 +74,9 @@ Now construct the connection string. This example uses device authentication to
7474
You create the destination table and mapping in a later step.
7575

7676
```python
77-
KCSB_INGEST = KustoConnectionStringBuilder.with_aad_device_authentication(KUSTO_INGEST_CLUSTER)
78-
KCSB_INGEST.authority_id = AAD_TENANT_ID
77+
KCSB_INGEST = KustoConnectionStringBuilder.with_aad_device_authentication(KUSTO_INGEST_URI, AAD_TENANT_ID)
7978

80-
KCSB_ENGINE = KustoConnectionStringBuilder.with_aad_device_authentication(KUSTO_ENGINE_CLUSTER)
81-
KCSB_ENGINE.authority_id = AAD_TENANT_ID
79+
KCSB_DATA = KustoConnectionStringBuilder.with_aad_device_authentication(KUSTO_URI, AAD_TENANT_ID)
8280

8381
DESTINATION_TABLE = "StormEvents"
8482
DESTINATION_TABLE_COLUMN_MAPPING = "StormEvents_CSV_Mapping"
@@ -106,10 +104,10 @@ BLOB_PATH = "https://" + ACCOUNT_NAME + ".blob.core.windows.net/" + CONTAINER +
106104
Create a table that matches the schema of the data in the StormEvents.csv file. When this code runs, it returns a message like the following: *To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code F3W4VWZDM to authenticate*. Follow the steps to sign in, then return to run the next code block. Subsequent code blocks that make a connection require you to sign in again.
107105

108106
```python
109-
ENGINE_CLIENT = KustoClient(KCSB_ENGINE)
107+
KUSTO_CLIENT = KustoClient(KCSB_ENGINE)
110108
CREATE_TABLE_COMMAND = ".create table StormEvents (StartTime: datetime, EndTime: datetime, EpisodeId: int, EventId: int, State: string, EventType: string, InjuriesDirect: int, InjuriesIndirect: int, DeathsDirect: int, DeathsIndirect: int, DamageProperty: int, DamageCrops: int, Source: string, BeginLocation: string, EndLocation: string, BeginLat: real, BeginLon: real, EndLat: real, EndLon: real, EpisodeNarrative: string, EventNarrative: string, StormSummary: dynamic)"
111109

112-
df_table_create_output = ENGINE_CLIENT.execute_mgmt(KUSTO_DATABASE, CREATE_TABLE_COMMAND).primary_results[0].to_dataframe()
110+
df_table_create_output = KUSTO_CLIENT.execute_mgmt(KUSTO_DATABASE, CREATE_TABLE_COMMAND).primary_results[0].to_dataframe()
113111

114112
df_table_create_output
115113
```
@@ -121,7 +119,7 @@ Map incoming CSV data to the column names and data types used when creating the
121119
```python
122120
CREATE_MAPPING_COMMAND = """.create table StormEvents ingestion csv mapping 'StormEvents_CSV_Mapping' '[{"Name":"StartTime","datatype":"datetime","Ordinal":0}, {"Name":"EndTime","datatype":"datetime","Ordinal":1},{"Name":"EpisodeId","datatype":"int","Ordinal":2},{"Name":"EventId","datatype":"int","Ordinal":3},{"Name":"State","datatype":"string","Ordinal":4},{"Name":"EventType","datatype":"string","Ordinal":5},{"Name":"InjuriesDirect","datatype":"int","Ordinal":6},{"Name":"InjuriesIndirect","datatype":"int","Ordinal":7},{"Name":"DeathsDirect","datatype":"int","Ordinal":8},{"Name":"DeathsIndirect","datatype":"int","Ordinal":9},{"Name":"DamageProperty","datatype":"int","Ordinal":10},{"Name":"DamageCrops","datatype":"int","Ordinal":11},{"Name":"Source","datatype":"string","Ordinal":12},{"Name":"BeginLocation","datatype":"string","Ordinal":13},{"Name":"EndLocation","datatype":"string","Ordinal":14},{"Name":"BeginLat","datatype":"real","Ordinal":16},{"Name":"BeginLon","datatype":"real","Ordinal":17},{"Name":"EndLat","datatype":"real","Ordinal":18},{"Name":"EndLon","datatype":"real","Ordinal":19},{"Name":"EpisodeNarrative","datatype":"string","Ordinal":20},{"Name":"EventNarrative","datatype":"string","Ordinal":21},{"Name":"StormSummary","datatype":"dynamic","Ordinal":22}]'"""
123121

124-
df_mapping_create_output = ENGINE_CLIENT.execute_mgmt(KUSTO_DATABASE, CREATE_MAPPING_COMMAND).primary_results[0].to_dataframe()
122+
df_mapping_create_output = KUSTO_CLIENT.execute_mgmt(KUSTO_DATABASE, CREATE_MAPPING_COMMAND).primary_results[0].to_dataframe()
125123

126124
df_mapping_create_output
127125
```
@@ -131,10 +129,10 @@ df_mapping_create_output
131129
Queue a message to pull data from blob storage and ingest that data into Azure Data Explorer.
132130

133131
```python
134-
INGESTION_CLIENT = KustoIngestClient(KCSB_INGEST)
132+
KUSTO_INGEST_CLIENT = KustoIngestClient(KCSB_INGEST)
135133

136134
INGESTION_PROPERTIES = IngestionProperties(database=KUSTO_DATABASE, table=DESTINATION_TABLE, dataFormat=DataFormat.csv, mappingReference=DESTINATION_TABLE_COLUMN_MAPPING, additionalProperties={'ignoreFirstRecord': 'true'})
137-
INGESTION_CLIENT.ingest_from_multiple_blobs([BlobDescriptor(BLOB_PATH,FILE_SIZE)],delete_sources_on_success=False,ingestion_properties=INGESTION_PROPERTIES)
135+
KUSTO_INGEST_CLIENT.ingest_from_multiple_blobs([BlobDescriptor(BLOB_PATH,FILE_SIZE)],delete_sources_on_success=False,ingestion_properties=INGESTION_PROPERTIES)
138136

139137
print('Done queueing up ingestion with Kusto')
140138
```
@@ -146,7 +144,7 @@ Wait for five to ten minutes for the queued ingestion to schedule the ingest and
146144
```python
147145
QUERY = "StormEvents | count"
148146

149-
df = ENGINE_CLIENT.execute_query(KUSTO_DATABASE, QUERY).primary_results[0].to_dataframe()
147+
df = KUSTO_CLIENT.execute_query(KUSTO_DATABASE, QUERY).primary_results[0].to_dataframe()
150148

151149
df
152150
```

0 commit comments

Comments
 (0)