Title: Run queries concurrently · Issue #19 · stackql/stackqljs · GitHub
Open Graph Title: Run queries concurrently · Issue #19 · stackql/stackqljs
X Title: Run queries concurrently · Issue #19 · stackql/stackqljs
Description: async def executeQueriesAsync(self, queries): """Executes multiple StackQL queries asynchronously using the current StackQL instance. This method utilizes an asyncio event loop to concurrently run a list of provided StackQL queries. Each...
Open Graph Description: async def executeQueriesAsync(self, queries): """Executes multiple StackQL queries asynchronously using the current StackQL instance. This method utilizes an asyncio event loop to concurrently run ...
X Description: async def executeQueriesAsync(self, queries): """Executes multiple StackQL queries asynchronously using the current StackQL instance. This method utilizes an asyncio event loop to co...
Opengraph URL: https://github.com/stackql/stackqljs/issues/19
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Run queries concurrently","articleBody":"```\n\tasync def executeQueriesAsync(self, queries):\n\t\t\"\"\"Executes multiple StackQL queries asynchronously using the current StackQL instance.\n\n\t\tThis method utilizes an asyncio event loop to concurrently run a list of provided \n\t\tStackQL queries. Each query is executed independently, and the combined results of \n\t\tall the queries are returned as a list of JSON objects if 'dict' output mode is selected,\n\t\tor as a concatenated DataFrame if 'pandas' output mode is selected.\n\n\t\tThe order of the results in the returned list or DataFrame may not necessarily \n\t\tcorrespond to the order of the queries in the input list due to the asynchronous nature \n\t\tof execution.\n\n\t\t:param queries: A list of StackQL query strings to be executed concurrently.\n\t\t:type queries: list[str], required\n\t\t:return: A list of results corresponding to each query. Each result is a JSON object or a DataFrame.\n\t\t:rtype: list[dict] or pd.DataFrame\n\t\t:raises ValueError: If method is used in `server_mode` on an unsupported OS (anything other than Linux).\n\t\t:raises ValueError: If an unsupported output mode is selected (anything other than 'dict' or 'pandas').\n\n\t\tExample:\n\t\t\t\u003e\u003e\u003e from pystackql import StackQL\n\t\t\t\u003e\u003e\u003e stackql = StackQL()\t\t\n\t\t\t\u003e\u003e\u003e queries = [\n\t\t\t\u003e\u003e\u003e \\\"\\\"\\\"SELECT '%s' as region, instanceType, COUNT(*) as num_instances \n\t\t\t... FROM aws.ec2.instances \n\t\t\t... WHERE region = '%s' \n\t\t\t... GROUP BY instanceType\\\"\\\"\\\" % (region, region)\n\t\t\t\u003e\u003e\u003e for region in regions ]\n\t\t\t\u003e\u003e\u003e result = stackql.executeQueriesAsync(queries)\n\n\t\tNote:\n\t\t\t- When operating in `server_mode`, this method is not supported.\n\t\t\"\"\"\n\t\tif self.server_mode:\n\t\t\traise ValueError(\"executeQueriesAsync are not supported in sever_mode.\")\n\t\tif self.output not in ['dict', 'pandas']:\n\t\t\traise ValueError(\"executeQueriesAsync supports only 'dict' or 'pandas' output modes.\")\n\t\tasync def main():\n\t\t\twith ThreadPoolExecutor() as executor:\n\t\t\t\t# New connection is created for each query in server_mode, reused otherwise.\n\t\t\t\tnew_connection = self.server_mode\n\t\t\t\t# Gather results from all the async calls.\n\t\t\t\tloop = asyncio.get_event_loop()\n\t\t\t\tfutures = [loop.run_in_executor(executor, self._sync_query, query, new_connection) for query in queries]\n\t\t\t\tresults = await asyncio.gather(*futures)\n\t\t\t# Concatenate DataFrames if output mode is 'pandas'.\n\t\t\tif self.output == 'pandas':\n\t\t\t\treturn pd.concat(results, ignore_index=True)\n\t\t\telse:\n\t\t\t\treturn [item for sublist in results for item in sublist]\n\t\t# Running the async function\n\t\treturn await main()\n```","author":{"url":"https://github.com/yunchengyang515","@type":"Person","name":"yunchengyang515"},"datePublished":"2023-12-09T12:57:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/19/stackqljs/issues/19"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1d25aaf3-2971-2668-50d7-bb6b7298bc5d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98A8:8AE8C:1CF1B93:2842E17:6A4EC5A4 |
| html-safe-nonce | 5add5eaaf522a8c999d264ab5f4e589e9984fb860829ef54d955c161dbc49fc9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEE4OjhBRThDOjFDRjFCOTM6Mjg0MkUxNzo2QTRFQzVBNCIsInZpc2l0b3JfaWQiOiI2OTU0OTQ3MzUxNDQzMDY0MjI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 87a1c72a5184497143ab419070a9b249804025413b37c529e3d77b315eb97af8 |
| hovercard-subject-tag | issue:2033839899 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/stackql/stackqljs/19/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b5e3225663f500a3452ca543b9de194d921cc70f7e2349439bc3cfa2b204af2e/stackql/stackqljs/issues/19 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b5e3225663f500a3452ca543b9de194d921cc70f7e2349439bc3cfa2b204af2e/stackql/stackqljs/issues/19 |
| og:image:alt | async def executeQueriesAsync(self, queries): """Executes multiple StackQL queries asynchronously using the current StackQL instance. This method utilizes an asyncio event loop to concurrently run ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yunchengyang515 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| go-import | github.com/stackql/stackqljs git https://github.com/stackql/stackqljs.git |
| octolytics-dimension-user_id | 95105302 |
| octolytics-dimension-user_login | stackql |
| octolytics-dimension-repository_id | 711717177 |
| octolytics-dimension-repository_nwo | stackql/stackqljs |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 711717177 |
| octolytics-dimension-repository_network_root_nwo | stackql/stackqljs |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width