Skip to content
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

Add support for pydantic2.0 #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ r/shroomDK_0.1.0.tar.gz
python-sdk-example.py
r/shroomDK/api_key.txt
r/shroomDK/test_of_page2_issue.R
test-script.py
2 changes: 1 addition & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pydantic==1.10.9
pydantic==2.6.3
requests==2.29.0
8 changes: 2 additions & 6 deletions python/src/models/compass/cancel_query_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List, Union

from typing import List, Optional, Union
from pydantic import BaseModel

from .core.query_run import QueryRun
Expand All @@ -11,16 +10,13 @@
class CancelQueryRunRpcRequestParams(BaseModel):
queryRunId: str


class CancelQueryRunRpcRequest(RpcRequest):
method: str = "cancelQueryRun"
params: List[CancelQueryRunRpcRequestParams]


# Response
class CancelQueryRunRpcResult(BaseModel):
queryRun: QueryRun


class CancelQueryRunRpcResponse(RpcResponse):
result: Union[CancelQueryRunRpcResult, None]
result: Optional[CancelQueryRunRpcResult]
30 changes: 15 additions & 15 deletions python/src/models/compass/core/query_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ class QueryRun(BaseModel):
sqlStatementId: str
state: str
path: str
fileCount: Optional[int]
lastFileNumber: Optional[int]
fileNames: Optional[str]
errorName: Optional[str]
errorMessage: Optional[str]
errorData: Optional[Any]
dataSourceQueryId: Optional[str]
dataSourceSessionId: Optional[str]
startedAt: Optional[str]
queryRunningEndedAt: Optional[str]
queryStreamingEndedAt: Optional[str]
endedAt: Optional[str]
rowCount: Optional[int]
totalSize: Optional[int]
fileCount: Optional[int] = None
lastFileNumber: Optional[int] = None
fileNames: Optional[str] = None
errorName: Optional[str] = None
errorMessage: Optional[str] = None
errorData: Optional[Any] = None
dataSourceQueryId: Optional[str] = None
dataSourceSessionId: Optional[str] = None
startedAt: Optional[str] = None
queryRunningEndedAt: Optional[str] = None
queryStreamingEndedAt: Optional[str] = None
endedAt: Optional[str] = None
rowCount: Optional[int] = None
totalSize: Optional[int] = None
tags: Tags
dataSourceId: str
userId: str
createdAt: str
updatedAt: datetime
archivedAt: Optional[datetime]
archivedAt: Optional[datetime] = None
2 changes: 1 addition & 1 deletion python/src/models/compass/core/rpc_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
class RpcError(BaseModel):
code: int
message: str
data: Optional[Any]
data: Optional[Any] = None
2 changes: 1 addition & 1 deletion python/src/models/compass/core/rpc_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class RpcResponse(BaseModel):
jsonrpc: str
id: int
result: Union[Optional[Dict[str, Any]], None]
error: Optional[RpcError]
error: Optional[Union[RpcError, None]] = None
2 changes: 1 addition & 1 deletion python/src/models/compass/core/sql_statement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Optional

from pydantic import BaseModel

Expand Down
6 changes: 3 additions & 3 deletions python/src/models/compass/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@


class Tags(BaseModel):
sdk_package: Optional[str]
sdk_version: Optional[str]
sdk_language: Optional[str]
sdk_package: Optional[str] = None
sdk_version: Optional[str] = None
sdk_language: Optional[str] = None
10 changes: 4 additions & 6 deletions python/src/models/compass/create_query_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Any, Dict, List, Union

from typing import List, Optional, Any
from pydantic import BaseModel

from .core.query_request import QueryRequest
Expand All @@ -19,18 +18,17 @@ class CreateQueryRunRpcParams(BaseModel):
dataSource: str
dataProvider: str


class CreateQueryRunRpcRequest(RpcRequest):
method: str = "createQueryRun"
params: List[CreateQueryRunRpcParams]


# Response
class CreateQueryRunRpcResult(BaseModel):
queryRequest: QueryRequest
queryRun: QueryRun
sqlStatement: SqlStatement


class CreateQueryRunRpcResponse(RpcResponse):
result: Union[CreateQueryRunRpcResult, None]
id: Optional[Any]
jsonrpc: Optional[str]
result: Optional[CreateQueryRunRpcResult]
13 changes: 9 additions & 4 deletions python/src/models/query.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Optional, Union

from pydantic import BaseModel, Field


class Query(BaseModel):
sql: str = Field(None, description="SQL query to execute")
sql: Optional[str] = Field(
None, description="SQL query to execute"
)
ttl_minutes: Optional[int] = Field(
None, description="The number of minutes to cache the query results"
)
Expand All @@ -21,8 +22,12 @@ class Query(BaseModel):
None,
description="An override on the cache. A value of true will Re-Execute the query.",
)
page_size: int = Field(None, description="The number of results to return per page")
page_number: int = Field(None, description="The page number to return")
page_size: Optional[int] = Field(
None, description="The number of results to return per page"
)
page_number: Optional[int] = Field(
None, description="The page number to return"
)
sdk_package: Optional[str] = Field(
None, description="The SDK package used for the query"
)
Expand Down
22 changes: 14 additions & 8 deletions python/src/models/query_defaults.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
from typing import Optional
from pydantic import BaseModel, Field


