fun process()

in tools/sql_extraction/src/main/kotlin/SqlExtractor.kt [28:73]


    fun process(
        filePaths: Sequence<Path>,
        confidenceThreshold: Double = 0.0,
        showProgress: Boolean = false,
        parallelize: Boolean = false
    ): Output {
        val queries = ConcurrentLinkedQueue<Query>()

        val numCompleted = AtomicInteger(0)
        val (length, processedFilePaths) = if (showProgress) {
            // iterate paths to count up the length
            val list = filePaths.toList()
            Pair(list.size, list.iterator().asSequence())
        } else {
            Pair(1, filePaths)
        }

        val coroutineDispatcher = Executors.newWorkStealingPool().asCoroutineDispatcher()
        runBlocking {
            for (filePath in processedFilePaths) {
                if (parallelize) {
                    launch(coroutineDispatcher) {
                        analyzeFile(
                            filePath,
                            showProgress,
                            numCompleted,
                            length,
                            confidenceThreshold,
                            queries
                        )
                    }
                } else {
                    analyzeFile(
                        filePath,
                        showProgress,
                        numCompleted,
                        length,
                        confidenceThreshold,
                        queries
                    )
                }
            }
        }

        return Output(queries.sortedByDescending { it.confidence })
    }