Skip to content

Add the concept of DB selectors#58

Merged
smukil merged 3 commits intocloudspannerecosystem:mainfrom
smukil:create_db_selector
Sep 18, 2025
Merged

Add the concept of DB selectors#58
smukil merged 3 commits intocloudspannerecosystem:mainfrom
smukil:create_db_selector

Conversation

@smukil
Copy link
Collaborator

@smukil smukil commented Sep 11, 2025

This change is added to minimize code-duplication between internal and OSS codebases.

The primary difference between internal and cloud is the params used to connect to them. We can create the concept of DB selectors which encapsulate details of the underlying DB being connected to. Hence, instead of passing cloud specific parameters (--database/--instance/--project), these selectors can be plumbed through the code.

  • 3 types of selectors are implemented: CLOUD, INFRA, MOCK

  • Passing the following options to %%spanner_graphs selects the appropriate DB:

    • --mock selects a Mock Spanner database.
    • --project <> --instance <> --database selects a Cloud Spanner database.
    • --infra_db_path <> selects an Infra database
  • Core cloud and infra related database code already separated. cloud_database.py will be available in OSS and the infra version will not. So infra_db_path will not work in OSS and vice versa. MOCK will be supported in both internal and OSS.

  • A new JSON based wire format between JS and Python is added: {
    "selector":
    {"env": "SpannerEnv.MOCK/CLOUD/INFRA", "project": "<>", "instance": "<>", "database": "<>", "infra_db_path": "<>"}, "graph": "<>" }

For example the protocol for cloud could look like: {
"selector":
{"env": "SpannerEnv.CLOUD",
"project": "span-cloud-testing",
"instance": "graph-demo",
"database": "viz-demo",
"infra_db_path": null},
"graph": "FinGraph"
}

Similarly INFRA would have infra_db_path populated and the rest as null.

@smukil smukil requested a review from cqian23 September 11, 2025 08:23
Sailesh Mukil added 2 commits September 17, 2025 20:32
This change is added to minimize code-duplication between internal and
OSS codebases.

The primary difference between internal and cloud is the params used to
connect to them. We can create the concept of DB selectors which
encapsulate details of the underlying DB being connected to.
Hence, instead of passing cloud specific parameters
(`--database/--instance/--project`), these selectors can be plumbed
through the code.

- 3 types of selectors are implemented: CLOUD, INFRA, MOCK
- Passing the following options to %%spanner_graphs selects the
  appropriate DB:
  - `--mock` selects a Mock Spanner database.
  - `--project <> --instance <> --database` selects a Cloud Spanner
    database.
  - `--infra_db_path <>` selects an Infra database
- Core cloud and infra related database code already separated.
  cloud_database.py will be available in OSS and the infra version will
  not. So `infra_db_path` will not work in OSS and vice versa. MOCK will
  be supported in both internal and OSS.

- A new JSON based wire format between JS and Python is added:
{
 "selector":
  {"env": "SpannerEnv.MOCK/CLOUD/INFRA",
   "project": "<>",
   "instance": "<>",
   "database": "<>",
   "infra_db_path": "<>"},
 "graph": "<>"
}

For example the protocol for cloud could look like:
{
 "selector":
 {"env": "SpannerEnv.CLOUD",
  "project": "span-cloud-testing",
  "instance": "graph-demo",
  "database": "viz-demo",
  "infra_db_path": null},
 "graph": "FinGraph"
}

Similarly INFRA would have infra_db_path populated and the rest as null.
Copy link
Collaborator

@cqian23 cqian23 left a comment

Choose a reason for hiding this comment

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

tested and worked well so far

@smukil smukil merged commit abbe104 into cloudspannerecosystem:main Sep 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants