diff --git a/Sources/DataTransferObjects/Query/CustomQuery.swift b/Sources/DataTransferObjects/Query/CustomQuery.swift index c9b2057..268f099 100644 --- a/Sources/DataTransferObjects/Query/CustomQuery.swift +++ b/Sources/DataTransferObjects/Query/CustomQuery.swift @@ -8,7 +8,8 @@ public struct CustomQuery: Codable, Hashable, Equatable { aggregations: [Aggregator]? = nil, postAggregations: [PostAggregator]? = nil, limit: Int? = nil, context: QueryContext? = nil, threshold: Int? = nil, metric: TopNMetricSpec? = nil, - dimension: DimensionSpec? = nil, dimensions: [DimensionSpec]? = nil) + dimension: DimensionSpec? = nil, dimensions: [DimensionSpec]? = nil, + steps: [Filter]? = nil, stepNames: [String]? = nil) { self.queryType = queryType self.dataSource = DataSource(type: .table, name: dataSource) @@ -25,15 +26,18 @@ public struct CustomQuery: Codable, Hashable, Equatable { self.metric = metric self.dimension = dimension self.dimensions = dimensions + self.steps = steps + self.stepNames = stepNames } - public init(queryType: CustomQuery.QueryType, dataSource: DataSource = .init(type: .table, name: "telemetry-signals"), + public init(queryType: CustomQuery.QueryType, dataSource: DataSource, descending: Bool? = nil, filter: Filter? = nil, intervals: [QueryTimeInterval]? = nil, relativeIntervals: [RelativeTimeInterval]? = nil, granularity: QueryGranularity, aggregations: [Aggregator]? = nil, postAggregations: [PostAggregator]? = nil, limit: Int? = nil, context: QueryContext? = nil, threshold: Int? = nil, metric: TopNMetricSpec? = nil, - dimension: DimensionSpec? = nil, dimensions: [DimensionSpec]? = nil) + dimension: DimensionSpec? = nil, dimensions: [DimensionSpec]? = nil, + steps: [Filter]? = nil, stepNames: [String]? = nil) { self.queryType = queryType self.dataSource = dataSource @@ -50,6 +54,8 @@ public struct CustomQuery: Codable, Hashable, Equatable { self.metric = metric self.dimension = dimension self.dimensions = dimensions + self.steps = steps + self.stepNames = stepNames } public enum QueryType: String, Codable, CaseIterable, Identifiable { @@ -58,6 +64,9 @@ public struct CustomQuery: Codable, Hashable, Equatable { case timeseries case groupBy case topN + + // derived types + case funnel } public var queryType: QueryType @@ -85,6 +94,12 @@ public struct CustomQuery: Codable, Hashable, Equatable { /// Only for groupBy Queries: A list of dimensions to do the groupBy over, if queryType is groupBy public var dimensions: [DimensionSpec]? + + /// Only for funnel Queries: A list of filters that form the steps of the funnel + public var steps: [Filter]? + + /// Only for funnel Queries: An optional List of names for the funnel steps + public var stepNames: [String]? public func hash(into hasher: inout Hasher) { hasher.combine(queryType) diff --git a/Tests/QueryGenerationTests/SQLQueryConversionTests.swift b/Tests/QueryGenerationTests/SQLQueryConversionTests.swift index 9bd8172..8ce2cbb 100644 --- a/Tests/QueryGenerationTests/SQLQueryConversionTests.swift +++ b/Tests/QueryGenerationTests/SQLQueryConversionTests.swift @@ -45,6 +45,6 @@ final class SQLQueryConversionTests: XCTestCase { let responseItems = try JSONDecoder.telemetryDecoder.decode([SQLQueryConversionResponseItem].self, from: planJSON) let responseItem = responseItems.first! - let query = try responseItem.getQuery() + _ = try responseItem.getQuery() } } diff --git a/Tests/QueryTests/CustomQueryTests.swift b/Tests/QueryTests/CustomQueryTests.swift index 1f60509..1ef6e13 100644 --- a/Tests/QueryTests/CustomQueryTests.swift +++ b/Tests/QueryTests/CustomQueryTests.swift @@ -254,4 +254,17 @@ final class CustomQueryTests: XCTestCase { XCTAssertEqual(regexQuery.dataSource, decodedQuery.dataSource) } + + func testMinimalCustomQueryForFunnels() throws { + // just ensuring this compiles + _ = CustomQuery( + queryType: .funnel, + granularity: .all, + steps: [ + .selector(.init(dimension: "something", value: "one")), + .selector(.init(dimension: "other", value: "two")), + ], + stepNames: ["Step One", "Step Two"] + ) + } }