jfrag1 commented on code in PR #22931: URL: https://github.com/apache/superset/pull/22931#discussion_r1100781643
########## superset/datasets/api.py: ########## @@ -877,3 +880,74 @@ def import_(self) -> Response: ) command.run() return self.response(200, message="OK") + + @expose("/get_or_create/", methods=["POST"]) + @protect() + @safe + @statsd_metrics + @event_logger.log_this_with_context( + action=lambda self, *args, **kwargs: f"{self.__class__.__name__}" + f".get_or_create_dataset", + log_to_statsd=False, + ) + def get_or_create_dataset(self) -> Response: + """Retrieve a dataset by name, or create it if it does not exist + --- + post: + summary: Retrieve a table by name, or create it if it does not exist + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/GetOrCreateDatasetSchema' + responses: + 200: + description: The ID of the table + content: + application/json: + schema: + type: object + properties: + result: + type: object + properties: + table_id: + type: integer + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 422: + $ref: '#/components/responses/422' + 500: + $ref: '#/components/responses/500' + """ + try: + body = GetOrCreateDatasetSchema().load(request.json) + except ValidationError as ex: + return self.response(400, message=ex.messages) + table_name = body["table_name"] + database_id = body["database_id"] + table = ( + db.session.query(SqlaTable) + .filter_by(database_id=database_id, table_name=table_name) + .one_or_none() + ) Review Comment: moved to DAO -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org