Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- # Required for the package command tests to work
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

.DS_Store
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.11-slim
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a Docker file so we can package the MemDB plugin in the tests


WORKDIR /app

# Copy the code and install dependencies
COPY requirements.txt .
COPY setup.cfg .
COPY setup.py .
COPY cloudquery cloudquery
COPY main.py .
RUN pip3 install --no-cache-dir -r requirements.txt

EXPOSE 7777

ENTRYPOINT ["python3", "main.py"]

CMD ["serve", "--address", "[::]:7777", "--log-format", "json", "--log-level", "info"]
63 changes: 61 additions & 2 deletions cloudquery/sdk/internal/memdb/memdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,75 @@
from cloudquery.sdk import schema
from typing import List, Generator, Dict
import pyarrow as pa
from cloudquery.sdk.types import JSONType

NAME = "memdb"
VERSION = "development"


class MemDB(plugin.Plugin):
def __init__(self) -> None:
super().__init__(NAME, VERSION)
super().__init__(
NAME, VERSION, opts=plugin.plugin.Options(team="cloudquery", kind="source")
)
self._db: Dict[str, pa.RecordBatch] = {}
self._tables: Dict[str, schema.Table] = {}
self._tables: Dict[str, schema.Table] = {
"table_1": schema.Table(
name="table_1",
columns=[
schema.Column(
name="name",
type=pa.string(),
primary_key=True,
not_null=True,
unique=True,
),
schema.Column(
name="id",
type=pa.string(),
primary_key=True,
not_null=True,
unique=True,
incremental_key=True,
),
],
title="Table 1",
description="Test Table 1",
is_incremental=True,
relations=[
schema.Table(
name="table_1_relation_1",
columns=[
schema.Column(
name="name",
type=pa.string(),
primary_key=True,
not_null=True,
unique=True,
),
schema.Column(name="data", type=JSONType()),
],
title="Table 1 Relation 1",
description="Test Table 1 Relation 1",
)
],
),
"table_2": schema.Table(
name="table_2",
columns=[
schema.Column(
name="name",
type=pa.string(),
primary_key=True,
not_null=True,
unique=True,
),
schema.Column(name="id", type=pa.string()),
],
title="Table 2",
description="Test Table 2",
),
}

def get_tables(self, options: plugin.TableOptions = None) -> List[plugin.Table]:
tables = list(self._tables.values())
Expand Down
36 changes: 35 additions & 1 deletion cloudquery/sdk/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,32 @@ class SyncOptions:
backend_options: BackendOptions = None


@dataclass
class BuildTarget:
os: str = None
arch: str = None


@dataclass
class Options:
dockerfile: str = None
build_targets: List[BuildTarget] = None
team: str = None
kind: str = None


class Plugin:
def __init__(self, name: str, version: str) -> None:
def __init__(self, name: str, version: str, opts: Options = None) -> None:
self._name = name
self._version = version
self._opts = Options() if opts is None else opts
if self._opts.dockerfile is None:
self._opts.dockerfile = "Dockerfile"
if self._opts.build_targets is None:
self._opts.build_targets = [
BuildTarget("linux", "amd64"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want Darwin targets as defaults? A lot of people do development on Macs (including us).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can still run Linux images on MacOS. For example Node.js images has only Linux platform:
https://hub.docker.com/_/node/tags?page=1
image

BuildTarget("linux", "arm64"),
]

def init(self, spec: bytes, no_connection: bool = False) -> None:
pass
Expand All @@ -46,6 +68,18 @@ def name(self) -> str:
def version(self) -> str:
return self._version

def team(self) -> str:
return self._opts.team

def kind(self) -> str:
return self._opts.kind

def dockerfile(self) -> str:
return self._opts.dockerfile

def build_targets(self) -> List[BuildTarget]:
return self._opts.build_targets

def get_tables(self, options: TableOptions) -> List[Table]:
raise NotImplementedError()

Expand Down
2 changes: 2 additions & 0 deletions cloudquery/sdk/schema/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def filter_dfs_func(tt: List[Table], include, exclude, skip_dependent_tables: bo
filtered_tables = []
for t in tt:
filtered_table = copy.deepcopy(t)
for r in filtered_table.relations:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to cloudquery/cloudquery#14637.
This was missing from the Python code and as a result the parent was never set. This means it was never sent via the gRPC call to get the tables.
See relevant Go code in https://github.com/cloudquery/plugin-sdk/blob/36128dd94c73675428b7380c9f7dccb0e6416758/schema/table.go#L201 and https://github.com/cloudquery/plugin-sdk/blob/36128dd94c73675428b7380c9f7dccb0e6416758/schema/table.go#L550

r.parent = filtered_table
filtered_table = _filter_dfs_impl(
filtered_table, False, include, exclude, skip_dependent_tables
)
Expand Down
Loading