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

[Cosmos] Add support for geospatial indexing and configuration #7331

Merged
merged 3 commits into from
Feb 12, 2020
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
5 changes: 5 additions & 0 deletions sdk/cosmosdb/cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release History

## 3.6.0 (2020-2-10)

- FEATURE: Add support for spatial indexing, bounding boxes, and geospatial configuration
- BUG FIX: Fix bug when passing forceQueryPlan to QueryIterator for non-item resources (#7333)

## 3.5.4 (2020-1-28)

- BUG FIX: Return parsed number instead of string for request charge
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/cosmos",
"version": "3.5.4",
"version": "3.6.0",
"description": "Microsoft Azure Cosmos DB Service Node.js SDK for SQL API",
"sdk-type": "client",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { IndexingPolicy, PartitionKeyDefinition } from "../../documents";
import { ConflictResolutionPolicy } from "../Conflict/ConflictResolutionPolicy";
import { UniqueKeyPolicy } from "./UniqueKeyPolicy";
import { GeospatialType } from "../../documents/GeospatialType";

export interface ContainerDefinition {
/** The id of the container. */
Expand All @@ -17,4 +18,8 @@ export interface ContainerDefinition {
conflictResolutionPolicy?: ConflictResolutionPolicy;
/** Policy for additional keys that must be unique per partition key */
uniqueKeyPolicy?: UniqueKeyPolicy;
/** Geospatial configuration for a collection. Type is set to Geography by default */
geospatialConfig?: {
type: GeospatialType;
};
}
9 changes: 9 additions & 0 deletions sdk/cosmosdb/cosmos/src/documents/GeospatialType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export enum GeospatialType {
/** Represents data in round-earth coordinate system. */
Geography = "Geography",
/** Represents data in Eucledian(flat) coordinate system. */
Geometry = "Geometry"
}
26 changes: 26 additions & 0 deletions sdk/cosmosdb/cosmos/src/documents/IndexingPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ export interface IndexingPolicy {
includedPaths?: IndexedPath[];
/** An array of {@link IncludedPath} represents the paths to be excluded for indexing. */
excludedPaths?: IndexedPath[];
spatialIndexes?: SpatialIndex[];
}

/* The target data type of a spatial path */
export enum SpatialType {
LineString = "LineString",
MultiPolygon = "MultiPolygon",
Point = "Point",
Polygon = "Polygon"
}

export interface SpatialIndex {
/* Path in JSON document to index */
path: string;
types: SpatialType[];
/* Bounding box for geometry spatial path */
boundingBox: {
/* X-coordinate of the lower-left corner of the bounding box. */
xmin: number;
/* Y-coordinate of the lower-left corner of the bounding box. */
ymin: number;
/* X-coordinate of the upper-right corner of the bounding box. */
xmax: number;
/* Y-coordinate of the upper-right corner of the bounding box. */
ymax: number;
};
}

export interface IndexedPath {
Expand Down
15 changes: 15 additions & 0 deletions sdk/cosmosdb/cosmos/test/functional/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
IndexingPolicy,
IndexKind
} from "../../dist-esm/documents";
import { SpatialType } from "../../dist-esm/documents/IndexingPolicy";
import { GeospatialType } from "../../dist-esm/documents/GeospatialType";
import { getTestDatabase, removeAllDatabases } from "../common/TestHelpers";

describe("Containers", function() {
Expand Down Expand Up @@ -64,6 +66,19 @@ describe("Containers", function() {

// Replacing indexing policy is allowed.
containerDef.indexingPolicy.indexingMode = IndexingMode.lazy;
containerDef.indexingPolicy.spatialIndexes = [
{
path: "/region/?",
types: [SpatialType.Polygon],
boundingBox: {
xmin: 0,
ymin: 0,
xmax: 10,
ymax: 10
}
}
];
containerDef.geospatialConfig.type = GeospatialType.Geometry;
const { resource: replacedContainer } = await container.replace(containerDef);
assert.equal("lazy", replacedContainer.indexingPolicy.indexingMode);

Expand Down