Skip to content

Commit

Permalink
Add properties for funnel steps (#19)
Browse files Browse the repository at this point in the history
* Add properties for funnel steps

* Add funnel query type
  • Loading branch information
winsmith authored Jan 12, 2023
1 parent 1df10a2 commit 43b114c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
21 changes: 18 additions & 3 deletions Sources/DataTransferObjects/Query/CustomQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -58,6 +64,9 @@ public struct CustomQuery: Codable, Hashable, Equatable {
case timeseries
case groupBy
case topN

// derived types
case funnel
}

public var queryType: QueryType
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/QueryGenerationTests/SQLQueryConversionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
13 changes: 13 additions & 0 deletions Tests/QueryTests/CustomQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
}
}

0 comments on commit 43b114c

Please sign in to comment.