Skip to content

Commit

Permalink
Remove sampleFactor property
Browse files Browse the repository at this point in the history
With the move to namespaces, we’re no longer going to support name spaces
  • Loading branch information
winsmith committed Jan 27, 2025
1 parent 3e08256 commit e2909ef
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 105 deletions.
13 changes: 1 addition & 12 deletions Sources/DataTransferObjects/Query/CustomQuery+CompileDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,7 @@ extension CustomQuery {
"com.telemetrydeck.compacted"
]

if let sampleFactor = query.sampleFactor {
switch sampleFactor {
case 10:
query.dataSource = .init("telemetry-signals-sample10")
case 100:
query.dataSource = .init("telemetry-signals-sample100")
case 1000:
query.dataSource = .init("telemetry-signals-sample1000")
default:
query.dataSource = .init("telemetry-signals")
}
} else if let dataSource = query.dataSource, allowedDataSourceNames.contains(dataSource.name) {
if let dataSource = query.dataSource, allowedDataSourceNames.contains(dataSource.name) {
query.dataSource = .init(dataSource.name)
} else {
if let namespace {
Expand Down
13 changes: 0 additions & 13 deletions Sources/DataTransferObjects/Query/CustomQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {
restrictions: [QueryTimeInterval]? = nil,
dataSource: String? = nil,
virtualColumns: [VirtualColumn]? = nil,
sampleFactor: Int? = nil,
descending: Bool? = nil,
filter: Filter? = nil,
having: HavingSpec? = nil,
Expand Down Expand Up @@ -45,7 +44,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {
}

self.virtualColumns = virtualColumns
self.sampleFactor = sampleFactor
self.descending = descending
self.baseFilters = baseFilters
self.testMode = testMode
Expand Down Expand Up @@ -79,7 +77,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {
restrictions: [QueryTimeInterval]? = nil,
dataSource: DataSource?,
virtualColumns: [VirtualColumn]? = nil,
sampleFactor: Int? = nil,
descending: Bool? = nil,
filter: Filter? = nil,
having: HavingSpec? = nil,
Expand Down Expand Up @@ -111,7 +108,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {
self.restrictions = restrictions
self.dataSource = dataSource
self.virtualColumns = virtualColumns
self.sampleFactor = sampleFactor
self.descending = descending
self.baseFilters = baseFilters
self.testMode = testMode
Expand Down Expand Up @@ -173,13 +169,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {

public var virtualColumns: [VirtualColumn]?

/// The sample factor to apply to this query
///
/// To speed up calculation, you can sample e.g. 1/10 or 1/100 of the signals, and get a good idea of the shapre of the available data.
///
/// Must be either 1, 10, 100 or 1000. All other values will be treated as 1 (i.e. look at all signals).
/// Setting this property will overwrite the dataSource property.
public var sampleFactor: Int?
public var descending: Bool?
public var baseFilters: BaseFilters?
public var testMode: Bool?
Expand Down Expand Up @@ -249,7 +238,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {
hasher.combine(restrictions)
hasher.combine(dataSource)
hasher.combine(virtualColumns)
hasher.combine(sampleFactor)
hasher.combine(descending)
hasher.combine(baseFilters)
hasher.combine(testMode)
Expand Down Expand Up @@ -288,7 +276,6 @@ public struct CustomQuery: Codable, Hashable, Equatable {
restrictions = try container.decodeIfPresent([QueryTimeInterval].self, forKey: CustomQuery.CodingKeys.restrictions)
dataSource = try container.decodeIfPresent(DataSource.self, forKey: CustomQuery.CodingKeys.dataSource)
virtualColumns = try container.decodeIfPresent([VirtualColumn].self, forKey: CustomQuery.CodingKeys.virtualColumns)
sampleFactor = try container.decodeIfPresent(Int.self, forKey: CustomQuery.CodingKeys.sampleFactor)
descending = try container.decodeIfPresent(Bool.self, forKey: CustomQuery.CodingKeys.descending)
baseFilters = try container.decodeIfPresent(BaseFilters.self, forKey: CustomQuery.CodingKeys.baseFilters)
testMode = try container.decodeIfPresent(Bool.self, forKey: CustomQuery.CodingKeys.testMode)
Expand Down
55 changes: 0 additions & 55 deletions Tests/QueryGenerationTests/CompileDownTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,61 +276,6 @@ final class CompileDownTests: XCTestCase {
])
}

func testSampleFactor1() throws {
let intervals: [QueryTimeInterval] = [
.init(beginningDate: Date(iso8601String: "2023-04-01T00:00:00.000Z")!, endDate: Date(iso8601String: "2023-05-31T00:00:00.000Z")!),
]

let query = CustomQuery(queryType: .timeseries, sampleFactor: 1, intervals: intervals, granularity: .day)
let precompiledQuery = try query.precompile(organizationAppIDs: [appID1, appID2], isSuperOrg: false)
let compiledQuery = try precompiledQuery.compileToRunnableQuery()
XCTAssertEqual(compiledQuery.dataSource?.name, "telemetry-signals")
}

func testSampleFactor10() throws {
let intervals: [QueryTimeInterval] = [
.init(beginningDate: Date(iso8601String: "2023-04-01T00:00:00.000Z")!, endDate: Date(iso8601String: "2023-05-31T00:00:00.000Z")!),
]

let query = CustomQuery(queryType: .timeseries, sampleFactor: 10, intervals: intervals, granularity: .day)
let precompiledQuery = try query.precompile(organizationAppIDs: [appID1, appID2], isSuperOrg: false)
let compiledQuery = try precompiledQuery.compileToRunnableQuery()
XCTAssertEqual(compiledQuery.dataSource?.name, "telemetry-signals-sample10")
}

func testSampleFactor100() throws {
let intervals: [QueryTimeInterval] = [
.init(beginningDate: Date(iso8601String: "2023-04-01T00:00:00.000Z")!, endDate: Date(iso8601String: "2023-05-31T00:00:00.000Z")!),
]

let query = CustomQuery(queryType: .timeseries, sampleFactor: 100, intervals: intervals, granularity: .day)
let precompiledQuery = try query.precompile(organizationAppIDs: [appID1, appID2], isSuperOrg: false)
let compiledQuery = try precompiledQuery.compileToRunnableQuery()
XCTAssertEqual(compiledQuery.dataSource?.name, "telemetry-signals-sample100")
}

func testSampleFactor1000() throws {
let intervals: [QueryTimeInterval] = [
.init(beginningDate: Date(iso8601String: "2023-04-01T00:00:00.000Z")!, endDate: Date(iso8601String: "2023-05-31T00:00:00.000Z")!),
]

let query = CustomQuery(queryType: .timeseries, sampleFactor: 1000, intervals: intervals, granularity: .day)
let precompiledQuery = try query.precompile(organizationAppIDs: [appID1, appID2], isSuperOrg: false)
let compiledQuery = try precompiledQuery.compileToRunnableQuery()
XCTAssertEqual(compiledQuery.dataSource?.name, "telemetry-signals-sample1000")
}

func testIllegalSampleFactor() throws {
let intervals: [QueryTimeInterval] = [
.init(beginningDate: Date(iso8601String: "2023-04-01T00:00:00.000Z")!, endDate: Date(iso8601String: "2023-05-31T00:00:00.000Z")!),
]

let query = CustomQuery(queryType: .timeseries, sampleFactor: 42, intervals: intervals, granularity: .day)
let precompiledQuery = try query.precompile(organizationAppIDs: [appID1, appID2], isSuperOrg: false)
let compiledQuery = try precompiledQuery.compileToRunnableQuery()
XCTAssertEqual(compiledQuery.dataSource?.name, "telemetry-signals")
}

func testNamespace() throws {
let intervals: [QueryTimeInterval] = [
.init(beginningDate: Date(iso8601String: "2023-04-01T00:00:00.000Z")!, endDate: Date(iso8601String: "2023-05-31T00:00:00.000Z")!),
Expand Down
25 changes: 0 additions & 25 deletions Tests/QueryTests/CustomQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,31 +383,6 @@ final class CustomQueryTests: XCTestCase {
)
}

func testSampleFactorEncoding() throws {
let input = CustomQuery(queryType: .timeseries, sampleFactor: 10, granularity: .day)

let expectedOutput = """
{"granularity":"day","queryType":"timeseries","sampleFactor":10}
"""

let encodedOutput = try JSONEncoder.telemetryEncoder.encode(input)

XCTAssertEqual(expectedOutput, String(data: encodedOutput, encoding: .utf8)!)
}

func testSampleFactorDecoding() throws {
let input = """
{"granularity":"day","queryType":"timeseries","sampleFactor":10}
"""
.data(using: .utf8)!

let expectedOutput = CustomQuery(queryType: .timeseries, sampleFactor: 10, granularity: .day)

let decodedOutput = try JSONDecoder.telemetryDecoder.decode(CustomQuery.self, from: input)

XCTAssertEqual(expectedOutput, decodedOutput)
}

func testScanQueryDecoding() throws {
let input = """
{
Expand Down

0 comments on commit e2909ef

Please sign in to comment.