GoogleCloudPlatform / zetasql-toolkit

The ZetaSQL Toolkit is a library that helps users use ZetaSQL Java API to perform SQL analysis for multiple query engines, including BigQuery and Cloud Spanner.
Apache License 2.0
39 stars 10 forks source link

Support creating catalogs from JSON objects #12

Closed ppaglilla closed 1 year ago

ppaglilla commented 1 year ago

Adds support for creating catalog that use resources defined in a JSON object. This is primarily intended for testing purposes, so that users don't need to write their own [BigQuery/Spanner]ResourceProvider for simple testing.

It achieves it by:

Example:

String json = "{\n"
    + "  \"tables\": ["
    + "    {"
    + "      \"name\": \"projectId.dataset.table\","
    + "      \"columns\": ["
    + "        { \"name\": \"column\", \"type\": \"INT64\" },"
    + "        { \"name\": \"column2\", \"type\": \"TIMESTAMP\", \"isPseudoColumn\": true }"
    + "      ]"
    + "    }"
    + "  ]"
    + "}";
CatalogResources resources = CatalogResources.fromJson(json);
BigQueryCatalog catalog = BigQueryCatalog.usingResources("projectId", resources);