-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Support simple DB query for sdk (#917)
Co-authored-by: chengfangyin2 <chengfangyin3@jd.com>
- Loading branch information
Showing
18 changed files
with
467 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,23 @@ | ||
from abc import abstractmethod | ||
from dbgpt.core.awel import MapOperator | ||
from dbgpt.core.awel.task.base import IN, OUT | ||
|
||
|
||
class RetrieverOperator(MapOperator[IN, OUT]): | ||
"""The Abstract Retriever Operator.""" | ||
|
||
async def map(self, input_value: IN) -> OUT: | ||
"""Map input value to output value. | ||
Args: | ||
input_value (IN): The input value. | ||
Returns: | ||
OUT: The output value. | ||
""" | ||
# The retrieve function is blocking, so we need to wrap it in a blocking_func_to_async. | ||
return await self.blocking_func_to_async(self.retrieve, input_value) | ||
|
||
@abstractmethod | ||
def retrieve(self, input_value: IN) -> OUT: | ||
"""Retrieve data for input value.""" |
This file contains 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 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 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
Empty file.
This file contains 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,16 @@ | ||
from typing import Any | ||
from dbgpt.core.awel import MapOperator | ||
from dbgpt.core.awel.task.base import IN, OUT | ||
from dbgpt.datasource.base import BaseConnect | ||
|
||
|
||
class DatasourceOperator(MapOperator[str, Any]): | ||
def __init__(self, connection: BaseConnect, **kwargs): | ||
super().__init__(**kwargs) | ||
self._connection = connection | ||
|
||
async def map(self, input_value: IN) -> OUT: | ||
return await self.blocking_func_to_async(self.query, input_value) | ||
|
||
def query(self, input_value: str) -> Any: | ||
return self._connection.run_to_df(input_value) |
Oops, something went wrong.