class QueryDefaults(BaseModel):
ttl_minutes: int = Field(
ttl_minutes: Optional[int] = Field(
None, description="The number of minutes to cache the query results"
)
max_age_minutes: int = Field(
max_age_minutes: Optional[int] = Field(
None,
description="The max age of query results to accept before deciding to run a query again",
)
cached: bool = Field(False, description="Whether or not to cache the query results")
timeout_minutes: int = Field(
cached: bool = Field(
False, description="Whether or not to cache the query results"
)
timeout_minutes: Optional[int] = Field(
None, description="The number of minutes to timeout the query"
)
retry_interval_seconds: float = Field(
retry_interval_seconds: Optional[float] = Field(
None, description="The number of seconds to wait before retrying the query"
)
page_size: int = Field(None, description="The number of results to return per page")
page_number: int = Field(None, description="The page number to return")
page_size: Optional[int] = Field(
None, description="The number of results to return per page"
)
page_number: Optional[int] = Field(
None, description="The page number to return"
)
28 changes: 16 additions & 12 deletions python/src/models/query_result_set.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
from typing import Any, List, Union

from typing import Any, List, Optional
from pydantic import BaseModel, Field

from .compass.core.page_stats import PageStats
from .query_run_stats import QueryRunStats


class QueryResultSet(BaseModel):
query_id: Union[str, None] = Field(None, description="The server id of the query")

query_id: Optional[str] = Field(
None, description="The server id of the query"
)
status: str = Field(
False, description="The status of the query (`PENDING`, `FINISHED`, `ERROR`)"
..., description="The status of the query (`PENDING`, `FINISHED`, `ERROR`)"
)
columns: Union[List[str], None] = Field(
columns: Optional[List[str]] = Field(
None, description="The names of the columns in the result set"
)
column_types: Union[List[str], None] = Field(
column_types: Optional[List[str]] = Field(
None, description="The type of the columns in the result set"
)
rows: Union[List[Any], None] = Field(None, description="The results of the query")
run_stats: Union[QueryRunStats, None] = Field(
rows: Optional[List[Any]] = Field(
None, description="The results of the query"
)
run_stats: Optional[QueryRunStats] = Field(
None,
description="Summary stats on the query run (i.e. the number of rows returned, the elapsed time, etc)",
)
records: Union[List[Any], None] = Field(
records: Optional[List[Any]] = Field(
None, description="The results of the query transformed as an array of objects"
)
page: Union[PageStats, None] = Field(
page: Optional[PageStats] = Field(
None, description="Summary of page stats for this query result set"
)
error: Any
error: Any = Field(
..., description="The error information if the query fails"
)
32 changes: 19 additions & 13 deletions python/src/models/query_run_stats.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
from typing import Optional
from datetime import datetime

from pydantic import BaseModel, Field


class QueryRunStats(BaseModel):
started_at: datetime = Field(None, description="The start time of the query run.")
ended_at: datetime = Field(None, description="The end time of the query run.")
query_exec_started_at: datetime = Field(
started_at: Optional[datetime] = Field(
None, description="The start time of the query run."
)
ended_at: Optional[datetime] = Field(
None, description="The end time of the query run."
)
query_exec_started_at: Optional[datetime] = Field(
None, description="The start time of query execution."
)
query_exec_ended_at: datetime = Field(
query_exec_ended_at: Optional[datetime] = Field(
None, description="The end time of query execution."
)
streaming_started_at: datetime = Field(
streaming_started_at: Optional[datetime] = Field(
None, description="The start time of streaming query results."
)
streaming_ended_at: datetime = Field(
streaming_ended_at: Optional[datetime] = Field(
None, description="The end time of streaming query results."
)
elapsed_seconds: int = Field(
elapsed_seconds: Optional[int] = Field(
None,
description="The number of seconds elapsed between the start and end times.",
)
queued_seconds: int = Field(
queued_seconds: Optional[int] = Field(
None,
description="The number of seconds elapsed between when the query was created and when execution on the data source began.",
)
streaming_seconds: int = Field(
streaming_seconds: Optional[int] = Field(
None,
description="The number of seconds elapsed between when the query execution completed and results were fully streamed to Flipside's servers.",
)
query_exec_seconds: int = Field(
query_exec_seconds: Optional[int] = Field(
None,
description="The number of seconds elapsed between when the query execution started and when it completed on the data source.",
)
record_count: int = Field(
record_count: Optional[int] = Field(
None, description="The number of records returned by the query."
)
bytes: int = Field(None, description="The number of bytes returned by the query.")
bytes: Optional[int] = Field(
None, description="The number of bytes returned by the query."
)
Loading