-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from owainhunt/datastore-aggregation-query
Datastore aggregation query, composite filter and multiple database support
- Loading branch information
Showing
15 changed files
with
654 additions
and
162 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
11 changes: 9 additions & 2 deletions
11
Datastore/Sources/Data API/Models/Project API/Request/AllocateIdsRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import Core | ||
|
||
public struct AllocateIdsRequest: GoogleCloudModel { | ||
public init(keys: [Key]? = nil) { | ||
public init( | ||
keys: [Key]? = nil, | ||
databaseId: String? = nil | ||
) { | ||
self.databaseId = databaseId | ||
self.keys = keys | ||
} | ||
/// A list of keys with incomppublic lete key paths for which to allocate IDs. No key may be reserved/read-only. | ||
/// The ID of the database against which to make the request. | ||
/// '(default)' is not allowed; please use empty string '' to refer the default database. | ||
public let databaseId: String? | ||
/// A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only. | ||
public let keys: [Key]? | ||
} |
9 changes: 8 additions & 1 deletion
9
Datastore/Sources/Data API/Models/Project API/Request/BeginTransactionRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import Core | ||
|
||
public struct BeginTransactionRequest: GoogleCloudModel { | ||
public init(transactionOptions: TransactionOptions? = nil) { | ||
public init( | ||
transactionOptions: TransactionOptions? = nil, | ||
databaseId: String? = nil | ||
) { | ||
self.transactionOptions = transactionOptions | ||
self.databaseId = databaseId | ||
} | ||
/// Options for a new transaction. | ||
public let transactionOptions: TransactionOptions? | ||
/// The ID of the database against which to make the request. | ||
/// '(default)' is not allowed; please use empty string '' to refer the default database. | ||
public let databaseId: String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
Datastore/Sources/Data API/Models/Project API/Request/LookupRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import Core | ||
|
||
public struct LookupRequest: GoogleCloudModel { | ||
public init(keys: [Key]? = nil, | ||
readOptions: ReadOptions? = nil) { | ||
public init( | ||
keys: [Key]? = nil, | ||
readOptions: ReadOptions? = nil, | ||
databaseId: String? = nil | ||
) { | ||
self.keys = keys | ||
self.readOptions = readOptions | ||
self.databaseId = databaseId | ||
} | ||
/// Keys of entities to look up. | ||
public let keys: [Key]? | ||
/// The options for this lookup request. | ||
public let readOptions: ReadOptions? | ||
/// The ID of the database against which to make the request. | ||
/// '(default)' is not allowed; please use empty string '' to refer the default database. | ||
public let databaseId: String? | ||
} | ||
|
6 changes: 4 additions & 2 deletions
6
Datastore/Sources/Data API/Models/Project API/Request/ReserveIdsRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
Datastore/Sources/Data API/Models/Project API/Request/RollbackRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import Core | ||
|
||
public struct RollbackRequest: GoogleCloudModel { | ||
|
||
public init( | ||
transaction: String, | ||
databaseId: String? = nil | ||
) { | ||
self.transaction = transaction | ||
self.databaseId = databaseId | ||
} | ||
|
||
/// The transaction identifier, | ||
public let transaction: String | ||
/// The ID of the database against which to make the request. | ||
/// '(default)' is not allowed; please use empty string '' to refer the default database. | ||
public let databaseId: String? | ||
} |
44 changes: 44 additions & 0 deletions
44
Datastore/Sources/Data API/Models/Project API/Request/RunAggregationQueryRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Core | ||
|
||
struct RunAggregationQueryRequest: GoogleCloudModel { | ||
|
||
init( | ||
gqlQuery: GqlQuery, | ||
partitionId: PartitionId? = nil, | ||
readOptions: ReadOptions? = nil, | ||
databaseId: String? = nil | ||
) { | ||
self.gqlQuery = gqlQuery | ||
self.aggregationQuery = nil | ||
self.partitionId = partitionId | ||
self.readOptions = readOptions | ||
self.databaseId = databaseId | ||
} | ||
|
||
init( | ||
query: Query, | ||
aggregations: [Aggregation], | ||
partitionId: PartitionId? = nil, | ||
readOptions: ReadOptions? = nil, | ||
databaseId: String? = nil | ||
) { | ||
self.aggregationQuery = AggregationQuery(aggregations: aggregations, nestedQuery: query) | ||
self.gqlQuery = nil | ||
self.partitionId = partitionId | ||
self.readOptions = readOptions | ||
self.databaseId = databaseId | ||
} | ||
|
||
/// The GQL query to run. | ||
let gqlQuery: GqlQuery? | ||
/// The aggregation query to run. | ||
let aggregationQuery: AggregationQuery? | ||
/// The (optional) namespace and partition against which to run the query | ||
let partitionId: PartitionId? | ||
/// The options for this query. | ||
let readOptions: ReadOptions? | ||
/// The ID of the database against which to make the request. | ||
/// '(default)' is not allowed; please use empty string '' to refer the default database. | ||
let databaseId: String? | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Datastore/Sources/Data API/Models/Project API/Response/RunAggregationQueryResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Core | ||
|
||
public struct RunAggregationQueryResponse: GoogleCloudModel { | ||
/// A batch of query results (always present). | ||
public let batch: AggregationResultBatch | ||
/// The parsed form of the GqlQuery from the request, if it was set. | ||
public let query: AggregationQuery? | ||
public let transaction: String? | ||
} | ||
|
||
public struct AggregationResultBatch: Codable { | ||
public let aggregationResults: [AggregationResult] | ||
} | ||
|
||
public struct AggregationResult: Codable { | ||
public let aggregateProperties: AggregateProperties | ||
} | ||
|
||
public typealias AggregateProperties = [String: Value] | ||
|
6 changes: 4 additions & 2 deletions
6
Datastore/Sources/Data API/Models/Project API/Response/RunQueryResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Datastore/Sources/Data API/Models/Project API/Types/AggregationQuery.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
public struct AggregationQuery: Codable { | ||
|
||
public let aggregations: [AggregationReference] | ||
public let nestedQuery: Query | ||
|
||
init( | ||
aggregations: [Aggregation], | ||
nestedQuery: Query | ||
) { | ||
self.aggregations = aggregations.map(AggregationReference.init) | ||
self.nestedQuery = nestedQuery | ||
} | ||
|
||
public struct AggregationReference: Codable { | ||
|
||
public let alias: String? | ||
public let count: Count? | ||
public let sum: Sum? | ||
public let avg: Average? | ||
|
||
init( | ||
alias: String? = nil, | ||
count: Count? = nil, | ||
sum: Sum? = nil, | ||
avg: Average? = nil | ||
) { | ||
self.alias = alias | ||
self.count = count | ||
self.sum = sum | ||
self.avg = avg | ||
} | ||
|
||
init(_ aggregration: Aggregation) { | ||
switch aggregration { | ||
case .count(alias: let alias, upTo: let upTo): | ||
self.init(alias: alias, count: Count(upTo: upTo)); return | ||
case .sum(alias: let alias, property: let property): | ||
self.init(alias: alias, sum: Sum(property: property)); return | ||
case .avg(alias: let alias, property: let property): | ||
self.init(alias: alias, avg: Average(property: property)); return | ||
} | ||
} | ||
|
||
public struct Count: Codable { | ||
public let upTo: String? | ||
} | ||
|
||
public struct Sum: Codable { | ||
public let property: PropertyReference | ||
} | ||
|
||
public struct Average: Codable { | ||
public let property: PropertyReference | ||
} | ||
} | ||
} | ||
|
||
public enum Aggregation: Codable { | ||
case count(alias: String? = nil, upTo: String? = nil) | ||
case sum(alias: String? = nil, property: PropertyReference) | ||
case avg(alias: String? = nil, property: PropertyReference) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.