viirya commented on code in PR #137: URL: https://github.com/apache/spark-connect-swift/pull/137#discussion_r2085365971
########## Sources/SparkConnect/StreamingQueryManager.swift: ########## @@ -0,0 +1,173 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +import Foundation + +/// Information about progress made for a sink in the execution of a ``StreamingQuery`` +/// during a trigger. See ``StreamingQueryProgress`` for more information. +public struct SourceProgress: Sendable { + let description: String + let startOffset: String + let endOffset: String + let latestOffset: String + let numInputRows: Int64 + let inputRowsPerSecond: Double + let processedRowsPerSecond: Double + let metrics: [String: String] = [:] +} + +/// Information about progress made for a sink in the execution of a ``StreamingQuery`` +/// during a trigger. See ``StreamingQueryProgress`` for more information. +public struct SinkProgress: Sendable { + let description: String + let numOutputRows: Int64 + let metrics: [String: String] = [:] + + init(_ description: String) { + self.description = description + self.numOutputRows = -1 + } + + init(_ description: String, _ numOutputRows: Int64) { + self.description = description + self.numOutputRows = numOutputRows + } +} + +/// Information about updates made to stateful operators in a ``StreamingQuery`` +/// during a trigger. See ``StreamingQueryProgress`` for more information. +public struct StateOperatorProgress: Sendable { + let operatorName: String + let numRowsTotal: Int64 + let numRowsUpdated: Int64 + let allUpdatesTimeMs: Int64 + let numRowsRemoved: Int64 + let allRemovalsTimeMs: Int64 + let commitTimeMs: Int64 + let memoryUsedBytes: Int64 + let numRowsDroppedByWatermark: Int64 + let numShufflePartitions: Int64 + let numStateStoreInstances: Int64 + let customMetrics: [String: Int64] +} + +/// Information about progress made in the execution of a ``StreamingQuery`` +/// during a trigger. Each event relates to processing done for a single trigger of +/// the streaming query. Events are emitted even when no new data is available to be processed. +public struct StreamingQueryProcess { + let id: UUID + let runId: UUID + let name: String + let timestamp: String + let batchId: Int64 + let batchDuration: Int64 + let durationMs: [String: Int64] + let eventTime: [String: String] + let stateOperators: [StateOperatorProgress] + let sources: [SourceProgress] + let sink: SinkProgress + let observedMetrics: [String: Row] + + func numInputRows() -> Int64 { + return sources.map { $0.numInputRows }.reduce(0, +) + } + + func inputRowsPerSecond() -> Double { + return sources.map { $0.inputRowsPerSecond }.reduce(0, +) + } + + func processedRowsPerSecond() -> Double { + return sources.map { $0.processedRowsPerSecond }.reduce(0, +) + } +} + +/// A class to manage all the ``StreamingQuery`` active in a ``SparkSession``. Review Comment: ```suggestion /// A class to manage all the ``StreamingQuery``s active in a ``SparkSession``. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org