-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Implementation for Datasources operations #11012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0297aa6
Initial Commit
rakshith91 037ea83
lint + mypy
rakshith91 1ff9d3a
tests
rakshith91 c6eb6ed
recordings update
rakshith91 c1adb7f
Apply suggestions from code review
73551fa
typo
rakshith91 bd3f0d1
remove datasource
rakshith91 82750e9
lint
rakshith91 55d562d
rename to get_datasources
rakshith91 1e10f71
Merge branch 'master' into datasource_op
bryevdv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...earch/azure-search-documents/samples/async_samples/sample_data_source_operations_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # coding: utf-8 | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| """ | ||
| FILE: sample_data_source_operations_async.py | ||
| DESCRIPTION: | ||
| This sample demonstrates how to get, create, update, or delete a Synonym Map. | ||
| USAGE: | ||
| python sample_data_source_operations_async.py | ||
|
|
||
| Set the environment variables with your own values before running the sample: | ||
| 1) AZURE_SEARCH_SERVICE_ENDPOINT - the endpoint of your Azure Cognitive Search service | ||
| 2) AZURE_SEARCH_API_KEY - your search API key | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
|
|
||
| service_endpoint = os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT") | ||
| key = os.getenv("AZURE_SEARCH_API_KEY") | ||
| connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") | ||
|
|
||
| from azure.core.credentials import AzureKeyCredential | ||
| from azure.search.documents import DataSource, DataContainer, DataSourceCredentials | ||
| from azure.search.documents.aio import SearchServiceClient | ||
|
|
||
| service_client = SearchServiceClient(service_endpoint, AzureKeyCredential(key)) | ||
|
|
||
| async def create_data_source(): | ||
| # [START create_data_source_async] | ||
| credentials = DataSourceCredentials(connection_string=connection_string) | ||
| container = DataContainer(name='searchcontainer') | ||
| data_source = DataSource(name="async-sample-datasource", type="azureblob", credentials=credentials, container=container) | ||
| async with service_client: | ||
| result = await service_client.create_datasource(data_source) | ||
| print("Create new Data Source - async-sample-datasource") | ||
| # [END create_data_source_async] | ||
|
|
||
| async def list_data_sources(): | ||
| # [START list_data_source_async] | ||
| async with service_client: | ||
| result = await service_client.get_datasources() | ||
| names = [x.name for x in result] | ||
| print("Found {} Data Sources in the service: {}".format(len(result), ", ".join(names))) | ||
| # [END list_data_source_async] | ||
|
|
||
| async def get_data_source(): | ||
| # [START get_data_source_async] | ||
| async with service_client: | ||
| result = await service_client.get_datasource("async-sample-datasource") | ||
| print("Retrived Data Source 'async-sample-datasource'") | ||
| return result | ||
| # [END get_data_source_async] | ||
|
|
||
| async def delete_data_source(): | ||
| # [START delete_data_source_async] | ||
| async with service_client: | ||
| service_client.delete_datasource("async-sample-datasource") | ||
| print("Data Source 'async-sample-datasource' successfully deleted") | ||
| # [END delete_data_source_async] | ||
|
|
||
| async def main(): | ||
| await create_data_source() | ||
| await list_data_sources() | ||
| await get_data_source() | ||
| await delete_data_source() | ||
| await service_client.close() | ||
|
|
||
| if __name__ == '__main__': | ||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(main()) | ||
| loop.close() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per @johanste This will either need to return a
PagedItemor be renamed toget_datasources(same comment for async version) @brjohnstmsft has indicated that the only one that realistically might be paged on the service side is the indexes list.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you confirm if there is an upper limit for the number of data sources?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will implement paging in a separate issue - that way this wont be blocked for indexers
#11025
EDIT
keeping in mind that service doesn't support paging yet, at this point we would want paging only for indexes (since there can be upto 3000 indexes). Realistically, datasources shouldn't have paging support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So with #11025 closed, this should be renamed to
get_datasourcesI think?